Allennlp ConfigurationError:在位置“模型”处需要键“ matrix_attention”。

时间:2020-07-08 19:01:27

标签: nlp allennlp

我是Allennlp的新手,这是我第一次尝试。我已经安装了所有必需的库!pip install allennlp !pip install --pre allennlp-models,我的代码也应该没问题,但是我仍然收到此错误消息:ConfigurationError: key "matrix_attention" is required at location "model." 这是我的代码:

import sys

from allennlp.predictors.predictor import Predictor
import allennlp_models

predictor = Predictor.from_path(
"https://storage.googleapis.com/allennlp-public-models/bidaf-elmo-model-2018.11.30-charpad.tar.gz"
)

prediction = predictor.predict(
passage="Life expectancy in Asia is at 68 years", question="What is the life expectancy in Asia"
)
print(prediction["best_span_str"])

您是否知道如何解决此错误?我正在使用macOS Catalina和Python 3.6。我真的不知道该怎么办,所以我真的需要您的帮助。预先感谢!

1 个答案:

答案 0 :(得分:2)

问题已解决:我的代码似乎已经过时,因此我对其进行了更新。首先,我需要安装以下依赖项:

!pip install allennlp
!pip install --pre allennlp-models

这是我的代码:

from allennlp.predictors.predictor import Predictor
import allennlp_models.rc
predictor = Predictor.from_path("https://storage.googleapis.com/allennlp-public-models/bidaf-elmo-model-2020.03.19.tar.gz")
result = predictor.predict(
  passage="Apple was founded by Steve Jobs, Steve Wozniak, and Ronald Wayne in April 1976 to develop and sell Wozniak\'s Apple I personal computer, though Wayne sold his share back within 12 days. It was incorporated as Apple Computer, Inc., in January 1977, and sales of its computers, including the Apple II, grew quickly.",
  question="Who founded Apple?"
)
result['best_span_str']

此外,如果有人感兴趣,我也会在Google Colab上使用此代码,尽管这在其他地方也可以使用。