如何将 Stanza 导出为 ONNX 格式?简单地训练模型似乎是不可能的。
1 回答
1
这里有一个解释:https ://pytorch.org/tutorials/advanced/super_resolution_with_onnxruntime.html
我在https://github.com/vivkvv/stanza为这个实验创建了一个分支。另请参阅我的提交https://github.com/vivkvv/stanza/commits?author=vivkvv。
我使用 pipeline_demo.py 进行测试。我添加的主要内容是第 77 行下方的 models/tokanization/trainer.py 中的代码
pred = self.model(units, features)
由于解释,我添加了
torch.onnx.export(
self.model,
(units, features),
onnx_export_file_name,
opset_version=9,
export_params=True,
do_constant_folding=True,
input_names=['input'],
output_names=['output'],
dynamic_axes={
'input': {0: 'batch_size'},
'output': {0: 'batch_size'}
}
)
它适用于标记化。但同样不适用于例如 pos 或 lemmatizer(请参阅我对 PartOfSpeech 的提交)。对于不同的 opset_version,我会得到不同的错误。
我在 github/stanza 上创建了一个问题,您可以在那里看到https://github.com/stanfordnlp/stanza/issues/893
于 2021-12-07T10:48:34.867 回答