【发布时间】:2021-12-26 18:12:35
【问题描述】:
我正在尝试将 XLNet 模型用于我的情绪分类项目,但收到此错误。
from transformers import XLNetTokenizer, XLNetModel
PRE_TRAINED_MODEL_NAME = 'xlnet-base-cased'
tokenizer = XLNetTokenizer.from_pretrained(PRE_TRAINED_MODEL_NAME)
input_txt = "India is my country. All Indians are my brothers and sisters"
encodings = tokenizer.encode_plus(input_txt, add_special_tokens=True, max_length=16, return_tensors='pt', return_token_type_ids=False, return_attention_mask=True, pad_to_max_length=False)
AttributeError Traceback (most recent call last)
<ipython-input-41-4b204650a45a> in <module>()
1 input_txt = "India is my country. All Indians are my brothers and sisters"
----> 2 encodings = tokenizer.encode_plus(input_txt, add_special_tokens=True, max_length=16, return_tensors='pt', return_token_type_ids=False, return_attention_mask=True, pad_to_max_length=False)
AttributeError: 'NoneType' object has no attribute 'encode_plus'
SEARCH STACK OVERFLOW
为什么我的分词器被识别为 NoneType?
【问题讨论】:
-
这个错误很清楚地告诉你
tokenizer是None。这意味着XLNetTokenizer.from_pretrained正在返回None。所以,检查一下,然后试着找出它为什么返回None。
标签: python nlp attributeerror huggingface-transformers