Update book

This commit is contained in:
Eric_lai
2022-01-19 11:03:47 +08:00
commit 820f3f4e4c
15 changed files with 726 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyInterpreterInspection" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<value>
<list size="6">
<item index="0" class="java.lang.String" itemvalue="numpy" />
<item index="1" class="java.lang.String" itemvalue="tensorflow" />
<item index="2" class="java.lang.String" itemvalue="opencv-python" />
<item index="3" class="java.lang.String" itemvalue="cython" />
<item index="4" class="java.lang.String" itemvalue="tensorlayer" />
<item index="5" class="java.lang.String" itemvalue="pycocotools" />
</list>
</value>
</option>
</inspection_tool>
</profile>
</component>

View File

@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/openmlsys-zh.iml" filepath="$PROJECT_DIR$/.idea/openmlsys-zh.iml" />
</modules>
</component>
</project>

8
.idea/openmlsys-zh.iml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

88
INFO.md Normal file
View File

@@ -0,0 +1,88 @@
## 环境安装
机器学习系统书籍部署在Github是依赖于d2lbook工具实现的。因此我们首先要安装d2lbook。
```
pip install git+https://github.com/d2l-ai/d2l-book
```
使用pip如果不能安装成功,可以通过git clon下载代码安装
```
git clone git@github.com:d2l-ai/d2l-book.git
cd d2l-book
python setyp.py install
```
使用d2lbook构建HTML需要安装pandoc,可以使用pip install pandoc。
构建PDF时如果有SVG图片需要安装LibRsvg来转换SVG图片,安装librsvg可以通过pip install librsvg。
当然构建PDF必须要有LaTeX,如安装[Tex Live](https://www.tug.org/texlive/).
## 编译HTML版本
在编译前先下载[openmlsys-zh](),所有的编译命令都在改文件目录内执行。
```
git clone git@github.com:openmlsys/openmlsys-zh.git
cd openmlsys-zh
```
使用d2lbook工具编译HTML。
```
d2lbook build html
```
生成的html会在`_build/html`。
此时我们将编译好的html整个文件夹下的内容拷贝至openmlsys.github.io的website发布。
需要注意的是website目录下的.nojekyll不要删除了,不然网页会没有渲染。
## 编译PDF版本
编译pdf版本需要xelatex、librsvg2-bin(svg图片转pdf)和思源字体。在Ubuntu可以这样安装。
```
sudo apt-get install texlive-full
sudo apt-get install librsvg2-bin
```
```
wget https://github.com/adobe-fonts/source-han-sans/raw/release/OTF/SourceHanSansSC.zip
wget https://github.com/adobe-fonts/source-han-serif/raw/release/OTF/SourceHanSerifSC_SB-H.zip
wget https://github.com/adobe-fonts/source-han-serif/raw/release/OTF/SourceHanSerifSC_EL-M.zip
unzip SourceHanSansSC.zip
unzip SourceHanSerifSC_EL-M.zip
unzip SourceHanSerifSC_SB-H.zip
sudo mv SourceHanSansSC SourceHanSerifSC_EL-M SourceHanSerifSC_SB-H /usr/share/fonts/opentype/
sudo fc-cache -f -v
```
这时候可以通过 `fc-list :lang=zh` 来查看安装的中文字体。
同样的去下载和安装英文字体
```
wget -O source-serif-pro.zip https://www.fontsquirrel.com/fonts/download/source-serif-pro
unzip source-serif-pro -d source-serif-pro
sudo mv source-serif-pro /usr/share/fonts/opentype/
wget -O source-sans-pro.zip https://www.fontsquirrel.com/fonts/download/source-sans-pro
unzip source-sans-pro -d source-sans-pro
sudo mv source-sans-pro /usr/share/fonts/opentype/
wget -O source-code-pro.zip https://www.fontsquirrel.com/fonts/download/source-code-pro
unzip source-code-pro -d source-code-pro
sudo mv source-code-pro /usr/share/fonts/opentype/
sudo fc-cache -f -v
```
然后就可以编译了。
```
d2lbook build pdf
```
## 样式规范
贡献请遵照本教程的[样式规范](STYLE_GUIDE.md)。
## 中英文术语对照
翻译请参照[中英文术语对照](TERMINOLOGY.md)。

2
README.md Normal file
View File

@@ -0,0 +1,2 @@
# 机器学习系统:设计和实现

178
STYLE_GUIDE.md Normal file
View File

@@ -0,0 +1,178 @@
# 样式规范
## 文本
* 章节
* 每章开头对全章做介绍
* 结构标题一致
* 小结
* 练习
* 扫码直达讨论区
* 参考文献(如有)
* 引用
* 在每节结尾处引用
* 字符串
* 使用中文双引号
* 符号描述
* 时刻t(不是t时刻)
* 形状使用英文标点
* (10, 20) 不是 (10,20)
* 空格:
* 文本中中文和英文、数字、数学公式、特殊字体等之间不要加空格
* 非行首的`:numref:`、`:cite:`等前留有一个英文空格(否则网页不渲染)
* 代码注释同上
* 人称
* 第一人称 → 我们
* 第二人称 → 读者、你、大家
* 工具或部件
* Gluon, MXNet, NumPy, spaCy, ResNet-18, Fashion-MNIST, matplotlib
* 这些都作为词,不要带重音符
* `backward`函数
* 不是“`backward()`函数” (不要带括号)
* `for`循环
* 术语
* 统一使用
* 函数(非方法)
* 实例(非对象)
* 区分:超参数和参数
* 区分:小批量随机梯度下降和随机梯度下降
* 权重、偏差、标签
* 模型训练、模型预测(推断)
* 训练数据集、验证数据集、测试数据集
* 中文优先于英文
* 首次出现,注明原英文术语
* 无须加粗
* 无须加引号
* 中英文对照统一标准
* https://github.com/mli/gluon-tutorials-zh/blob/master/README.md
## 数学
* 数学符号样式一致
* https://github.com/goodfeli/dlbook_notation/blob/master/notation_example.pdf
* 书本页宽限制
* 每行长度
* 引用
* 上式和下式
* 以上N式,以下N式
* 公式末放英文标点
* 逗号:,
* 句号:.
* 赋值符号
* \leftarrow
## 图片
* 软件
* 使用OmniGraffle制图,以100%的大小导出pdf(infinite canvas),再使用pdf2svg转成svg
* 样式
* 格式:
* svg
* png
* export resolution: 144
* 大小:
* 横向:不超过400像素
* 纵向:不超过200像素
* 粗细:
* StickArrow
* 1pt
* arrow head size: 50%
* 字体:
* 英文:STIXGeneral, 9pt(下标和上标:6pt)
* 中文:PingFang SC, 9pt
* 下标和上标中的数字和括号不要斜体
* 颜色:
* 非填充深蓝色(与黑相近):
* 5B7DAA
* 填充蓝色(与黑对比)
* 深:66BFFF
* 淡:B2D9FF
* 版权
* 不使用网络图片
* 位置
* 两张图不可以较邻近
* 两张图拼一下
* 引用
* 手动引用(例如,图7.1)
* matplotlib
* 大小
* 分辨率
## 代码
* 使用utils.py封装多次使用函数
* 首次出现函数,书里给出函数实现
* Python规范一致
* PEP8
* 二元操作符换行:操作符和后一元一起换行 (https://www.python.org/dev/peps/pep-0008/#should-a-line-break-before-or-after-a-binary-operator)
* 将相邻赋值语句尽可能合并为同一行
* 如 num_epochs, lr = 5, 0.1
* 变量名一致
* num_epochs
* 迭代周期
* num_hiddens
* 隐藏单元个数
* num_inputs
* 输入个数
* num_outputs
* 输出个数
* net
* 模型
* lr
* 学习率
* acc
* 准确率
* 迭代中
* 特征:X
* 标签:y, y_hat 或 Y, Y_hat
* for X, y in data_iter
* 数据集:
* 特征:features或images
* 标签:labels
* DataLoader实例:train_iter, test_iter, data_iter
* 注释
* 中文
* 句末不加句号
* 书本页宽限制
* 每行不超过78字符
* In [X]: 79字符不会自动换行(X = 1, ..., 9)
* In [XX]: 78字符不会自动换行(XX = 10, 11, ..., 99)
* 打印结果自动换行
* imports
* import alphabetically
* from mxnet.gluon import data as gdata, loss as gloss, nn, utils as gutils
* 打印名称
* epoch(从1开始计数), lr, loss, train acc, time
* 5行左右
* 打印变量
* 代码块最后一行尽量不用print()语句,例如`x, y`而不是`print('x:', x, 'y:', y)`
* 字符串
* 使用单引号
* 其他
* nd.f(x) → x.nd
* random_normal → random.normal
* multiple imports
* .1 → 1.0
* 1. → 1.0
* remove namescope
## 超链接
* 内链格式
* [“线性回归”](linear-reg.md)一节
* 外链
* [层](http:bla)
* 无须暴露URL
## 英翻汉的常见问题
* 遇到不确定的地方,可以翻阅中文版第一版的处理方法(即我们需要遵照的出版标准),以及查阅人工翻译 http://www.jukuu.com/
* 建立中英文术语对照表,全书术语翻译要完全一致。
* 语法要正确(如不能缺主语、谓语)、句子要通顺(硬翻不妥就意译)、不要漏内容。
* 代码注释要翻译。注意:i) 每行不要超过78字符,注释末尾不用加句号。 ii) # 后要空一个半角字符(英文空格)。iii) 如果注释与代码同行,# 前要空两个半角字符(英文空格)。iv)保留注释中的``符号(为了表示代码部分,如变量名、函数名等)。v)注释中中文和英文之间不要空格。vi)贪婪换行:只有当一行注释抵到78字符时再换行。
* 不要新加空行(这样会另起一个自然段)。
* 术语要保留英文翻译。现在很多地方漏了英文翻译。格式:*术语*(terminology)
* 正文和代码注释均使用中文标点。例如,中文括号要用全角括号(),不是英文半角()。例外:所有表示形状的括号和逗号(逗号后紧跟半角英文空格)用英文半角,例如“(批量大小, 词数)”而不是“(批量大小,词数)”
* 英文在标题里或句首全部不要首字母大写(即便在标题的第一个词)。除非本身是首字母大写的术语
* 不要客气。“您”->“你”,去掉“请”

