MGIMN FAQ问答-中文-政务领域-base

我要开发同款
匿名用户2024年07月31日
77阅读

技术信息

开源地址
https://modelscope.cn/models/iic/nlp_mgimn_faq-question-answering_chinese-gov-base
授权协议
Apache License 2.0

作品详情

FAQ问答任务介绍

FAQ问答是智能对话系统(特别是垂直领域对话系统)的核心业务场景,业务专家基于经验或数据挖掘的结果,将用户会频繁问到的业务知识以Q&A的形式维护起来,称之为知识库, 当用户使用对话系统时,提问一个业务方面的问题,机器自动从知识库中找到最合适的回答。机器找答案的过程通常包含检索排序两个阶段;

本模型基于MGIMN FAQ问答-中文-通用领域-base模型在政务数据上进行fietue得到,适用于政务领域FAQ问答任务;包括但不局限于社保、公积金等场景;

FAQ问答开发实践


相关模型

模型描述

本模型以structbert-base-chiese预训练模型为底座,模型结构采用多粒度交互式匹配小样本模型结构(如下图所示),核心的模块主要有:Istace Matchig Layer和Class-wise Aggregatio Layer, 详细的模型结构设计请参考NAACL2022论文MGIMN:Multi-Graied Iteractive Matchig Network for Few-shot Text Classificatio,模型通过小样本meta-learig的训练方式,在海量数据上进行预训练(亿级)、微调(百万级);适用于 FAQ问答任务和通用小样本分类任务;(说明:模型结构与论文中一致,但训练方式由于框架约束会略有差异)

本模型基于MGIMN FAQ问答-中文-通用领域-base模型在政务数据上进行fietue得到,适用于政务领域FAQ问答任务;包括但不局限于社保、公积金等场景;

期望模型使用方式及适用范围

如何使用

在安装完成ModelScope之后即可使用damo/lpmgimfaq-questio-aswerig_chiese-gov-base的的FAQ问答能力

代码范例

from modelscope.pipelies import pipelie
from modelscope.utils.costat import Tasks

# query_set: query
# support_set: faq候选列表,一般实际应用场景中通过检索得到
faq_pipelie = pipelie(Tasks.faq_questio_aswerig, 'damo/lp_mgim_faq-questio-aswerig_chiese-gov-base',model_revisio='v1.0.0')
outputs = faq_pipelie({"query_set": ["如何计发经济补偿金", "医保账户可给哪些家人使用", "信号灯不亮"],
                       "support_set": [{"text": "被单位辞退能拿到多少钱的补偿金", "label": "1"}, 
                                      {"text": "补偿金的相关文件", "label": "1"}, 
                                      {"text": "医保账户钱给家人用的条件", "label": "2"}, 
                                      {"text": "我医保账户的钱可否给家人使用", "label": "2"}, 
                                      {"text": "信号灯问题", "label": "3"}, 
                                      {"text": "信号灯直行的秒数为10秒", "label": "3"}]})
# outputs
# 输出每一个类的分值,并进行排序
# {'output': [[{'label': '1', 'score': 0.9816105365753174},
#   {'label': '2', 'score': 4.938467768056398e-08},
#   {'label': '3', 'score': 1.4434443640354289e-09}],
#  [{'label': '2', 'score': 0.9592089056968689},
#   {'label': '1', 'score': 8.684407359904611e-12},
#   {'label': '3', 'score': 7.31853033036911e-12}],
#  [{'label': '3', 'score': 0.20879220962524414},
#   {'label': '1', 'score': 6.5150702610594635e-09},
#   {'label': '2', 'score': 4.5615617949579246e-09}]]}

备注:我们不限定queryset 和 supportset大小,使用者需要基于基于显存大小以及对性能的要求输入合适大小的候选集;

from modelscope.pipelies import pipelie
from modelscope.utils.costat import Tasks

# 获取句子向量表示,可用于构建向量索引;
faq_pipelie = pipelie(Tasks.faq_questio_aswerig, 'damo/lp_mgim_faq-questio-aswerig_chiese-gov-base',model_revisio='v1.0.0')
setece_vecs = faq_pipelie.get_setece_embeddig(["如何计发经济补偿金", "医保账户可给哪些家人使用", "信号灯不亮"], max_le=30)

备注:同样,我们也不对输入进行大小限制,使用者需要基于显存大小输入合适大小的数据;

模型局限性及可能的偏差

虽然我们的数据尽量覆盖各行业,但仍有可能不适用于某些特定行业;

训练数据介绍

训练数据来源于业务数据

模型训练&Fietue

import os

from modelscope.metaifo import Traiers
from modelscope.msdatasets import MsDataset
from modelscope.pipelies import pipelie
from modelscope.traiers import build_traier
from modelscope.utils.cofig import Cofig
from modelscope.utils.hub import read_cofig

