我是新来的。我训练了一个elmo模型,将它应用到其他allennlp模型作为嵌入,但失败了。我的模型似乎与配置提供的接口不兼容。我能做什么?
我的elmo是由allennlp用命令训练的:
allennlp train config/elmo.jsonnet --serialization-dir /xxx除了数据集和词汇表之外,elmo.jsonnet与https://github.com/allenai/allennlp-models/blob/main/training_config/lm/bidirectional_language_model.jsonnet几乎相同。
在那之后,我得到了一个elmo模型
config.json
weights.th
vocabulary/
vocabulary/.lock
vocabulary/non_padded_namespaces.txt
vocabulary/tokens.txt
meta.json当我尝试将模型加载到其他模型(如https://github.com/allenai/allennlp-models/blob/main/training_config/rc/bidaf_elmo.jsonnet中的bidaf)中时,我发现它需要选项和权重:
"elmo": {
"type": "elmo_token_embedder",
"do_layer_norm": false,
"dropout": 0,
"options_file": "xxx/options.json",
"weight_file": "xxx/weights.hdf5"
}不包括在我的模型里。我试图将model.state_dict()更改为weights.hdf5,但收到了一个错误:
KeyError: "Unable to open object (object 'char_embed' doesn't exist)"中所要求的
File "/home/xxx/anaconda3/envs/thesis_torch1.8/lib/python3.8/site-packages/allennlp/modules/elmo.py", line 393, in _load_char_embedding
char_embed_weights = fin["char_embed"][...]看来我所训练的模型与界面不兼容。如何将我的elmo应用于其他模型的嵌入?
发布于 2022-02-24 19:15:33
你说得对,这两种格式不对齐。
恐怕没有容易的出路。我认为您必须编写一个可以读取和应用来自TokenEmbedder的输出的bidirectional_language_model.jsonnet。
如果你这么做了,我们很乐意把它作为对AllenNLP的贡献!
https://stackoverflow.com/questions/71182588
复制相似问题