277
TERMINOLOGY.md Normal file
View File

@@ -0,0 +1,277 @@
## 英汉术语对照
鞍点,saddle point
变换,transform
编码器,encoder
标签,label
步幅,stride
参数,parameter
长短期记忆网络,long short-term memory (LSTM)
超参数,hyperparameter
层序softmax,hierarchical softmax
查准率,precision
成本,cost
词表,vocabulary
词嵌入,word embedding
词向量,word vector
词元,token
词元分析器,tokenizer
词元化,tokenize
汇聚层,pooling layer
稠密,dense
大小,size
导入,import
轮,epoch
暂退法,dropout
动量法,momentum (method)
独立同分布,independent and identically distributed (i.i.d.)
端到端,end-to-end
多层感知机,multilayer perceptron
多头注意力,multi-head attention
二元分类,binary classification
二元,bigram
子采样,subsample
发散,diverge
泛化,generalization
泛化误差,generalization error
方差,variance
分类,classification
分类器,classifier
负采样,negative sampling
感受野,receptive field
格拉姆矩阵,Gram matrix
共现,co-occurrence
广播,broadcast
规范化,normalization
过拟合,overfitting
核回归,kernel regression
恒等映射,identity mapping
假设,hypothesis
基准,baseline
激活函数,activation function
解码器,decoder
近似法,approximate method
经验风险最小化,empirical risk minimization
局部最小值,local minimum
卷积核,convolutional kernel
卷积神经网络,convolutional neural network
决策边界,decision boundary
均值,mean
均方误差,mean squared error
均匀采样,uniform sampling
块,block
困惑度,perplexity
拉普拉斯平滑,Laplace smoothing
连结,concatenate
类,class
交叉熵,cross-entropy
连续词袋,continous bag-of-words (CBOW)
零张量,zero tensor
流水线,pipeline
滤波器,filter
门控循环单元,gated recurrent units (GRU)
目标检测,object detection
偏置,bias
偏导数,partial derivative
偏移量,offset
批量,batch
齐普夫定律,Zipf's law
欠拟合,underfitting
情感分析,sentiment analysis
全连接层,fully-connected layer
权重,weight
三元,trigram
上采样,upsample
上下文变量,context variable
上下文窗口,context window
上下文词,context word
上下文向量,context vector
实例/示例,instance
收敛,converge
属性,property
数值方法,numerical method
数据集,dataset
数据示例,data instance
数据样例,data example
顺序分区,sequential partitioning
softmax回归,softmax regression
随机采样,random sampling
损失函数,loss function
双向循环神经网络,bidirectional recurrent neural network
特征,feature
特征图,feature map
特征值,eigenvalue
梯度,gradient
梯度裁剪,gradient clipping
梯度消失,vanishing gradients
填充,padding
跳元模型,skip-gram model
调参,tune hyperparameter
停用词,stop words
通道,channel
凸优化,convex optimization
图像,image
未知词元,unknown token
无偏估计,unbiased estimate
误差,error
小批量,minibatch
小批量梯度,minibatch gradient
线性模型,linear model
线性回归,linear regression
协同过滤,collaborative filtering
学习率,learning rate
训练误差,training error
循环神经网络,recurrent neural network (RNN)
样例,example
一维梯度下降,gradient descent in one-dimensional space
一元,unigram
隐藏变量,hidden variable
隐藏层,hidden layer
优化器,optimizer
语料库,corpus
运算符,operator
自注意力,self-attention
真实值,ground truth
指标,metric
支持向量机,support vector machine
注意力机制,attention mechanism
注意力模型,attention model
注意力提示,attention cue
准确率/精度,accuracy

