python - 使用 tokenizer.encode_plus 的麻烦
问题描述
#jupyter 笔记本
在那个 colab 中,从“Tokenize all the sentence.....”开始
在那部分,我遇到了麻烦“TypeError:_tokenize()得到了一个意外的关键字参数'pad_to_max_length'”
**
input_ids = []
attention_masks = []
for sent in sentences:
encoded_dict = tokenizer.encode_plus(
sent, # Sentence to encode.
add_special_tokens = True, # Add '[CLS]' and '[SEP]'
max_length = 64, # Pad & truncate all sentences.
pad_to_max_length = True,
return_attention_mask = True, # Construct attn. masks.
return_tensors = 'pt', # Return pytorch tensors.
)
解决方案
参考:本帖
“问题在于 conda 仅在 2.1.1 版(存储库信息)中提供了转换器库,并且此版本没有 pad_to_max_length 参数。”
所以也许最好的选择是卸载然后重新安装转换器(这次使用 pip install 而不是 conda forge)或创建一个新的 conda 环境并安装所有东西(通过 pip 而不是通过 conda)。
推荐阅读
- facebook - 广告组推荐“广告未针对转化进行优化”
- powershell - 如何防止执行下一行,除非当前行被执行?
- c# - 无法复制节点及其子节点使用
- r - 循环遍历多列并在 R 中绘制一个图(每个图都有误差线)
- reactjs - 反应中的警报标题
- http - 如何在 Camel 中的 HTTP 重定向期间过滤掉标头?
- azure - HTTP 错误 500.37 - ANCM 无法在启动时间限制内启动 - 增加启动时间限制后仍未解决
- reactjs - 在 ReactJS 中测试自定义钩子
- anylogic - 如何在属性中更改框架尺寸尺寸?
- python-camelot - python中的Camelot没有按预期运行