allenNLP无法加载HuggingFace预训练模型
allenNLP在window下无法运行带有local加载模型的 jsonnet配置文件
local bert_model = “bert-base-uncased”;
配置文件.jsonnet加载预训练模型时报错。
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
原因:
windows使用深度学习组件jsonnet的异常。
解决方法:
1、下载mingw-w64
https://sourceforge.net/projects/mingw-w64/
可能下载不成功
-
选择file栏–>选择下图文件安装即可。
-
配置环境变量:
将下载的安装包解压后,将bin的路径(…\mingw64\bin)加入环境变量中的path. -
下载jsonnet-binary,pip install jsonnet-binary
-
重新测试可以运行。
allennlp train my_text_classifier_bert.jsonnet -s model --include-package my_text_classifier
my_text_classifier_bert.jsonnet配置文件
local bert_model = "bert-base-uncased";
{
"dataset_reader" : {
"type": "classification-tsv",
"tokenizer": {
"type": "pretrained_transformer",
"model_name": bert_model,
},
"token_indexers": {
"bert": {
"type": "pretrained_transformer",
"model_name": bert_model,
}
},
"max_tokens": 512
},
"train_data_path": "data/movie_review/train.tsv",
"validation_data_path": "data/movie_review/dev.tsv",
"model": {
"type": "simple_classifier",
"embedder": {
"token_embedders": {
"bert": {
"type": "pretrained_transformer",
"model_name": bert_model
}
}
},
"encoder": {
"type": "bert_pooler",
"pretrained_model": bert_model,
"requires_grad": true
}
},
"data_loader": {
"batch_size": 8,
"shuffle": true
},
"trainer": {
"optimizer": {
"type": "huggingface_adamw",
"lr": 1.0e-5
},
"num_epochs": 5
}
}