我可以访问最新的软件包,但我不能从我的python环境访问互联网。
我拥有的包版本如下所示
huggingface-hub-0.4.0 sacremoses-0.0.47 tokenizers-0.10.3 transformers-4.15.0
sentence-transformers-2.1.0 sentencepiece-0.1.96 torchvision-0.11.2
print (torch.__version__)
1.10.1+cu102我去了位置,在一个文件夹中复制了所有的文件。
os.listdir('multi-qa-mpnet-base-dot-v1_Jan2022/')
['config_sentence_transformers.json',
'config.json',
'gitattributes',
'modules.json',
'data_config.json',
'sentence_bert_config.json',
'README.md',
'special_tokens_map.json',
'tokenizer_config.json',
'train_script.py',
'vocab.txt',
'tokenizer.json',
'1_Pooling',
'.ipynb_checkpoints',
'9e1e76b7a067f72e49c7f571cd8e811f7a1567bec49f17e5eaaea899e7bc2c9e']然后我去了url,并试图执行这里列出的代码。
但我得到的是错误
model = SentenceTransformer('multi-qa-mpnet-base-dot-v1_Jan2022/')
OSError: Error no file named ['pytorch_model.bin', 'tf_model.h5', 'model.ckpt.index', 'flax_model.msgpack'] found in directory multi-qa-mpnet-base-dot-v1_Jan2022/ or `from_tf` and `from_flax` set to False.我在哪里可以得到这4个文件('pytorch_model.bin', 'tf_model.h5', 'model.ckpt.index', 'flax_model.msgpack'),或者我还需要更改什么?这些文件在上面提到的第一个URL中不可用
发布于 2022-01-17 08:40:33
基于您提到的内容,我在Google上查看了sentence-transformers的源代码。在运行模型并获取文件之后,我检查了目录,并在那里看到了pytorch_model.bin。

根据sentence-transformers代码:链接

当flax_model.msgpack、rust_model.ot、tf_model.h5试图下载时被忽略了。
这些是它下载的文件:
['1_Pooling', 'config_sentence_transformers.json', 'tokenizer.json', 'tokenizer_config.json', 'modules.json', 'sentence_bert_config.json', 'pytorch_model.bin', 'special_tokens_map.json', 'config.json', 'train_script.py', 'data_config.json', 'README.md', '.gitattributes', 'vocab.txt']唯一需要加载模型的是pytorch_model.bin文件。我通过将模块复制到另一个目录进行了测试,结果成功了。根据你的问题,你还没有下载这个文件,所以这就是问题所在。
总之,您应该使用它的命令下载模型,然后将文件移动到另一个目录,并使用该dir初始化SentenceTransformer类。
我希望这会有帮助。
https://stackoverflow.com/questions/70716702
复制相似问题