如何为预训练模型编写评估函数并指定数据加载器?



我是allenlp库的新手。我正在使用预训练Bidaf-elmo模型来完成阅读理解任务。我的代码看起来像-

from allennlp.predictors.predictor import Predictor
import allennlp_models.rc
from allennlp_models import pretrained
from allennlp.training.util import evaluate
import allennlp.data.data_loaders.simple_data_loader
archive_file_path = "https://storage.googleapis.com/allennlp-public-models/bidaf-model-2020.03.19.tar.gz"
input_path = "C:\Users\SHRIPRIYA\sample_dataset.json"
data_load = simple_data_loader(input_path)
evaluate(model=archive_file_path, data_loader = data_load, output_file=output, predictions_output_file=pred_output_file, cuda_device=0)

simple_data_loader()抛出错误-name 'simple_data_loader' is not defined。我知道这是一个语法错误,但我找不到任何例子来加载JSON文件使用数据加载器函数从AllenNLP和评估它使用预训练的模型。

关于我的数据:

  1. 总样本数= 10,000
  2. 总问题数= 1000

每个样本文章都需要回答全部1000个问题。我的示例JSON输入看起来像-

{
"passage": "Venus is named after the Roman goddess of love and beauty. Venus is the second planet from the sun. Is the brightest object in the sky besides our Sun and the Moon. Venus has no moons. It is also known as the morning star because at sunrise it appears in the east. It is also known as the evening star as it appears at sunset when it is in the west. It cannot be seen in the middle of the night. Venus and Earth are close together in space and similar in size, which is the reason Venus is called Earth's sister planet. Venus has more volcanoes than any other planet. It is the hottest planet in the solar system, even hotter than Mercury, which is closer to the Sun. The temperature on the surface of Venus is about 460° Celsius. The atmosphere on Venus is composed of carbon dioxide. The surface is heated by radiation from the sun, but the heat cannot escape through the clouds and layer of carbon dioxide. (This is a “greenhouse effect”).",
"questions": [
"How many moons does Venus have?",
"Venus was named after which Roman goddess?",    
"At what position does Venus lie from Sun?",
"What is the temperature of Venus surface?",
"Why is Venus called Earth’s sister planet?",
"What is the atmosphere of Venus composed of?"
]}

如果有任何更快的替代方法来根据多篇文章评估多个问题,请告诉我。

谢谢!

从您的代码中,看起来您没有正确导入SimpleDataLoader。下面的方法应该有效:from allennlp.data.data_loaders import SimpleDataLoader

你可以在这里找到训练和评估模型的例子:https://guide.allennlp.org/training-and-prediction#3

最新更新