Hugginface变压器模块未被anaconda识别



我正在使用Anaconda,python 3.7,windows 10。

我试图通过 https://huggingface.co/transformers/在我的环境中安装变压器。 我知道我必须安装pytorch或TF,我安装了pytorch - 如在anaconda导航器环境中看到的那样。

我会收到多种错误,具体取决于我卸载并重新安装 pytorch 和变压器的位置(anaconda/提示符(。最后一次尝试使用 康达安装PyTorch火炬视觉CPUONLY -C PyTorch和 康达安装-C 康达锻造变压器 我收到一个错误:

from transformers import BertTokenizer
bert_tokenizer = BertTokenizer.from_pretrained('bert-base-uncased', do_lower_case=True)
def tok(dataset):
input_ids = []
attention_masks = []
sentences = dataset.Answer2EN.values
labels = dataset.Class.values
for sent in sentences:
encoded_sent = bert_tokenizer.encode(sent, 
add_special_tokens=True,
max_length = 64,
pad_to_max_length =True)

类型错误:_tokenize(( 得到一个意外的关键字参数 "pad_to_max_length">

有谁知道使用Anaconda安全安装变压器?谢谢

问题是 conda 只在 2.1.1 版(存储库信息(中提供转换器库,而这个版本没有pad_to_max_length参数。如果有不同的参数,我不想查找它,但您可以简单地填充结果(这只是一个整数列表(:

from transformers import BertTokenizer
bert_tokenizer = BertTokenizer.from_pretrained('bert-base-uncased', do_lower_case=True)
sentences = ['this is just a test', 'this is another test']
max_length = 64
for sent in sentences:
encoded_sent = bert_tokenizer.encode(sent, 
add_special_tokens=True,
max_length = max_length)
encoded_sent.extend([0]* (max_length - len(encoded_sent)))
###your other stuff

在我看来,更好的选择是创建一个新的 conda 环境并通过 pip 而不是通过 conda 安装所有内容。这将允许您使用最新的转换器版本 (2.11(。

正如cronoik已经提到的,不知何故,conda只安装变压器版本2.1.1,尽管更高版本似乎可用(请参阅:https://anaconda.org/conda-forge/transformers/files(

关于conda,为我解决的是,也可以通过链接进行安装。

所以我使用以下命令安装了最新版本:

conda install https://anaconda.org/conda-forge/transformers/4.16.2/download/noarch/transformers-4.16.2-pyhd8ed1ab_0.tar.bz2

只需浏览他们的存储库并右键单击>复制链接目标

编辑:我注意到,Cronoik的答案是在condas存储库实际上尚未提供任何其他版本的时候。但是,在我回答时,它确实提供了其他版本,但是如果没有另行指定,仍然只安装版本2.1.1。

@Hung的回答对我有用,但我在收到错误后还需要更新打包版本:"拥抱面集线器 0.5.1 需要打包>=20.9,但你会有不兼容的打包 20.4"。

另一篇文章也已经通过运行以下内容解决了这个问题:

pip install --upgrade huggingface-hub

最新更新