【问题标题】:AttributeError: 'NoneType' object has no attribute 'tokenize'AttributeError:“NoneType”对象没有属性“tokenize”
【发布时间】:2021-10-22 22:16:30
【问题描述】:

我正在尝试通过转换器使用 XLNET。但是我不断收到问题“AttributeError:'NoneType'对象没有属性'tokenize'”。我不确定如何进行。如果有人能指出我正确的方向,将不胜感激。

tokenizer = XLNetTokenizer.from_pretrained('xlnet-base-cased', do_lower_case=True)

print(' Original: ', X_train[1])

# Print the tweet split into tokens.
print('Tokenized: ', tokenizer.tokenize(X_train[1]))

# Print the tweet mapped to token ids.
print('Token IDs: ', tokenizer.convert_tokens_to_ids(tokenizer.tokenize(X_train[1])))




Original:  hey angel duh sexy really thanks haha
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-67-2b1b432b3e15> in <module>()
      2 
      3 # Print the tweet split into tokens.
----> 4 print('Tokenized: ', tokenizer.tokenize(X_train[2]))
      5 
      6 # Print the tweet mapped to token ids.

AttributeError: 'NoneType' object has no attribute 'tokenize'

【问题讨论】:

标签: python huggingface-transformers


【解决方案1】:

我假设:

from transformers import XLNetTokenizerFast
tokenizer = XLNetTokenizerFast.from_pretrained('xlnet-base-cased', do_lower_case=True)

有效吗? 在这种情况下,您只是缺少 sentencepiece 包:

pip install sentencepiece

【讨论】:

    【解决方案2】:

    如果安装了 SenencePience 仍然有错误

    当然,@cronoik 的答案是正确的。毫无疑问。但是如果你已经安装了SenencePience 包还是有错误,那就restart the runtime environment and it will work

    【讨论】:

      猜你喜欢
      • 2019-01-01
      • 2021-12-26
      • 2019-07-23
      • 2018-05-13
      • 2020-09-07
      • 2017-05-03
      • 2023-03-16
      • 2018-07-14
      • 2013-06-16
      相关资源
      最近更新 更多