View File

@@ -0,0 +1,3 @@
# 计算图
在此处书写计算图内容。。。。

View File

@@ -0,0 +1,14 @@
# 导论
本书试图全面地讲解机器学习系统的设计和实现,从而帮助学生,工程师和科研人员理解机器学习系统背后的原理,并且可以根据自身需求改进和构建机器学习系统。
## 机器学习应用
通俗来讲,机器学习是指从数据中学习出有用知识的计算技术。从处理的数据类型和学习模式来说,机器学习可以分为监督学习(Supervised Learning)、无监督学习(Unsupervised Learning)、强化学习(Reinforcement Learning)等等。监督学习是已知输入输出对应关系情况下的学习,比如给定输入图像和它对应的内容标签,则学习图像分类(Classification);而无监督学习是只有输入数据但不知道输出标签情况下的学习,比如:给定一堆猫和狗的图像,自主学会猫和狗的分类,这种无监督分类也称为聚类(Clustering);强化学习则是给定一个学习环境和任务目标,算法自主地去不断尝试、改进自己、以实现任务目标。比如AlphaGo围棋就是用强化学习实现的,给定的环境是围棋的规则、而目标则是胜利得分。
从应用领域上划分,主要可以包括计算机视觉、自然语言处理和智能决策这三大部分,而且这三大部分之间也有很多交集。
狭义上来讲基于图像的应用都可归为计算机视觉方面的应用,典型的应用有人脸识别、物体识别、目标跟踪、人体姿态估计、以及图像的理解、修复、分割与检测等等。
计算机视觉方法广泛应用于自动驾驶、智慧城市、智慧安防等领域。
自然语言处理涉及文本或者语音方面的应用,典型的应用包括语言翻译、文本转语音、语音转文本、以及文本理解、分类、风格变换与纠错等等。
计算机视觉和自然语言处理有很多交集,例如图像的文本描述生成、基于文本的图像生成、基于文本的图像处理等应用都同时涉及到了语言和图像两种数据类型。
智能决策方面,往往通过结合计算机视觉、自然语言处理、强化学习、控制论等技术手段,实现决策类任务,广泛用于机器人、自动驾驶、游戏、推荐系统、智能工厂、智能电网等领域。

