From e812f74222691502f6e4bfba041bc855889dd866 Mon Sep 17 00:00:00 2001
From: 1375626371 <40328311+1375626371@users.noreply.github.com>
Date: Wed, 13 Apr 2022 17:58:59 +0800
Subject: [PATCH] Chinese - Chapter 1 finished (#113)
* Chinese - Chapter 1 finished
* Add zh to the languages field
Co-authored-by: petrichor1122 <87262598+petrichor1122@users.noreply.github.com>
Co-authored-by: zhlhyx <95976146+zhlhyx@users.noreply.github.com>
---
.github/workflows/build_documentation.yml | 2 +-
.github/workflows/build_pr_documentation.yml | 2 +-
chapters/zh/_toctree.yml | 23 ++
chapters/zh/chapter1/1.mdx | 52 ++++
chapters/zh/chapter1/10.mdx | 253 ++++++++++++++++
chapters/zh/chapter1/2.mdx | 20 ++
chapters/zh/chapter1/3.mdx | 287 +++++++++++++++++++
chapters/zh/chapter1/4.mdx | 172 +++++++++++
chapters/zh/chapter1/5.mdx | 17 ++
chapters/zh/chapter1/6.mdx | 17 ++
chapters/zh/chapter1/7.mdx | 16 ++
chapters/zh/chapter1/8.mdx | 31 ++
chapters/zh/chapter1/9.mdx | 11 +
13 files changed, 901 insertions(+), 2 deletions(-)
create mode 100644 chapters/zh/_toctree.yml
create mode 100644 chapters/zh/chapter1/1.mdx
create mode 100644 chapters/zh/chapter1/10.mdx
create mode 100644 chapters/zh/chapter1/2.mdx
create mode 100644 chapters/zh/chapter1/3.mdx
create mode 100644 chapters/zh/chapter1/4.mdx
create mode 100644 chapters/zh/chapter1/5.mdx
create mode 100644 chapters/zh/chapter1/6.mdx
create mode 100644 chapters/zh/chapter1/7.mdx
create mode 100644 chapters/zh/chapter1/8.mdx
create mode 100644 chapters/zh/chapter1/9.mdx
diff --git a/.github/workflows/build_documentation.yml b/.github/workflows/build_documentation.yml
index a03061dc8..8e0f0b7e9 100644
--- a/.github/workflows/build_documentation.yml
+++ b/.github/workflows/build_documentation.yml
@@ -14,6 +14,6 @@ jobs:
package: course
path_to_docs: course/chapters/
additional_args: --not_python_module
- languages: ar bn en es fa fr he ko pt ru th tr
+ languages: ar bn en es fa fr he ko pt ru th tr zh
secrets:
token: ${{ secrets.HUGGINGFACE_PUSH }}
\ No newline at end of file
diff --git a/.github/workflows/build_pr_documentation.yml b/.github/workflows/build_pr_documentation.yml
index 84af57f75..ff5039db9 100644
--- a/.github/workflows/build_pr_documentation.yml
+++ b/.github/workflows/build_pr_documentation.yml
@@ -16,5 +16,5 @@ jobs:
package: course
path_to_docs: course/chapters/
additional_args: --not_python_module
- languages: ar bn en es fa fr he ko pt ru th tr
+ languages: ar bn en es fa fr he ko pt ru th tr zh
hub_base_path: https://moon-ci-docs.huggingface.co/course
diff --git a/chapters/zh/_toctree.yml b/chapters/zh/_toctree.yml
new file mode 100644
index 000000000..453fc5e99
--- /dev/null
+++ b/chapters/zh/_toctree.yml
@@ -0,0 +1,23 @@
+- title: 1. Transformer 模型
+ sections:
+ - local: chapter1/1
+ title: 章节简介
+ - local: chapter1/2
+ title: 自然语言处理
+ - local: chapter1/3
+ title: Transformers能做什么?
+ - local: chapter1/4
+ title: Transformers 是如何工作的?
+ - local: chapter1/5
+ title: 编码器模型
+ - local: chapter1/6
+ title: 解码器模型
+ - local: chapter1/7
+ title: 序列到序列模型
+ - local: chapter1/8
+ title: 偏见和局限性
+ - local: chapter1/9
+ title: 总结
+ - local: chapter1/10
+ title: 章末小测验
+ quiz: 1
\ No newline at end of file
diff --git a/chapters/zh/chapter1/1.mdx b/chapters/zh/chapter1/1.mdx
new file mode 100644
index 000000000..68e6a14c7
--- /dev/null
+++ b/chapters/zh/chapter1/1.mdx
@@ -0,0 +1,52 @@
+# 简介
+
+## 欢迎来到🤗课程
+
+
+
+本课程将使用 Hugging Face 生态系统中的库——🤗 Transformers、🤗 Datasets、🤗 Tokenizers 和 🤗 Accelerate——以及 Hugging Face Hub 教你自然语言处理 (NLP)。它是完全免费的,并且没有广告。
+
+
+## 有什么是值得期待的?
+
+以下是课程的简要概述:
+
+
+
+
+
+
+- 第 1 章到第 4 章介绍了 🤗 Transformers 库的主要概念。在本课程的这一部分结束时,您将熟悉 Transformer 模型的工作原理,并将了解如何使用 [Hugging Face Hub](https://huggingface.co/models) 中的模型,在数据集上对其进行微调,并在 Hub 上分享您的结果。
+- 第 5 章到第 8 章在深入研究经典 NLP 任务之前,教授 🤗 Datasets和 🤗 Tokenizers的基础知识。在本部分结束时,您将能够自己解决最常见的 NLP 问题。
+- 第 9 章到第 12 章更加深入,探讨了如何使用 Transformer 模型处理语音处理和计算机视觉中的任务。在此过程中,您将学习如何构建和分享模型,并针对生产环境对其进行优化。在这部分结束时,您将准备好将🤗 Transformers 应用于(几乎)任何机器学习问题!
+
+这个课程:
+
+* 需要良好的 Python 知识
+* 最好先学习深度学习入门课程,例如[DeepLearning.AI](https://www.deeplearning.ai/) 提供的 [fast.ai实用深度学习教程](https://course.fast.ai/)
+* 不需要事先具备 [PyTorch](https://pytorch.org/) 或 [TensorFlow](https://www.tensorflow.org/) 知识,虽然熟悉其中任何一个都会对huggingface的学习有所帮助
+
+完成本课程后,我们建议您查看 [DeepLearning.AI的自然语言处理系列课程](https://www.coursera.org/specializations/natural-language-processing?utm_source=deeplearning-ai&utm_medium=institutions&utm_campaign=20211011-nlp-2-hugging_face-page-nlp-refresh),其中涵盖了广泛的传统 NLP 模型,如朴素贝叶斯和 LSTM,这些模型非常值得了解!
+
+## 我们是谁?
+
+关于作者:
+
+**Matthew Carrigan** 是 Hugging Face 的机器学习工程师。他住在爱尔兰都柏林,之前在 Parse.ly 担任机器学习工程师,在此之前,他在Trinity College Dublin担任博士后研究员。他不相信我们会通过扩展现有架构来实现 AGI,但无论如何都对机器人充满希望。
+
+**Lysandre Debut** 是 Hugging Face 的机器学习工程师,从早期的开发阶段就一直致力于 🤗 Transformers 库。他的目标是通过使用非常简单的 API 开发工具,让每个人都可以使用 NLP。
+
+**Sylvain Gugger** 是 Hugging Face 的一名研究工程师,也是 🤗Transformers库的核心维护者之一。此前,他是 fast.ai 的一名研究科学家,他与Jeremy Howard 共同编写了[Deep Learning for Coders with fastai and Py Torch](https://learning.oreilly.com/library/view/deep-learning-for/9781492045519/)。他的主要研究重点是通过设计和改进允许模型在有限资源上快速训练的技术,使深度学习更容易普及。
+
+**Merve Noyan** 是 Hugging Face 的开发者倡导者,致力于开发工具并围绕它们构建内容,以使每个人的机器学习平民化。
+
+**Lucile Saulnier** 是 Hugging Face 的机器学习工程师,负责开发和支持开源工具的使用。她还积极参与了自然语言处理领域的许多研究项目,例如协作训练和 BigScience。
+
+**Lewis Tunstall** 是 Hugging Face 的机器学习工程师,专注于开发开源工具并使更广泛的社区可以使用它们。他也是即将出版的一本书[O’Reilly book on Transformers](https://www.oreilly.com/library/view/natural-language-processing/9781098103231/)的作者之一。
+
+**Leandro von Werra** 是 Hugging Face 开源团队的机器学习工程师,也是即将出版的一本书[O’Reilly book on Transformers](https://www.oreilly.com/library/view/natural-language-processing/9781098103231/)的作者之一。他拥有多年的行业经验,通过在整个机器学习堆栈中工作,将 NLP 项目投入生产。
+
+你准备好了吗?在本章中,您将学习:
+* 如何使用 `pipeline()` 函数解决文本生成、分类等NLP任务
+* 关于 Transformer 架构
+* 如何区分编码器、解码器和编码器-解码器架构和用例
diff --git a/chapters/zh/chapter1/10.mdx b/chapters/zh/chapter1/10.mdx
new file mode 100644
index 000000000..23f768115
--- /dev/null
+++ b/chapters/zh/chapter1/10.mdx
@@ -0,0 +1,253 @@
+
+
+# 章末小测试
+
+这一章涵盖了很多内容! 如果有一些不太明白的地方,请不要担心; 下一章将帮助你了解这些模块在底层是如何工作的。
+
+让我们来测试一下你在这一章学到了什么!
+
+### 1. 探索 Hub 并寻找 `roberta-large-mnli` checkpoint。 它可以完成什么类型的任务?
+
+
+roberta-large-mnli 页面回顾一下."
+ },
+ {
+ text: "文本分类",
+ explain: "更准确地说,它对两个句子在三个标签(矛盾、无关、相近)之间的逻辑链接进行分类——这项任务也称为自然语言推理.",
+ correct: true
+ },
+ {
+ text: "文本生成",
+ explain: "点击前往roberta-large-mnli 页面回顾一下."
+ }
+ ]}
+/>
+
+### 2. 下面的代码将会返回什么结果?
+
+```py
+from transformers import pipeline
+
+ner = pipeline("ner", grouped_entities=True)
+ner("My name is Sylvain and I work at Hugging Face in Brooklyn.")
+```
+
+sentiment-analysis pipeline将会返回这些."
+ },
+ {
+ text: "它将返回一个生成的文本来完成这句话。",
+ explain: "这个选项是不对的 — text-generation pipeline将会返回这些.",
+ },
+ {
+ text: "它将返回代表人员、组织或位置的单词。",
+ explain: "此外,使用 grouped_entities=True,它会将属于同一实体的单词组合在一起,例如“Hugging Face”。",
+ correct: true
+ }
+ ]}
+/>
+
+### 3. 在此代码示例中...的地方应该填写什么?
+
+```py
+from transformers import pipeline
+
+filler = pipeline("fill-mask", model="bert-base-cased")
+result = filler("...")
+```
+
+ has been waiting for you.",
+ explain: "这个选项是不对的。 请查看 bert-base-cased 模型卡片,然后再尝试找找错在哪里。"
+ },
+ {
+ text: "This [MASK] has been waiting for you.",
+ explain: "正解! 这个模型的mask的掩码是[MASK].",
+ correct: true
+ },
+ {
+ text: "This man has been waiting for you.",
+ explain: "这个选项是不对的。 这个pipeline的作用是填充经过mask的文字,因此它需要在输入的文本中存在mask的token。"
+ }
+ ]}
+/>
+
+### 4. 为什么这段代码会无法运行?
+
+```py
+from transformers import pipeline
+
+classifier = pipeline("zero-shot-classification")
+result = classifier("This is a course about the Transformers library")
+```
+
+candidate_labels=[...].",
+ correct: true
+ },
+ {
+ text: "这个pipeline需要多个句子,而不仅仅是一个。",
+ explain: "这个选项是不对的。尽管正确使用时,此pipeline可以同时处理多个句子(与所有其他pipeline一样)。"
+ },
+ {
+ text: "像往常一样,🤗 Transformers库出故障了。",
+ explain: "对此,我们不予置评!"
+ },
+ {
+ text: "该pipeline需要更长的输入; 这个句子太短了。",
+ explain: "这个选项是不对的。 不过请注意,在这个pipeline处理时,太长的文本将被截断。"
+ }
+ ]}
+/>
+
+### 5. “迁移学习”是什么意思?
+
+
+
+### 6. 语言模型在预训练时通常不需要标签,这样的说法是否正确。
+
+
+自监督,这意味着标签是根据输入自动创建的(例如:预测下一个单词或填充一些[MARSK]单词)。",
+ correct: true
+ },
+ {
+ text: "错误",
+ explain: "这不是一个正确的答案。"
+ }
+ ]}
+/>
+
+
+### 7. 选择最能描述“模型(model)”、“架构(architecture)”和“权重(weights)”的句子。
+
+
+
+### 8. 你将使用以下哪种类型的模型来根据输入的提示生成文本?
+
+
+
+### 9. 你会使用哪些类型的模型来生成文本的摘要?
+
+
+
+### 10. 你会使用哪一种类型的模型来根据特定的标签对文本输入进行分类?
+
+
+
+### 11. 模型中观察到的偏见有哪些可能的来源?
+
+
diff --git a/chapters/zh/chapter1/2.mdx b/chapters/zh/chapter1/2.mdx
new file mode 100644
index 000000000..1b5ee0ea6
--- /dev/null
+++ b/chapters/zh/chapter1/2.mdx
@@ -0,0 +1,20 @@
+# 自然语言处理
+
+在进入 Transformer 模型之前,让我们快速概述一下自然语言处理是什么以及我们为什么这么重视它。
+
+## 什么是自然语言处理?
+
+NLP 是语言学和机器学习交叉领域,专注于理解与人类语言相关的一切。 NLP 任务的目标不仅是单独理解单个单词,而且是能够理解这些单词的上下文。
+
+以下是常见 NLP 任务的列表,每个任务都有一些示例:
+
+- **对整个句子进行分类**: 获取评论的情绪,检测电子邮件是否为垃圾邮件,确定句子在语法上是否正确或两个句子在逻辑上是否相关
+- **对句子中的每个词进行分类**: 识别句子的语法成分(名词、动词、形容词)或命名实体(人、地点、组织)
+- **生成文本内容**: 用自动生成的文本完成提示,用屏蔽词填充文本中的空白
+- **从文本中提取答案**: 给定问题和上下文,根据上下文中提供的信息提取问题的答案
+- **从输入文本生成新句子**: 将文本翻译成另一种语言,总结文本
+
+NLP 不仅限于书面文本。它还解决了语音识别和计算机视觉中的复杂挑战,例如生成音频样本的转录或图像描述。
+## 为什么具有挑战性?
+
+计算机处理信息的方式与人类不同。例如,当我们读到“我饿了”这句话时,我们很容易理解它的意思。同样,给定两个句子,例如“我很饿”和“我很伤心”,我们可以轻松确定它们的相似程度。对于机器学习 (ML) 模型,此类任务更加困难。文本需要以一种使模型能够从中学习的方式进行处理。而且由于语言很复杂,我们需要仔细考虑必须如何进行这种处理。关于如何表示文本已经做了很多研究,我们将在下一章中介绍一些方法。
\ No newline at end of file
diff --git a/chapters/zh/chapter1/3.mdx b/chapters/zh/chapter1/3.mdx
new file mode 100644
index 000000000..076263ba4
--- /dev/null
+++ b/chapters/zh/chapter1/3.mdx
@@ -0,0 +1,287 @@
+# Transformers能做什么?
+
+
+
+在本节中,我们将看看 Transformer 模型可以做什么,并使用 🤗 Transformers 库中的第一个工具:pipeline() 函数。
+
+👀 看到那个右上角的 在Colab中打开的按钮了吗? 单击它就可以打开一个包含本节所有代码示例的 Google Colab 笔记本。 每一个有实例代码的小节都会有它。
+
+如果您想在本地运行示例,我们建议您查看准备.
+
+
+## Transformer被应用于各个方面!
+Transformer 模型用于解决各种 NLP 任务,就像上一节中提到的那样。以下是一些使用 Hugging Face 和 Transformer 模型的公司和组织,他们也通过分享他们的模型回馈社区:
+
+![使用 Hugging Face 的公司](https://huggingface.co/course/static/chapter1/companies.PNG)
+[🤗 Transformers 库](https://github.com/huggingface/transformers)提供了创建和使用这些共享模型的功能。[模型中心(hub)](https://huggingface.co/models)包含数千个任何人都可以下载和使用的预训练模型。您还可以将自己的模型上传到 Hub!
+
+
+⚠️ Hugging Face Hub 不限于 Transformer 模型。任何人都可以分享他们想要的任何类型的模型或数据集!创建一个 Huggingface.co 帐户(https://huggingface.co/join)以使用所有可用功能!
+
+
+在深入研究 Transformer 模型的底层工作原理之前,让我们先看几个示例,看看它们如何用于解决一些有趣的 NLP 问题。
+
+## 使用pipelines
+
+
+(这里有一个视频,但是国内可能打不开,译者注)
+
+
+🤗 Transformers 库中最基本的对象是 **pipeline()** 函数。它将模型与其必要的预处理和后处理步骤连接起来,使我们能够通过直接输入任何文本并获得最终的答案:
+
+```python
+from transformers import pipeline
+
+classifier = pipeline("sentiment-analysis")
+classifier("I've been waiting for a HuggingFace course my whole life.")
+```
+```python out
+[{'label': 'POSITIVE', 'score': 0.9598047137260437}]
+```
+
+
+我们也可以多传几句!
+```python
+classifier(
+ ["I've been waiting for a HuggingFace course my whole life.", "I hate this so much!"]
+)
+```
+```python out
+[{'label': 'POSITIVE', 'score': 0.9598047137260437},
+ {'label': 'NEGATIVE', 'score': 0.9994558095932007}]
+```
+默认情况下,此pipeline选择一个特定的预训练模型,该模型已针对英语情感分析进行了微调。创建**分类器**对象时,将下载并缓存模型。如果您重新运行该命令,则将使用缓存的模型,无需再次下载模型。
+
+将一些文本传递到pipeline时涉及三个主要步骤:
+
+1. 文本被预处理为模型可以理解的格式。
+2. 预处理的输入被传递给模型。
+3. 模型处理后输出最终人类可以理解的结果。
+
+目前[可用的一些pipeline](https://huggingface.co/transformers/main_classes/pipelines.html)是:
+
+* **特征提取**(获取文本的向量表示)
+* **填充空缺**
+* **ner**(命名实体识别)
+* **问答**
+* **情感分析**
+* **文本摘要**
+* **文本生成**
+* **翻译**
+* **零样本分类**
+
+让我们来看看其中的一些吧!
+
+## 零样本分类
+我们将首先处理一项非常具挑战性的任务,我们需要对尚未标记的文本进行分类。这是实际项目中的常见场景,因为注释文本通常很耗时并且需要领域专业知识。对于这项任务**zero-shot-classification**pipeline非常强大:它允许您直接指定用于分类的标签,因此您不必依赖预训练模型的标签。下面的模型展示了如何使用这两个标签将句子分类为正面或负面——但也可以使用您喜欢的任何其他标签集对文本进行分类。
+
+```python
+from transformers import pipeline
+
+classifier = pipeline("zero-shot-classification")
+classifier(
+ "This is a course about the Transformers library",
+ candidate_labels=["education", "politics", "business"],
+)
+```
+```python out
+{'sequence': 'This is a course about the Transformers library',
+ 'labels': ['education', 'business', 'politics'],
+ 'scores': [0.8445963859558105, 0.111976258456707, 0.043427448719739914]}
+```
+
+此pipeline称为zero-shot,因为您不需要对数据上的模型进行微调即可使用它。它可以直接返回您想要的任何标签列表的概率分数!
+
+✏️**快来试试吧!**使用您自己的序列和标签,看看模型的行为。
+
+
+## 文本生成
+现在让我们看看如何使用pipeline来生成一些文本。这里的主要使用方法是您提供一个提示,模型将通过生成剩余的文本来自动完成整段话。这类似于许多手机上的预测文本功能。文本生成涉及随机性,因此如果您没有得到相同的如下所示的结果,这是正常的。
+
+```python
+from transformers import pipeline
+
+generator = pipeline("text-generation")
+generator("In this course, we will teach you how to")
+```
+```python out
+[{'generated_text': 'In this course, we will teach you how to understand and use '
+ 'data flow and data interchange when handling user data. We '
+ 'will be working with one or more of the most commonly used '
+ 'data flows — data flows of various types, as seen by the '
+ 'HTTP'}]
+```
+您可以使用参数 **num_return_sequences** 控制生成多少个不同的序列,并使用参数 **max_length** 控制输出文本的总长度。
+
+
+✏️**快来试试吧!**使用 num_return_sequences 和 max_length 参数生成两个句子,每个句子 15 个单词。
+
+
+## 在pipeline中使用 Hub 中的其他模型
+前面的示例使用了默认模型,但您也可以从 Hub 中选择特定模型以在特定任务的pipeline中使用 - 例如,文本生成。转到[模型中心(hub)](https://huggingface.co/models)并单击左侧的相应标签将会只显示该任务支持的模型。[例如这样](https://huggingface.co/models?pipeline_tag=text-generation)。
+
+让我们试试 [**distilgpt2**](https://huggingface.co/distilgpt2) 模型吧!以下是如何在与以前相同的pipeline中加载它:
+
+```python
+from transformers import pipeline
+
+generator = pipeline("text-generation", model="distilgpt2")
+generator(
+ "In this course, we will teach you how to",
+ max_length=30,
+ num_return_sequences=2,
+)
+```
+```python out
+[{'generated_text': 'In this course, we will teach you how to manipulate the world and '
+ 'move your mental and physical capabilities to your advantage.'},
+ {'generated_text': 'In this course, we will teach you how to become an expert and '
+ 'practice realtime, and with a hands on experience on both real '
+ 'time and real'}]
+```
+您可以通过单击语言标签来筛选搜索结果,然后选择另一种文本生成模型的模型。模型中心(hub)甚至包含支持多种语言的多语言模型。
+
+通过单击选择模型后,您会看到有一个小组件,可让您直接在线试用。通过这种方式,您可以在下载之前快速测试模型的功能。
+
+✏️**快来试试吧!**使用标签筛选查找另一种语言的文本生成模型。使用小组件测试并在pipeline中使用它!
+
+
+## 推理 API
+所有模型都可以使用 Inference API 直接通过浏览器进行测试,该 API 可在 [Hugging Face 网站](https://huggingface.co/)上找到。通过输入自定义文本并观察模型的输出,您可以直接在此页面上使用模型。
+
+小组件形式的推理 API 也可作为付费产品使用,如果您的工作流程需要它,它会派上用场。有关更多详细信息,请参阅[定价页面](https://huggingface.co/pricing)。
+
+## Mask filling
+您将尝试的下一个pipeline是 **fill-mask**。此任务的想法是填充给定文本中的空白:
+```python
+from transformers import pipeline
+
+unmasker = pipeline("fill-mask")
+unmasker("This course will teach you all about models.", top_k=2)
+```
+```python out
+[{'sequence': 'This course will teach you all about mathematical models.',
+ 'score': 0.19619831442832947,
+ 'token': 30412,
+ 'token_str': ' mathematical'},
+ {'sequence': 'This course will teach you all about computational models.',
+ 'score': 0.04052725434303284,
+ 'token': 38163,
+ 'token_str': ' computational'}]
+```
+**top_k** 参数控制要显示的结果有多少种。请注意,这里模型填充了特殊的< **mask** >词,它通常被称为掩码标记。其他掩码填充模型可能有不同的掩码标记,因此在探索其他模型时要验证正确的掩码字是什么。检查它的一种方法是查看小组件中使用的掩码。
+
+
+✏️**快来试试吧!**在 Hub 上搜索基于 bert 的模型并在推理 API 小组件中找到它的掩码。这个模型对上面pipeline示例中的句子预测了什么?
+
+
+## 命名实体识别
+命名实体识别 (NER) 是一项任务,其中模型必须找到输入文本的哪些部分对应于诸如人员、位置或组织之类的实体。让我们看一个例子:
+```python
+from transformers import pipeline
+
+ner = pipeline("ner", grouped_entities=True)
+ner("My name is Sylvain and I work at Hugging Face in Brooklyn.")
+```
+```python out
+[{'entity_group': 'PER', 'score': 0.99816, 'word': 'Sylvain', 'start': 11, 'end': 18},
+ {'entity_group': 'ORG', 'score': 0.97960, 'word': 'Hugging Face', 'start': 33, 'end': 45},
+ {'entity_group': 'LOC', 'score': 0.99321, 'word': 'Brooklyn', 'start': 49, 'end': 57}
+]
+```
+在这里,模型正确地识别出 Sylvain 是一个人 (PER),Hugging Face 是一个组织 (ORG),而布鲁克林是一个位置 (LOC)。
+
+我们在pipeline创建函数中传递选项 **grouped_entities=True** 以告诉pipeline将对应于同一实体的句子部分重新组合在一起:这里模型正确地将“Hugging”和“Face”分组为一个组织,即使名称由多个词组成。事实上,正如我们即将在下一章看到的,预处理甚至会将一些单词分成更小的部分。例如,**Sylvain** 分割为了四部分:**S、##yl、##va** 和 **##in**。在后处理步骤中,pipeline成功地重新组合了这些部分。
+
+
+✏️**快来试试吧!**在模型中心(hub)搜索能够用英语进行词性标注(通常缩写为 POS)的模型。这个模型对上面例子中的句子预测了什么?
+
+
+## 问答系统
+问答pipeline使用来自给定上下文的信息回答问题:
+```python
+from transformers import pipeline
+
+question_answerer = pipeline("question-answering")
+question_answerer(
+ question="Where do I work?",
+ context="My name is Sylvain and I work at Hugging Face in Brooklyn",
+)
+```
+```python out
+{'score': 0.6385916471481323, 'start': 33, 'end': 45, 'answer': 'Hugging Face'}
+klyn",
+)
+
+```
+请注意,此pipeline通过从提供的上下文中提取信息来工作;它不会凭空生成答案。
+
+## 文本摘要
+文本摘要是将文本缩减为较短文本的任务,同时保留文本中的主要(重要)信息。下面是一个例子:
+
+```python
+from transformers import pipeline
+
+summarizer = pipeline("summarization")
+summarizer(
+ """
+ America has changed dramatically during recent years. Not only has the number of
+ graduates in traditional engineering disciplines such as mechanical, civil,
+ electrical, chemical, and aeronautical engineering declined, but in most of
+ the premier American universities engineering curricula now concentrate on
+ and encourage largely the study of engineering science. As a result, there
+ are declining offerings in engineering subjects dealing with infrastructure,
+ the environment, and related issues, and greater concentration on high
+ technology subjects, largely supporting increasingly complex scientific
+ developments. While the latter is important, it should not be at the expense
+ of more traditional engineering.
+
+ Rapidly developing economies such as China and India, as well as other
+ industrial countries in Europe and Asia, continue to encourage and advance
+ the teaching of engineering. Both China and India, respectively, graduate
+ six and eight times as many traditional engineers as does the United States.
+ Other industrial countries at minimum maintain their output, while America
+ suffers an increasingly serious decline in the number of engineering graduates
+ and a lack of well-educated engineers.
+"""
+)
+```
+```python out
+[{'summary_text': ' America has changed dramatically during recent years . The '
+ 'number of engineering graduates in the U.S. has declined in '
+ 'traditional engineering disciplines such as mechanical, civil '
+ ', electrical, chemical, and aeronautical engineering . Rapidly '
+ 'developing economies such as China and India, as well as other '
+ 'industrial countries in Europe and Asia, continue to encourage '
+ 'and advance engineering .'}]
+```
+与文本生成一样,您指定结果的 **max_length** 或 **min_length**。
+
+## 翻译
+对于翻译,如果您在任务名称中提供语言对(例如“**translation_en_to_fr**”),则可以使用默认模型,但最简单的方法是在[模型中心(hub)](https://huggingface.co/models)选择要使用的模型。在这里,我们将尝试从法语翻译成英语:
+
+```python
+from transformers import pipeline
+
+translator = pipeline("translation", model="Helsinki-NLP/opus-mt-fr-en")
+translator("Ce cours est produit par Hugging Face.")
+```
+```python out
+[{'translation_text': 'This course is produced by Hugging Face.'}]
+
+```
+
+与文本生成和摘要一样,您可以指定结果的 **max_length** 或 **min_length**。
+
+
+
+✏️**快来试试吧!**搜索其他语言的翻译模型,尝试将前一句翻译成几种不同的语言。
+
+
+
+到目前为止显示的pipeline主要用于演示目的。它们是为特定任务而编程的,不能对他们进行自定义的修改。在下一章中,您将了解 **pipeline()** 函数内部的内容以及如何进行自定义的修改。
\ No newline at end of file
diff --git a/chapters/zh/chapter1/4.mdx b/chapters/zh/chapter1/4.mdx
new file mode 100644
index 000000000..45641e71e
--- /dev/null
+++ b/chapters/zh/chapter1/4.mdx
@@ -0,0 +1,172 @@
+# Transformers 是如何工作的?
+
+在本节中,我们将深入了解 Transformer 模型的架构。
+
+## 一点Transformers的发展历史
+
+以下是 Transformer 模型(简短)历史中的一些关键节点:
+
+