pytorch的开源对话框架ParlAI系统实践

  最近抽点时间将ParlAI代码进行重构和调试之后,发现其代码设计风格类似于工厂模式,非常便于插入式开发,算是接触过的python代码框架中比较棒的一个。

  1、框架基本介绍

在facebook的github官网(https://github.com/facebookresearch/ParlAI)上对其介绍为对话系统框架。即:ParlAI (pronounced “par-lay”) is a framework for dialog AI research, implemented in Python.

  Its goal is to provide researchers:
    (1) a unified framework for sharing, training and testing dialog models。(分享、训练和测试对话模型的统一框架)
    (2) many popular datasets available all in one place, with the ability to multi-task over them。支持多种数据集。官网上介绍包括SQuADbAbI tasksMS MARCOMCTestWikiQAWebQuestionsSimpleQuestionsWikiMoviesQACNN & QADailyMailCBTBookTestbAbI Dialog tasksUbuntu DialogOpenSubtitlesCornell MovieVQA-COCO2014VisDial and CLEVR.等20多种数据集

    (3) seamless integration of Amazon Mechanical Turk for data collection and human evaluation 可以和亚马逊的数据收集进行无疑集成。

  2、框架的基本架构

  框架的入口都必须明确要执行何种任务,这个任务有一定的范围,在master/parlai/tasks/task_list.py这个文件中以JSON的格式进行了列举。因此其输入的任务必须在task_list中指定才可以。

{
        "id": "MovieDD-QA",
        "display_name": "Movie Dialog QA",
        "task": "moviedialog:Task:1",
        "tags": [ "All",  "QA", "MovieDD" ],
        "description": "Closed-domain QA dataset asking templated questions about movies, answerable from Wikipedia, similar to WikiMovies. From Dodge et al. '15. Link: https://arxiv.org/abs/1511.06931"
    },

代码的架构主要分为三个主要概念来展开:

(1)world - defines the environment (can be very simple, just two agents talking to each other). 即任务执行的环境,给的示例中均需要首先通过创建任务来构建这样的环境,如其中的示例代码:

# create repeat label agent and assign it to the specified task
    agent = RepeatLabelAgent(opt)
    world = create_task(opt, agent)

(2)agent – an agent in the world, e.g. the learner. (There can be multiple learners.):主要用来定义如何进行学习,tasks下每个数据集中都有对应的agents包,这个包可以根据任务名称而自动import,从而实现加载。在agents中定义了很多的teacher,可以支撑多样化的训练。

(3)teacher – a type of agent that talks to the learner, implements one of the listed before. 具体的任务执行学习。即教会机器先把何种方式来进行训练或者测试。


2、系统重构与实践

(1)display data的测试




(2)eval_model.py:使用命名后的 agent 来计算一个命令行给出的特定任务的评价量度(evaluation metric)数据。如图为对话系统的评测


猜你喜欢

转载自blog.csdn.net/sparkexpert/article/details/79966513
今日推荐