Unverified Commit 897a826d authored by Jabasukuriputo Wang's avatar Jabasukuriputo Wang Committed by GitHub
Browse files

docs(zh): review and punctuation & space fix (#26627)

parent 360ea8fc
- sections: - sections:
- local: index - local: index
title: 🤗 Transformers简介 title: 🤗 Transformers 简介
- local: quicktour - local: quicktour
title: 快速上手 title: 快速上手
- local: installation - local: installation
title: 安装 title: 安装
title: 开始使用 title: 开始使用
\ No newline at end of file
...@@ -16,20 +16,20 @@ rendered properly in your Markdown viewer. ...@@ -16,20 +16,20 @@ rendered properly in your Markdown viewer.
# 🤗 Transformers简介 # 🤗 Transformers简介
[PyTorch](https://pytorch.org/), [TensorFlow](https://www.tensorflow.org/)[JAX](https://jax.readthedocs.io/en/latest/)打造的先进的机器学习工具. [PyTorch](https://pytorch.org/)[TensorFlow](https://www.tensorflow.org/)[JAX](https://jax.readthedocs.io/en/latest/) 打造的先进的机器学习工具.
🤗 Transformers 提供了可以轻松地下载并且训练先进的预训练模型的API和工具. 使用预训练模型可以减少计算消耗和碳排放, 并且节省从头训练所需要的时间和资源. 这些模型支持不同模态中的常见任务,比如: 🤗 Transformers 提供了可以轻松地下载并且训练先进的预训练模型的 API 和工具使用预训练模型可以减少计算消耗和碳排放并且节省从头训练所需要的时间和资源这些模型支持不同模态中的常见任务,比如
📝 **自然语言处理**: 文本分类, 命名实体识别, 问答, 语言建模, 摘要, 翻译, 多项选择和文本生成.<br> 📝 **自然语言处理**文本分类命名实体识别、问答、语言建模、摘要、翻译、多项选择和文本生成<br>
🖼️ **机器视觉**: 图像分类, 目标检测和语义分割.<br> 🖼️ **机器视觉**图像分类目标检测和语义分割<br>
🗣️ **音频**: 自动语音识别和音频分类.<br> 🗣️ **音频**自动语音识别和音频分类<br>
🐙 **多模态**: 表格问答, 光学字符识别, 从扫描文档提取信息, 视频分类和视觉问答. 🐙 **多模态**表格问答光学字符识别从扫描文档提取信息视频分类和视觉问答
🤗 Transformers支持在PyTorch, TensorFlowJAX上的互操作性. 这给在模型的每个阶段使用不同的框架带来了灵活性; 在一个框架中使用几行代码训练一个模型, 然后在另一个框架中加载它并进行推理. 模型也可以被导出为ONNXTorchScript格式, 用于在生产环境中部署. 🤗 Transformers 支持在 PyTorchTensorFlowJAX 上的互操作性. 这给在模型的每个阶段使用不同的框架带来了灵活性在一个框架中使用几行代码训练一个模型然后在另一个框架中加载它并进行推理模型也可以被导出为 ONNXTorchScript 格式用于在生产环境中部署
马上加入在[Hub](https://huggingface.co/models), [forum](https://discuss.huggingface.co/), 或者[Discord](https://discord.com/invite/JfAtkvEtRb)上正在快速发展的社区吧! 马上加入在 [Hub](https://huggingface.co/models)[论坛](https://discuss.huggingface.co/) 或者 [Discord](https://discord.com/invite/JfAtkvEtRb) 上正在快速发展的社区吧
## 如果你需要来自Hugging Face团队的个性化支持 ## 如果你需要来自 Hugging Face 团队的个性化支持
<a target="_blank" href="https://huggingface.co/support"> <a target="_blank" href="https://huggingface.co/support">
<img alt="HuggingFace Expert Acceleration Program" src="https://cdn-media.huggingface.co/marketing/transformers/new-support-improved.png" style="width: 100%; max-width: 600px; border: 1px solid #eee; border-radius: 4px; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);"> <img alt="HuggingFace Expert Acceleration Program" src="https://cdn-media.huggingface.co/marketing/transformers/new-support-improved.png" style="width: 100%; max-width: 600px; border: 1px solid #eee; border-radius: 4px; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);">
...@@ -39,15 +39,15 @@ rendered properly in your Markdown viewer. ...@@ -39,15 +39,15 @@ rendered properly in your Markdown viewer.
这篇文档被组织为以下5个章节: 这篇文档被组织为以下5个章节:
- **开始使用** 包含了库的快速上手和安装说明, 便于配置和运行. - **开始使用** 包含了库的快速上手和安装说明便于配置和运行
- **教程** 是一个初学者开始的好地方. 本章节将帮助你获得你会用到的使用这个库的基本技能. - **教程** 是一个初学者开始的好地方本章节将帮助你获得你会用到的使用这个库的基本技能
- **操作指南** 向你展示如何实现一个特定目标, 比如为语言建模微调一个预训练模型或者如何创造并分享个性化模型. - **操作指南** 向你展示如何实现一个特定目标比如为语言建模微调一个预训练模型或者如何创造并分享个性化模型
- **概念指南** 对🤗 Transformers的模型, 任务和设计理念背后的基本概念和思想做了更多的讨论和解释. - **概念指南** 🤗 Transformers 的模型任务和设计理念背后的基本概念和思想做了更多的讨论和解释
- **API介绍** 描述了所有的类和函数: - **API 介绍** 描述了所有的类和函数
- **MAIN CLASSES** 详述了配置(configuration)、模型(model)、分词器(tokenizer)和流水线(pipeline)这几个最重要的类. - **MAIN CLASSES** 详述了配置configuration、模型model、分词器tokenizer和流水线pipeline这几个最重要的类
- **MODELS** 详述了在这个库中和每个模型实现有关的类和函数. - **MODELS** 详述了在这个库中和每个模型实现有关的类和函数
- **INTERNAL HELPERS** 详述了内部使用的工具类和函数. - **INTERNAL HELPERS** 详述了内部使用的工具类和函数
### 支持的模型 ### 支持的模型
...@@ -229,8 +229,8 @@ rendered properly in your Markdown viewer. ...@@ -229,8 +229,8 @@ rendered properly in your Markdown viewer.
### 支持的框架 ### 支持的框架
下表展示了库中对每个模型的支持情况, 是否具有Python分词器 (表中的"Tokenizer slow"). 是否具有由🤗 Tokenizers库支持的快速分词器(表中的"Tokenizer fast"), 是否支持Jax (通过 下表展示了库中对每个模型的支持情况,如是否具有 Python 分词器表中的Tokenizer slow”)、是否具有由 🤗 Tokenizers 库支持的快速分词器表中的Tokenizer fast”)、是否支持 Jax通过
Flax), PyTorch, 和/或者 TensorFlow. Flax)、PyTorch TensorFlow
<!--This table is updated automatically from the auto modules with _make fix-copies_. Do not update manually!--> <!--This table is updated automatically from the auto modules with _make fix-copies_. Do not update manually!-->
...@@ -395,4 +395,4 @@ Flax), PyTorch, 和/或者 TensorFlow. ...@@ -395,4 +395,4 @@ Flax), PyTorch, 和/或者 TensorFlow.
| YOLOS | ❌ | ❌ | ✅ | ❌ | ❌ | | YOLOS | ❌ | ❌ | ✅ | ❌ | ❌ |
| YOSO | ❌ | ❌ | ✅ | ❌ | ❌ | | YOSO | ❌ | ❌ | ✅ | ❌ | ❌ |
<!-- End table--> <!-- End table-->
\ No newline at end of file
...@@ -20,17 +20,17 @@ rendered properly in your Markdown viewer. ...@@ -20,17 +20,17 @@ rendered properly in your Markdown viewer.
# 安装 # 安装
为你正在使用的深度学习框架安装 🤗 Transformers、设置缓存并选择性配置 🤗 Transformers 以离线运行。 为你正在使用的深度学习框架安装 🤗 Transformers、设置缓存并选择性配置 🤗 Transformers 以离线运行。
🤗 Transformers 已在Python 3.6+、PyTorch 1.1.0+、TensorFlow 2.0+以及Flax上进行测试。针对你使用的深度学习框架,请参照以下安装说明进行安装: 🤗 Transformers 已在 Python 3.6+、PyTorch 1.1.0+、TensorFlow 2.0+ 以及 Flax 上进行测试。针对你使用的深度学习框架,请参照以下安装说明进行安装:
* [PyTorch](https://pytorch.org/get-started/locally/)安装说明。 * [PyTorch](https://pytorch.org/get-started/locally/) 安装说明。
* [TensorFlow 2.0](https://www.tensorflow.org/install/pip)安装说明。 * [TensorFlow 2.0](https://www.tensorflow.org/install/pip) 安装说明。
* [Flax](https://flax.readthedocs.io/en/latest/)安装说明。 * [Flax](https://flax.readthedocs.io/en/latest/) 安装说明。
## 使用pip安装 ## 使用 pip 安装
你应该使用[虚拟环境](https://docs.python.org/3/library/venv.html)安装 🤗 Transformers。如果你不熟悉Python虚拟环境,请查看此[教程](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/)。使用虚拟环境,你可以轻松管理不同项目,避免不同依赖项之间的兼容性问题。 你应该使用 [虚拟环境](https://docs.python.org/3/library/venv.html) 安装 🤗 Transformers。如果你不熟悉 Python 虚拟环境,请查看此 [教程](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/)。使用虚拟环境,你可以轻松管理不同项目,避免不同依赖项之间的兼容性问题。
首先,在项目目录中创建虚拟环境: 首先,在项目目录中创建虚拟环境:
...@@ -38,12 +38,12 @@ rendered properly in your Markdown viewer. ...@@ -38,12 +38,12 @@ rendered properly in your Markdown viewer.
python -m venv .env python -m venv .env
``` ```
在LinuxMacOs系统中激活虚拟环境: LinuxMacOs 系统中激活虚拟环境:
```bash ```bash
source .env/bin/activate source .env/bin/activate
``` ```
在Windows系统中激活虚拟环境: Windows 系统中激活虚拟环境:
```bash ```bash
.env/Scripts/activate .env/Scripts/activate
...@@ -55,13 +55,13 @@ source .env/bin/activate ...@@ -55,13 +55,13 @@ source .env/bin/activate
pip install transformers pip install transformers
``` ```
若仅需CPU支持,可以使用单行命令方便地安装 🤗 Transformers 和深度学习库。例如,使用以下命令安装 🤗 Transformers 和PyTorch: 若仅需 CPU 支持,可以使用单行命令方便地安装 🤗 Transformers 和深度学习库。例如,使用以下命令安装 🤗 Transformers 和 PyTorch:
```bash ```bash
pip install 'transformers[torch]' pip install 'transformers[torch]'
``` ```
🤗 Transformers 和TensorFlow 2.0: 🤗 Transformers 和 TensorFlow 2.0
```bash ```bash
pip install 'transformers[tf-cpu]' pip install 'transformers[tf-cpu]'
...@@ -71,7 +71,7 @@ pip install 'transformers[tf-cpu]' ...@@ -71,7 +71,7 @@ pip install 'transformers[tf-cpu]'
M1 / ARM用户 M1 / ARM用户
在安装TensorFLow 2.0前,你需要安装以下库 在安装 TensorFlow 2.0 前,你需要安装以下库
``` ```
brew install cmake brew install cmake
brew install pkg-config brew install pkg-config
...@@ -79,7 +79,7 @@ brew install pkg-config ...@@ -79,7 +79,7 @@ brew install pkg-config
</Tip> </Tip>
🤗 Transformers 和Flax: 🤗 Transformers 和 Flax:
```bash ```bash
pip install 'transformers[flax]' pip install 'transformers[flax]'
...@@ -105,7 +105,7 @@ python -c "from transformers import pipeline; print(pipeline('sentiment-analysis ...@@ -105,7 +105,7 @@ python -c "from transformers import pipeline; print(pipeline('sentiment-analysis
pip install git+https://github.com/huggingface/transformers pip install git+https://github.com/huggingface/transformers
``` ```
此命令下载的是最新的前沿`main`版本而不是最新的`stable`版本。`main`版本适用于跟最新开发保持一致。例如,上次正式版发布带来的bug被修复了,但新版本尚未被推出。但是,这也说明`main`版本并不一定总是稳定的。我们努力保持`main`版本的可操作性,大多数问题通常在几个小时或一天以内就能被解决。如果你遇到问题,请提个[Issue](https://github.com/huggingface/transformers/issues)以便我们能更快修复。 此命令下载的是最新的前沿 `main` 版本而不是最新的 `stable` 版本。`main` 版本适用于跟最新开发保持一致。例如,上次正式版发布带来的 bug 被修复了,但新版本尚未被推出。但是,这也说明 `main` 版本并不一定总是稳定的。我们努力保持 `main` 版本的可操作性,大多数问题通常在几个小时或一天以内就能被解决。如果你遇到问题,请提个 [Issue](https://github.com/huggingface/transformers/issues) 以便我们能更快修复。
运行以下命令以检查 🤗 Transformers 是否已被正确安装: 运行以下命令以检查 🤗 Transformers 是否已被正确安装:
...@@ -117,7 +117,7 @@ python -c "from transformers import pipeline; print(pipeline('sentiment-analysis ...@@ -117,7 +117,7 @@ python -c "from transformers import pipeline; print(pipeline('sentiment-analysis
如果你有下列需求,需要进行可编辑安装: 如果你有下列需求,需要进行可编辑安装:
* 使用源码的`main`版本。 * 使用源码的 `main` 版本。
* 为 🤗 Transformers 贡献代码,需要测试代码中的更改。 * 为 🤗 Transformers 贡献代码,需要测试代码中的更改。
使用以下命令克隆仓库并安装 🤗 Transformers: 使用以下命令克隆仓库并安装 🤗 Transformers:
...@@ -128,11 +128,11 @@ cd transformers ...@@ -128,11 +128,11 @@ cd transformers
pip install -e . pip install -e .
``` ```
这些命令将会链接你克隆的仓库以及你的Python库路径。现在,Python不仅会在正常的库路径中,也会在你克隆到的文件夹中进行查找。例如,如果你的Python包通常本安装在`~/anaconda3/envs/main/lib/python3.7/site-packages/`目录下,Python也会搜索你克隆到的文件夹:`~/transformers/` 这些命令将会链接你克隆的仓库以及你的 Python 库路径。现在,Python 不仅会在正常的库路径中搜索库,也会在你克隆到的文件夹中进行查找。例如,如果你的 Python 包通常本安装在 `~/anaconda3/envs/main/lib/python3.7/site-packages/` 目录中,在这种情况下 Python 也会搜索你克隆到的文件夹:`~/transformers/`
<Tip warning={true}> <Tip warning={true}>
如果你想继续使用这个库,必须保留`transformers`文件夹。 如果你想继续使用这个库,必须保留 `transformers` 文件夹。
</Tip> </Tip>
...@@ -143,11 +143,11 @@ cd ~/transformers/ ...@@ -143,11 +143,11 @@ cd ~/transformers/
git pull git pull
``` ```
你的Python环境将在下次运行时找到`main`版本的 🤗 Transformers。 你的 Python 环境将在下次运行时找到 `main` 版本的 🤗 Transformers。
## 使用conda安装 ## 使用 conda 安装
从conda`huggingface`频道安装: conda`huggingface` 频道安装:
```bash ```bash
conda install -c huggingface transformers conda install -c huggingface transformers
...@@ -155,25 +155,25 @@ conda install -c huggingface transformers ...@@ -155,25 +155,25 @@ conda install -c huggingface transformers
## 缓存设置 ## 缓存设置
预训练模型会被下载并本地缓存到`~/.cache/huggingface/hub`。这是由shell环境变量`TRANSFORMERS_CACHE`指定的默认目录。在Windows上,默认目录为`C:\Users\username\.cache\huggingface\hub`。你可按照以下优先级改变下面显示的shell环境变量,以指定不同的缓存目录。 预训练模型会被下载并本地缓存到 `~/.cache/huggingface/hub`。这是由环境变量 `TRANSFORMERS_CACHE` 指定的默认目录。在 Windows 上,默认目录为 `C:\Users\username\.cache\huggingface\hub`。你可按照不同优先级改变下环境变量,以指定不同的缓存目录。
1. Shell环境变量(默认): `HUGGINGFACE_HUB_CACHE``TRANSFORMERS_CACHE` 1. 环境变量(默认): `HUGGINGFACE_HUB_CACHE``TRANSFORMERS_CACHE`
2. Shell环境变量`HF_HOME` 2. 环境变量 `HF_HOME`
3. Shell环境变量 `XDG_CACHE_HOME` + `/huggingface` 3. 环境变量 `XDG_CACHE_HOME` + `/huggingface`
<Tip> <Tip>
🤗 Transformers 将会使用shell环境变量`PYTORCH_TRANSFORMERS_CACHE``PYTORCH_PRETRAINED_BERT_CACHE`如果你来自此库的较早版本并且已经设置了这些环境变量,除非你明确指定了shell环境变量`TRANSFORMERS_CACHE`. 除非你明确指定了环境变量 `TRANSFORMERS_CACHE`🤗 Transformers 将可能会使用较早版本设置的环境变量 `PYTORCH_TRANSFORMERS_CACHE``PYTORCH_PRETRAINED_BERT_CACHE`
</Tip> </Tip>
## 离线模式 ## 离线模式
🤗 Transformers 可以仅使用本地文件在防火墙或离线环境中运行。设置环境变量`TRANSFORMERS_OFFLINE=1`以启用该行为。 🤗 Transformers 可以仅使用本地文件在防火墙或离线环境中运行。设置环境变量 `TRANSFORMERS_OFFLINE=1` 以启用该行为。
<Tip> <Tip>
通过设置环境变量`HF_DATASETS_OFFLINE=1`[🤗 Datasets](https://huggingface.co/docs/datasets/)添加至你的离线训练工作流程中。 通过设置环境变量 `HF_DATASETS_OFFLINE=1`[🤗 Datasets](https://huggingface.co/docs/datasets/) 添加至你的离线训练工作流程中。
</Tip> </Tip>
...@@ -196,13 +196,13 @@ python examples/pytorch/translation/run_translation.py --model_name_or_path t5-s ...@@ -196,13 +196,13 @@ python examples/pytorch/translation/run_translation.py --model_name_or_path t5-s
另一种离线时使用 🤗 Transformers 的方法是预先下载好文件,然后在需要离线使用时指向它们的离线路径。有三种实现的方法: 另一种离线时使用 🤗 Transformers 的方法是预先下载好文件,然后在需要离线使用时指向它们的离线路径。有三种实现的方法:
* 单击[Model Hub](https://huggingface.co/models)用户界面上的 ↓ 图标下载文件。 * 单击 [Model Hub](https://huggingface.co/models) 用户界面上的 ↓ 图标下载文件。
![下载图标](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/download-icon.png) ![下载图标](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/download-icon.png)
* 使用[`PreTrainedModel.from_pretrained`][`PreTrainedModel.save_pretrained`]工作流程: * 使用 [`PreTrainedModel.from_pretrained`][`PreTrainedModel.save_pretrained`] 工作流程:
1. 预先使用[`PreTrainedModel.from_pretrained`]下载文件: 1. 预先使用 [`PreTrainedModel.from_pretrained`] 下载文件:
```py ```py
>>> from transformers import AutoTokenizer, AutoModelForSeq2SeqLM >>> from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
...@@ -211,29 +211,29 @@ python examples/pytorch/translation/run_translation.py --model_name_or_path t5-s ...@@ -211,29 +211,29 @@ python examples/pytorch/translation/run_translation.py --model_name_or_path t5-s
>>> model = AutoModelForSeq2SeqLM.from_pretrained("bigscience/T0_3B") >>> model = AutoModelForSeq2SeqLM.from_pretrained("bigscience/T0_3B")
``` ```
2. 使用[`PreTrainedModel.save_pretrained`]将文件保存至指定目录: 2. 使用 [`PreTrainedModel.save_pretrained`] 将文件保存至指定目录:
```py ```py
>>> tokenizer.save_pretrained("./your/path/bigscience_t0") >>> tokenizer.save_pretrained("./your/path/bigscience_t0")
>>> model.save_pretrained("./your/path/bigscience_t0") >>> model.save_pretrained("./your/path/bigscience_t0")
``` ```
3. 现在,你可以在离线时从指定目录使用[`PreTrainedModel.from_pretrained`]重新加载你的文件: 3. 现在,你可以在离线时从指定目录使用 [`PreTrainedModel.from_pretrained`] 重新加载你的文件:
```py ```py
>>> tokenizer = AutoTokenizer.from_pretrained("./your/path/bigscience_t0") >>> tokenizer = AutoTokenizer.from_pretrained("./your/path/bigscience_t0")
>>> model = AutoModel.from_pretrained("./your/path/bigscience_t0") >>> model = AutoModel.from_pretrained("./your/path/bigscience_t0")
``` ```
* 使用代码用[huggingface_hub](https://github.com/huggingface/huggingface_hub/tree/main/src/huggingface_hub)库下载文件: * 使用代码用 [huggingface_hub](https://github.com/huggingface/huggingface_hub/tree/main/src/huggingface_hub) 库下载文件:
1. 在你的虚拟环境中安装`huggingface_hub`库: 1. 在你的虚拟环境中安装 `huggingface_hub` 库:
```bash ```bash
python -m pip install huggingface_hub python -m pip install huggingface_hub
``` ```
2. 使用[`hf_hub_download`](https://huggingface.co/docs/hub/adding-a-library#download-files-from-the-hub)函数将文件下载到指定路径。例如,以下命令将`config.json`文件从[T0](https://huggingface.co/bigscience/T0_3B)模型下载至你想要的路径: 2. 使用 [`hf_hub_download`](https://huggingface.co/docs/hub/adding-a-library#download-files-from-the-hub) 函数将文件下载到指定路径。例如,以下命令将 `config.json` 文件从 [T0](https://huggingface.co/bigscience/T0_3B) 模型下载至你想要的路径:
```py ```py
>>> from huggingface_hub import hf_hub_download >>> from huggingface_hub import hf_hub_download
...@@ -251,6 +251,6 @@ python examples/pytorch/translation/run_translation.py --model_name_or_path t5-s ...@@ -251,6 +251,6 @@ python examples/pytorch/translation/run_translation.py --model_name_or_path t5-s
<Tip> <Tip>
请参阅[如何从Hub下载文件](https://huggingface.co/docs/hub/how-to-downstream)部分,获取有关下载存储在Hub上文件的更多详细信息。 请参阅 [如何从 Hub 下载文件](https://huggingface.co/docs/hub/how-to-downstream) 部分,获取有关下载存储在 Hub 上文件的更多详细信息。
</Tip> </Tip>
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment