Allennlp配置错误:key";矩阵“注意”;要求在“位置”处安装;模型。”;

Allennlp配置错误:key";矩阵“注意”;要求在“位置”处安装;模型。”;,nlp,allennlp,Nlp,Allennlp,我是Allennlp的新手,这是我第一次尝试。我已经安装了所有必需的库!pip安装allennlp!pip安装——预allennlp型号和我的代码也应该很好,但我仍然收到这样的错误消息:ConfigurationError:key“matrix\u attention”需要在位置“model.” 这是我的密码: import sys from allennlp.predictors.predictor import Predictor import allennlp_models predi

我是Allennlp的新手,这是我第一次尝试。我已经安装了所有必需的库
!pip安装allennlp!pip安装——预allennlp型号
和我的代码也应该很好,但我仍然收到这样的错误消息:
ConfigurationError:key“matrix\u attention”需要在位置“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"])
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']

你知道如何修复这个错误吗?我正在使用macOS Catalina和Python 3.6。我真的不知道现在该怎么办,所以我真的需要你的帮助。提前谢谢

问题解决了:我的代码似乎过时了,所以我更新了它。首先,我需要安装以下依赖项:

!pip install allennlp
!pip install --pre allennlp-models
这是我的代码:

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"])
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']
另外,如果有人感兴趣的话,我在GoogleColab上使用了这段代码,不过在其他地方也可以