当我没有可用的 Internet 连接时,以下代码对我来说会失败,并会出现我在下面详述的错误消息。我尝试了很多东西,包括配置和检查.flair
文件夹以及包使用的.cache
文件夹。transformers
我还检查了这是https://huggingface.co/modelsdistilbert-base-uncased
上的当前模型标识符,正如错误消息所建议的那样。我能做些什么来解决这个问题?详情如下。
失败的代码
from flair.models import TextClassifier
en_classifier = TextClassifier.load('en-sentiment')
错误:
Can't load tokenizer for 'distilbert-base-uncased'. Make sure that:
- 'distilbert-base-uncased' is a correct model identifier listed on 'https://huggingface.co/models'
- or 'distilbert-base-uncased' is the correct path to a directory containing relevant tokenizer files
额外细节:
天才版:0.8.0.post1'
需要环境变量,因为我的应用需要在没有互联网连接的情况下独立运行:
TRANSFORMERS_OFFLINE=1
HF_DATASETS_OFFLINE=1
我的模型文件位于.flair
由flair.cache_root
. 当我加载其他模型时,适用于我的代码是:
from flair.models import TextClassifier
rnn_classifier = TextClassifier.load('sentiment-fast')
即使这样也有效:
from flair.models import SequenceTagger
tagger = SequenceTagger.load('ner')
.flair
目录有:
sentiment-en-mix-distillbert_4.pt
sentiment-en-mix-ft-rnn.pt
ner-english
(文件夹)pos-english
(文件夹)
~/.cache/huggingface/transformers
目录有:
0e1bbfda7f63a99bb52e3915dcf10c3c92122b827d92eb2d34ce94ee79ba486c.d789d64ebfe299b0e416afc4a169632f903f693095b4629a7ea271d5a0cf2c99
0e1bbfda7f63a99bb52e3915dcf10c3c92122b827d92eb2d34ce94ee79ba486c.d789d64ebfe299b0e416afc4a169632f903f693095b4629a7ea271d5a0cf2c99.json
75abb59d7a06f4f640158a9bfcde005264e59e8d566781ab1415b139d2e4c603.7f2721073f19841be16f41b0a70b600ca6b880c8f3df6f3535cbc704371bdfa4
75abb59d7a06f4f640158a9bfcde005264e59e8d566781ab1415b139d2e4c603.7f2721073f19841be16f41b0a70b600ca6b880c8f3df6f3535cbc704371bdfa4.json
8c8624b8ac8aa99c60c912161f8332de003484428c47906d7ff7eb7f73eecdbb.20430bd8e10ef77a7d2977accefe796051e01bc2fc4aa146bc862997a1a15e79
8c8624b8ac8aa99c60c912161f8332de003484428c47906d7ff7eb7f73eecdbb.20430bd8e10ef77a7d2977accefe796051e01bc2fc4aa146bc862997a1a15e79.json