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

This commit is contained in:
Jabasukuriputo Wang
2023-10-06 11:24:28 -05:00
committed by GitHub
parent 360ea8fc72
commit 897a826d83
4 changed files with 142 additions and 143 deletions

View File

@@ -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/)安装说明。
* [TensorFlow 2.0](https://www.tensorflow.org/install/pip)安装说明。
* [Flax](https://flax.readthedocs.io/en/latest/)安装说明。
* [PyTorch](https://pytorch.org/get-started/locally/) 安装说明。
* [TensorFlow 2.0](https://www.tensorflow.org/install/pip) 安装说明。
* [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.
python -m venv .env
```
在LinuxMacOs系统中激活虚拟环境
LinuxMacOs 系统中激活虚拟环境:
```bash
source .env/bin/activate
```
在Windows系统中激活虚拟环境
Windows 系统中激活虚拟环境:
```bash
.env/Scripts/activate
@@ -55,13 +55,13 @@ source .env/bin/activate
pip install transformers
```
若仅需CPU支持可以使用单行命令方便地安装 🤗 Transformers 和深度学习库。例如,使用以下命令安装 🤗 Transformers 和PyTorch
若仅需 CPU 支持,可以使用单行命令方便地安装 🤗 Transformers 和深度学习库。例如,使用以下命令安装 🤗 Transformers 和 PyTorch
```bash
pip install 'transformers[torch]'
```
🤗 Transformers 和TensorFlow 2.0:
🤗 Transformers 和 TensorFlow 2.0
```bash
pip install 'transformers[tf-cpu]'
@@ -71,7 +71,7 @@ pip install 'transformers[tf-cpu]'
M1 / ARM用户
在安装TensorFLow 2.0前,你需要安装以下库
在安装 TensorFlow 2.0 前,你需要安装以下库
```
brew install cmake
brew install pkg-config
@@ -79,7 +79,7 @@ brew install pkg-config
</Tip>
🤗 Transformers 和Flax:
🤗 Transformers 和 Flax:
```bash
pip install 'transformers[flax]'
@@ -105,7 +105,7 @@ python -c "from transformers import pipeline; print(pipeline('sentiment-analysis
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 是否已被正确安装:
@@ -117,7 +117,7 @@ python -c "from transformers import pipeline; print(pipeline('sentiment-analysis
如果你有下列需求,需要进行可编辑安装:
* 使用源码的`main`版本。
* 使用源码的 `main` 版本。
* 为 🤗 Transformers 贡献代码,需要测试代码中的更改。
使用以下命令克隆仓库并安装 🤗 Transformers
@@ -128,11 +128,11 @@ cd transformers
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}>
如果你想继续使用这个库,必须保留`transformers`文件夹。
如果你想继续使用这个库,必须保留 `transformers` 文件夹。
</Tip>
@@ -143,11 +143,11 @@ cd ~/transformers/
git pull
```
你的Python环境将在下次运行时找到`main`版本的 🤗 Transformers。
你的 Python 环境将在下次运行时找到 `main` 版本的 🤗 Transformers。
## 使用conda安装
## 使用 conda 安装
从conda`huggingface`频道安装:
conda`huggingface` 频道安装:
```bash
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`
2. Shell环境变量`HF_HOME`
3. Shell环境变量 `XDG_CACHE_HOME` + `/huggingface`
1. 环境变量(默认): `HUGGINGFACE_HUB_CACHE``TRANSFORMERS_CACHE`
2. 环境变量 `HF_HOME`
3. 环境变量 `XDG_CACHE_HOME` + `/huggingface`
<Tip>
🤗 Transformers 将会使用shell环境变量`PYTORCH_TRANSFORMERS_CACHE``PYTORCH_PRETRAINED_BERT_CACHE`如果你来自此库的较早版本并且已经设置了这些环境变量除非你明确指定了shell环境变量`TRANSFORMERS_CACHE`.
除非你明确指定了环境变量 `TRANSFORMERS_CACHE`🤗 Transformers 将可能会使用较早版本设置的环境变量 `PYTORCH_TRANSFORMERS_CACHE``PYTORCH_PRETRAINED_BERT_CACHE`
</Tip>
## 离线模式
🤗 Transformers 可以仅使用本地文件在防火墙或离线环境中运行。设置环境变量`TRANSFORMERS_OFFLINE=1`以启用该行为。
🤗 Transformers 可以仅使用本地文件在防火墙或离线环境中运行。设置环境变量 `TRANSFORMERS_OFFLINE=1` 以启用该行为。
<Tip>
通过设置环境变量`HF_DATASETS_OFFLINE=1`[🤗 Datasets](https://huggingface.co/docs/datasets/)添加至你的离线训练工作流程中。
通过设置环境变量 `HF_DATASETS_OFFLINE=1`[🤗 Datasets](https://huggingface.co/docs/datasets/) 添加至你的离线训练工作流程中。
</Tip>
@@ -196,13 +196,13 @@ python examples/pytorch/translation/run_translation.py --model_name_or_path t5-s
另一种离线时使用 🤗 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)
* 使用[`PreTrainedModel.from_pretrained`][`PreTrainedModel.save_pretrained`]工作流程:
* 使用 [`PreTrainedModel.from_pretrained`][`PreTrainedModel.save_pretrained`] 工作流程:
1. 预先使用[`PreTrainedModel.from_pretrained`]下载文件:
1. 预先使用 [`PreTrainedModel.from_pretrained`] 下载文件:
```py
>>> from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
@@ -211,29 +211,29 @@ python examples/pytorch/translation/run_translation.py --model_name_or_path t5-s
>>> model = AutoModelForSeq2SeqLM.from_pretrained("bigscience/T0_3B")
```
2. 使用[`PreTrainedModel.save_pretrained`]将文件保存至指定目录:
2. 使用 [`PreTrainedModel.save_pretrained`] 将文件保存至指定目录:
```py
>>> tokenizer.save_pretrained("./your/path/bigscience_t0")
>>> model.save_pretrained("./your/path/bigscience_t0")
```
3. 现在,你可以在离线时从指定目录使用[`PreTrainedModel.from_pretrained`]重新加载你的文件:
3. 现在,你可以在离线时从指定目录使用 [`PreTrainedModel.from_pretrained`] 重新加载你的文件:
```py
>>> tokenizer = AutoTokenizer.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
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
>>> from huggingface_hub import hf_hub_download
@@ -251,6 +251,6 @@ python examples/pytorch/translation/run_translation.py --model_name_or_path t5-s
<Tip>
请参阅[如何从Hub下载文件](https://huggingface.co/docs/hub/how-to-downstream)部分获取有关下载存储在Hub上文件的更多详细信息。
请参阅 [如何从 Hub 下载文件](https://huggingface.co/docs/hub/how-to-downstream) 部分,获取有关下载存储在 Hub 上文件的更多详细信息。
</Tip>