问题描述
我在这里学习本教程:https://huggingface.co/transformers/training.html - 不过,我遇到了一个错误,我认为该教程缺少导入,但我不知道是哪个。
这些是我当前的导入:
# Transformers installation
! pip install transformers
# To install from source instead of the last release,comment the command above and uncomment the following one.
# ! pip install git+https://github.com/huggingface/transformers.git
! pip install datasets transformers
from transformers import pipeline
当前代码:
from datasets import load_dataset
raw_datasets = load_dataset("imdb")
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("bert-base-cased")
inputs = tokenizer(sentences,padding="max_length",truncation=True)
错误:
NameError Traceback (most recent call last)
<ipython-input-9-5a234f114e2e> in <module>()
----> 1 inputs = tokenizer(sentences,truncation=True)
NameError: name 'sentences' is not defined
解决方法
创建变量
sentences = ["Hello I'm a single sentence","And another sentence","And the very very last one"]
“正如我们在 Preprocessing data 中看到的,我们可以使用以下命令为模型准备文本输入(这是一个示例,不是您可以执行的命令)” >
,该错误指出您在作用域中没有名为 sentences
的变量。我相信本教程假定您已经有了一个句子列表并正在对其进行标记。
看看 documentation 第一个参数可以是字符串或字符串列表或字符串列表列表。
__call__(text: Union[str,List[str],List[List[str]]],...)