拥抱脸:NameError:未定义名称“句子”

问题描述

我在这里学习本教程: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]]],...)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...