【发布时间】:2021-03-04 15:50:42
【问题描述】:
我已经下载了 bert 预训练模型 'bert-base-cased.我无法在 BertTokenizer 的帮助下加载模型。我正在尝试使用bert tokenizer。在 bert-pretrained-model 文件夹中,我有 config.json 和 pytorch_model.bin。
tokenizer = BertTokenizer.from_pretrained(r'C:\Downloads\bert-pretrained-model')
我遇到了类似的错误
OSError Traceback (most recent call last)
<ipython-input-17-bd4c0051c48e> in <module>
----> 1 tokenizer = BertTokenizer.from_pretrained(r'\Downloads\bert-pretrained-model')
~\sentiment_analysis\lib\site-packages\transformers\tokenization_utils_base.py in from_pretrained(cls, pretrained_model_name_or_path, *init_inputs, **kwargs)
1775 f"- or '{pretrained_model_name_or_path}' is the correct path to a directory containing relevant tokenizer files\n\n"
1776 )
-> 1777 raise EnvironmentError(msg)
1778
1779 for file_id, file_path in vocab_files.items():
OSError: Can't load tokenizer for 'C:\Downloads\bert-pretrained-model'. Make sure that:
- 'C:\Downloads\bert-pretrained-model' is a correct model identifier listed on 'https://huggingface.co/models'
- or 'C:\Downloads\bert-pretrained-model' is the correct path to a directory containing relevant tokenizer files
当我尝试使用 BertModel 加载时,它正在加载。但是当我尝试使用 BertTokenizer 时,它没有加载。
【问题讨论】:
-
你错过了
vocab.json。 -
我有 config.json,我在哪里可以得到 vocab.json?我正在尝试使用 Hugging Face、Torch 和 Bert 进行情绪分析
-
我应该只下载 vocab.txt 并将其放在模型文件夹中还是应该下载任何额外的文件?
-
您还需要
tokenizer_config.json。
标签: nlp pytorch bert-language-model huggingface-transformers huggingface-tokenizers