View File

@@ -0,0 +1,3 @@
# 编程模型
在此书写编程模型内容

110
config.ini Normal file
View File

@@ -0,0 +1,110 @@
[project]
name = machine laerning system
title = 机器学习系统:设计和实现
author = Luo Mai, Hao Dong
copyright = 2022, All authors.
release = 1.0.0
lang = zh
[build]
# A list of wildcards to indicate the markdown files that need to be evaluated as
# Jupyter notebooks.
notebooks = *.md */*.md
# A list of files that will be copied to the build folder.
resources = img/ mlsyszh/ mlsys.bib
# Files that will be skipped.
exclusions = */*_origin.md README.md STYLE_GUIDE.md INFO.md CODE_OF_CONDUCT.md CONTRIBUTING.md contrib/*md
# If True (default), then will evaluate the notebook to obtain outputs.
eval_notebook = True
tabs = mindspore, pytorch, tensorflow
sphinx_configs = numfig_format = {'figure': '图%%s', 'table': '表%%s', 'code-block': '列表%%s', 'section': '%%s节'}
latex_elements = {
'utf8extra' : '',
'inputenc' : '',
'babel' : r'''\usepackage[english]{babel}''',
'preamble' : r'''
\usepackage{ctex}
\setmainfont{Source Serif Pro}
\setsansfont{Source Sans Pro}
\setmonofont{Source Code Pro}
\setCJKmainfont[BoldFont=Source Han Serif SC SemiBold]{Source Han Serif SC}
\setCJKsansfont[BoldFont=Source Han Sans SC Medium]{Source Han Sans SC Normal}
\setCJKmonofont{Source Han Sans SC Normal}
\addto\captionsenglish{\renewcommand{\chaptername}{}}
\addto\captionsenglish{\renewcommand{\contentsname}{目录}}
\usepackage[draft]{minted}
\fvset{breaklines=true, breakanywhere=true}
\setlength{\headheight}{13.6pt}
\makeatletter
\fancypagestyle{normal}{
\fancyhf{}
\fancyfoot[LE,RO]{{\py@HeaderFamily\thepage}}
\fancyfoot[LO]{{\py@HeaderFamily\nouppercase{\rightmark}}}
\fancyfoot[RE]{{\py@HeaderFamily\nouppercase{\leftmark}}}
\fancyhead[LE,RO]{{\py@HeaderFamily }}
}
\makeatother
\CJKsetecglue{}
\usepackage{zhnumber}
''',
# The font size ('10pt', '11pt' or '12pt').
'pointsize': '10pt',
# Latex figure (float) alignment
'figure_align': 'H',
'fncychap': '\\usepackage[Sonny]{fncychap}',
}
[html]
# A list of links that is displayed on the navbar. A link consists of three
# items: name, URL, and a fontawesome icon
# (https://fontawesome.com/icons?d=gallery). Items are separated by commas.
# PDF, http://numpy.d2l.ai/d2l-en.pdf, fas fa-file-pdf,
header_links = GitHub, https://github.com/openmlsys/openmlsys-zh, fab fa-github,
favicon = static/favicon.png
# html_logo = static/logo-with-text.png
[pdf]
# The file used to post-process the generated tex file.
# post_latex = ./static/post_latex/main.py
latex_logo = static/logo.png
#[deploy]
#other_file_s3urls = s3://d2l-webdata/releases/d2l-zh/d2l-zh-1.0.zip
# s3://d2l-webdata/releases/d2l-zh/d2l-zh-1.1.zip
# s3://d2l-webdata/releases/d2l-zh/d2l-zh-2.0.0.zip
#google_analytics_tracking_id = UA-96378503-2
#[colab]
#github_repo = mxnet, d2l-ai/d2l-zh-colab
# pytorch, d2l-ai/d2l-zh-pytorch-colab
# tensorflow, d2l-ai/d2l-zh-tensorflow-colab
#replace_svg_url = img, http://d2l.ai/_images
#libs = mxnet, mxnet, -U mxnet-cu101==1.7.0
# mxnet, d2l, git+https://github.com/d2l-ai/d2l-zh@release # installing d2l
# pytorch, d2l, git+https://github.com/d2l-ai/d2l-zh@release # installing d2l
# tensorflow, d2l, git+https://github.com/d2l-ai/d2l-zh@release # installing d2l

9
index.md Normal file
View File

@@ -0,0 +1,9 @@
# 机器学习系统:设计和实现
```toc
:maxdepth: 2
:numbered:
chapter_introduction/index
chapter_programming_model/index
chapter_computational_graph/index

BIN
static/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
static/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB