我有一个训练有素的变压器 NER 模型,我想在未连接到互联网的机器上使用它。加载此类模型时,当前它会将缓存文件下载到 .cache 文件夹。
要离线加载和运行模型,您需要将 .cache 文件夹中的文件复制到离线机器。但是,这些文件具有很长的非描述性名称,如果您要使用多个模型,则很难识别正确的文件。对此有何想法?
Example of model files
最佳答案
处理此问题的一种相对简单的方法是简单地“重命名”预训练模型,如 this 中所述。线。
从本质上讲,对于您尝试使用的任何模型,您所要做的就是这样:
from transformers import BertModel
model = BertModel.from_pretrained("bert-base-uncased")
model.save_pretrained("./my_named_bert")
该线程还详细介绍了本地模型文件夹的命名方式,请参阅 LysandreJik 的帖子:Hi, they are named as such because that's a clean way to make sure the model on the S3 is the same as the model in the cache. The name is created from the etag of the file hosted on the S3. [...]
关于python - 下载变压器模型以供离线使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62261602/