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-binsvg图片转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) 不是 1020
* 空格:
* 文本中中文和英文、数字、数学公式、特殊字体等之间不要加空格
* 非行首的`: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%的大小导出pdfinfinite 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
层序softmaxhierarchical 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