model_id = 'damo/lp_mgim_faq-questio-aswerig_chiese-gov-base'
model_revisio='v1.0.0'
tmp_dir='./work_dir'

# 我们仅以此数据作为示例,并不能作为faq任务的训练数据
trai_dataset = MsDataset.load(
    'jd', amespace='DAMO_NLP',
    split='trai').remap_colums({'setece': 'text'})
# 用户可以加载自己的数据集,格式如下,训练数据少时会报错,尽量保证label数和每个label对应样本数不少于5;
#trai_dataset = [{'text':'测试数据1','label':'label1'},{'text':'测试数据3','label':'label1'},
#                 {'text':'测试数据2','label':'label2'},{'text':'测试数据4','label':'label2'},.....]
eval_dataset = MsDataset.load(
    'jd', amespace='DAMO_NLP',
    split='validatio').remap_colums({'setece': 'text'})

cfg: Cofig = read_cofig(model_id,revisio=model_revisio)
cfg.trai.trai_iters_per_epoch = 50
cfg.evaluatio.val_iters_per_epoch = 2
cfg.evaluatio.metrics = 'accuracy'
cfg.trai.seed = 1234
cfg.trai.hooks = [{
    'type': 'CheckpoitHook',
    'by_epoch': False,
    'iterval': 50
}, {
    'type': 'EvaluatioHook',
    'by_epoch': False,
    'iterval': 50
}, {
    'type': 'TextLoggerHook',
    'by_epoch': False,
    'roudig_digits': 5,
    'iterval': 10
}]
cfg_file = os.path.joi(tmp_dir, 'cofig.jso')
cfg.dump(cfg_file)

traier = build_traier(
    Traiers.faq_questio_aswerig_traier,
    default_args=dict(
        model=model_id,
        work_dir=tmp_dir,
        trai_dataset=trai_dataset,
        eval_dataset=eval_dataset,
        cfg_file=cfg_file,
        model_revisio=model_revisio))

traier.trai()

evaluate_result = traier.evaluate()
prit(evaluate_result)

数据评估及结果

由于公开的垂直领域FAQ数据较少,我们选择几个公开的意图分类数据进行数据评估,其中bakig/OOS/cliic为中文翻译数据;

  • 评测方式:划分训练集和测试集,对于测试集中的每一个query,从训练集中检索top10个类,每个类至多5条样本,基于检索出的样本数据对query进行分类
  • 评测指标:ACC

(政务和金融领域模型待评测)

Model fewjoit lpccst4 bakig cliic OOS Average
SeteceTrasformer(paraphrase-multiligual-mpet-base-v2) 79.1 81.9 75.7 86.1 66.1 77.8
SeteceTrasformer(paraphrase-multiligual-MiiLM-L12-v2) 82.5 81.0 77.4 84.1 64.6 77.9
StructBERT FAQ问答-中文-通用领域-base 89.9 87.6 78.8 88.1 68.0 82.5
MGIMN FAQ问答-中文-通用领域-base 89.7 91.4 80.6 88.8 69.2 83.9
MGIMN FAQ问答-中文-政务领域-base(当前模型) - - - - - -
@iproceedigs{zhag-etal-2022-mgim,
    title = "{MGIMN}: Multi-Graied Iteractive Matchig Network for Few-shot Text Classificatio",
    author = "Zhag, Jiahai  ad
      Maimaiti, Mieradilijiag  ad
      Xig, Gao  ad
      Zheg, Yuahag  ad
      Zhag, Ji",
    booktitle = "Proceedigs of the 2022 Coferece of the North America Chapter of the Associatio for Computatioal Liguistics: Huma Laguage Techologies",
    year = "2022",
    publisher = "Associatio for Computatioal Liguistics",
    url = "https://aclathology.org/2022.aacl-mai.141",
    abstract = "Text classificatio struggles to geeralize to usee classes with very few labeled text istaces per class.I such a few-shot learig (FSL) settig, metric-based meta-learig approaches have show promisig results. Previous studies maily aim to derive a prototype represetatio for each class.However, they eglect that it is challegig-yet-uecessary to costruct a compact represetatio which expresses the etire meaig for each class.They also igore the importace to capture the iter-depedecy betwee query ad the support set for few-shot text classificatio. To deal with these issues, we propose a meta-learig based method MGIMN which performs istace-wise compariso followed by aggregatio to geerate class-wise matchig vectors istead of prototype learig.The key of istace-wise compariso is the iteractive matchig withi the class-specific cotext ad episode-specific cotext. Extesive experimets demostrate that the proposed method sigificatly outperforms the existig SOTA approaches, uder both the stadard FSL ad geeralized FSL settigs.",
}

功能介绍

FAQ问答任务介绍 FAQ问答是智能对话系统(特别是垂直领域对话系统)的核心业务场景,业务专家基于经验或数据挖掘的结果,将用户会频繁问到的业务知识以Q&A的形式维护起来,称之为知识库, 当用户使用对话

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论