BERT模型应用智能客服方案
方案旨在解决企业自有业务场景下且设备预算有限的小成本智能客服方案。bert模型可运行在仅CPU设备环境且相应速度迅速可实现企业级智能体的搭建需求。同时结合freeswitch语音识别即可完成呼叫中心智能客服功能freeswitch语音识别可参照往期文章有业务需求可邮箱mokeily99126.com或主页咨询一、bert模型功能文本分类如情感分析命名实体识别NER意图判断语义相似度计算模型可以通过少量数据的训练及微调即可实现简单的智能客服功能二、应用方案1、数据清洗针对准备好的训练数据和用户提问进行数据清洗包括分词、停用词剔除等操作使意图更加明确和清晰2、bert模型选型前期尝试了bert的bert-base-chinese中文模型但是该模型词语完整性边界不足bert-base-chinese是按照单个字来作为边界这对于中文分析有一定局限性所以选择了chinese-bert-wwm-ext模型。chinese-bert-wwm-ext模型是以词作为词语边界。能够很好的针对中文进行分析和判断。方案使用chinese-bert-wwm-ext核心逻辑就是通过用户输入判断用户意图从而实现对应回答。3、模型训练微调刚下载下来的模型是没法直接应用到某个领域的需要喂数据进行学习模型就像一个刚毕业的大学生虽然很聪明且有一定学习基础但是在某个领域是无法成为专家的进到企业后通过工作学习后才能迅速掌握专业知识和能力。bert模型通过几十条或几百条数据训练即可完成一个简单的智能体例如数据建议又针对性以及不通语句相同含义数据{text: 我想订一张明天去北京的机票, intent: book_ticket, slots: {time: 明天, destination: 北京}}, {text: 查询一下上海的天气, intent: query_weather, slots: {location: 上海}}, {text: 帮我查一下订单, intent: query_order, slots: {}}, {text: 后天去上海, intent: book_ticket, slots: {time: 后天, destination: 上海}}, {text: 出发地是广州, intent: book_ticket, slots: {origin: 广州}}, {text: 你好, intent: greeting, slots: {}}, {text: 把时间改成上午, intent: modify_slot, slots: {time: 上午}}, {text: 预订下周一从深圳到杭州的机票, intent: book_ticket, slots: {time: 下周一, origin: 深圳, destination: 杭州}}, {text: 北京今天天气怎么样, intent: query_weather, slots: {location: 北京, time: 今天}}, {text: 我要买两张后天去成都的票, intent: book_ticket, slots: {number: 两张, time: 后天, destination: 成都}}, {text: 从武汉出发, intent: book_ticket, slots: {origin: 武汉}}, {text: 目的地是南京, intent: book_ticket, slots: {destination: 南京}}, {text: 帮我取消订单, intent: cancel_order, slots: {}}, {text: 上海明天会下雨吗, intent: query_weather, slots: {location: 上海, time: 明天}}, {text: 谢谢, intent: thanks, slots: {}}, {text: 我想查询从北京到上海的航班, intent: book_ticket, slots: {origin: 北京, destination: 上海}}, {text: 广州的天气如何, intent: query_weather, slots: {location: 广州}}, {text: 帮我预订明天的机票, intent: book_ticket, slots: {time: 明天}}, {text: 我要去深圳, intent: book_ticket, slots: {destination: 深圳}}, {text: 订单号是多少, intent: query_order, slots: {}}, {text: 订一张后天飞往成都的机票, intent: book_ticket, slots: {time: 后天, destination: 成都}}, {text: 查询北京后天的天气, intent: query_weather, slots: {location: 北京, time: 后天}}, {text: 从北京到上海的航班, intent: book_ticket, slots: {origin: 北京, destination: 上海}}, {text: 明天去广州, intent: book_ticket, slots: {time: 明天, destination: 广州}}, {text: 预订深圳的机票, intent: book_ticket, slots: {destination: 深圳}}, {text: 杭州天气怎么样, intent: query_weather, slots: {location: 杭州}}, {text: 我要订下周三去武汉的票, intent: book_ticket, slots: {time: 下周三, destination: 武汉}}, {text: 查询南京的天气, intent: query_weather, slots: {location: 南京}}, {text: 从成都出发去北京, intent: book_ticket, slots: {origin: 成都, destination: 北京}}, {text: 帮我订一张机票, intent: book_ticket, slots: {}}, {text: 今天天气如何, intent: query_weather, slots: {time: 今天}}, {text: 预订后天去西安的航班, intent: book_ticket, slots: {time: 后天, destination: 西安}}, {text: 查询一下订单状态, intent: query_order, slots: {}}, {text: 我要退掉订单, intent: cancel_order, slots: {}}, {text: 早上好, intent: greeting, slots: {}}, {text: 从上海到广州的机票, intent: book_ticket, slots: {origin: 上海, destination: 广州}}, {text: 明天北京的天气, intent: query_weather, slots: {location: 北京, time: 明天}}, {text: 订两张去深圳的票, intent: book_ticket, slots: {number: 两张, destination: 深圳}}, {text: 查询广州今天气温, intent: query_weather, slots: {location: 广州, time: 今天}}, {text: 我要去北京出差, intent: book_ticket, slots: {destination: 北京}}, {text: 下个月去上海, intent: book_ticket, slots: {time: 下个月, destination: 上海}}, {text: 从杭州出发, intent: book_ticket, slots: {origin: 杭州}}, {text: 目的地成都, intent: book_ticket, slots: {destination: 成都}}, {text: 帮我查订单, intent: query_order, slots: {}}, {text: 取消我的预订, intent: cancel_order, slots: {}}, {text: 您好, intent: greeting, slots: {}}, {text: 预订明天从北京到上海的机票, intent: book_ticket, slots: {time: 明天, origin: 北京, destination: 上海}}, {text: 上海后天天气, intent: query_weather, slots: {location: 上海, time: 后天}}, {text: 我要三张去武汉的票, intent: book_ticket, slots: {number: 三张, destination: 武汉}}, {text: 查询深圳的天气情况, intent: query_weather, slots: {location: 深圳}}, {text: 从乌鲁木齐到北京的航班, intent: book_ticket, slots: {origin: 乌鲁木齐, destination: 北京}}, {text: 预订去乌鲁木齐的机票, intent: book_ticket, slots: {destination: 乌鲁木齐}}, {text: 从哈尔滨到广州, intent: book_ticket, slots: {origin: 哈尔滨, destination: 广州}}, {text: 明天从西安出发, intent: book_ticket, slots: {time: 明天, origin: 西安}}, {text: 去呼和浩特, intent: book_ticket, slots: {destination: 呼和浩特}}, {text: 从石家庄到郑州, intent: book_ticket, slots: {origin: 石家庄, destination: 郑州}}, {text: 预订拉萨的机票, intent: book_ticket, slots: {destination: 拉萨}}, {text: 从银川出发去西宁, intent: book_ticket, slots: {origin: 银川, destination: 西宁}}, {text: 查询乌鲁木齐的天气, intent: query_weather, slots: {location: 乌鲁木齐}}, {text: 哈尔滨今天气温, intent: query_weather, slots: {location: 哈尔滨, time: 今天}}, {text: 从北京飞往上海, intent: book_ticket, slots: {origin: 北京, destination: 上海}}, {text: 自广州到深圳, intent: book_ticket, slots: {origin: 广州, destination: 深圳}}, {text: 由成都出发, intent: book_ticket, slots: {origin: 成都}}, {text: 前往杭州, intent: book_ticket, slots: {destination: 杭州}}, {text: 到达南京, intent: book_ticket, slots: {destination: 南京}}, {text: 从重庆到武汉的航班, intent: book_ticket, slots: {origin: 重庆, destination: 武汉}}, {text: 明天从天津出发去北京, intent: book_ticket, slots: {time: 明天, origin: 天津, destination: 北京}}, {text: 后天从长沙到厦门, intent: book_ticket, slots: {time: 后天, origin: 长沙, destination: 厦门}}, {text: 大后天去昆明, intent: book_ticket, slots: {time: 大后天, destination: 昆明}}, {text: 从贵阳出发到南宁, intent: book_ticket, slots: {origin: 贵阳, destination: 南宁}}, {text: 预订下周一从青岛到大连的机票, intent: book_ticket, slots: {time: 下周一, origin: 青岛, destination: 大连}}, {text: 从苏州到无锡, intent: book_ticket, slots: {origin: 苏州, destination: 无锡}}, {text: 明天从宁波出发, intent: book_ticket, slots: {time: 明天, origin: 宁波}}, {text: 去温州, intent: book_ticket, slots: {destination: 温州}}, {text: 从福州到台北, intent: book_ticket, slots: {origin: 福州, destination: 台北}}, {text: 预订海口的机票, intent: book_ticket, slots: {destination: 海口}}, {text: 从三亚出发, intent: book_ticket, slots: {origin: 三亚}}, {text: 明天从兰州到西宁, intent: book_ticket, slots: {time: 明天, origin: 兰州, destination: 西宁}}, {text: 从包头到鄂尔多斯, intent: book_ticket, slots: {origin: 包头, destination: 鄂尔多斯}}, {text: 查询呼和浩特的天气, intent: query_weather, slots: {location: 呼和浩特}}, {text: 拉萨明天天气, intent: query_weather, slots: {location: 拉萨, time: 明天}}, {text: 从乌鲁木齐飞往北京, intent: book_ticket, slots: {origin: 乌鲁木齐, destination: 北京}}, {text: 预订明天从哈尔滨到广州的机票, intent: book_ticket, slots: {time: 明天, origin: 哈尔滨, destination: 广州}}, {text: 从西安到成都的航班, intent: book_ticket, slots: {origin: 西安, destination: 成都}}, {text: 后天从重庆出发去昆明, intent: book_ticket, slots: {time: 后天, origin: 重庆, destination: 昆明}}, {text: 从贵阳到桂林, intent: book_ticket, slots: {origin: 贵阳, destination: 桂林}}, {text: 明天去张家界, intent: book_ticket, slots: {time: 明天, destination: 张家界}}, {text: 从珠海到澳门, intent: book_ticket, slots: {origin: 珠海, destination: 澳门}}, {text: 预订下个月从厦门到台北的机票, intent: book_ticket, slots: {time: 下个月, origin: 厦门, destination: 台北}}, {text: 从烟台到威海, intent: book_ticket, slots: {origin: 烟台, destination: 威海}}, {text: 明天从徐州出发, intent: book_ticket, slots: {time: 明天, origin: 徐州}}, {text: 去洛阳, intent: book_ticket, slots: {destination: 洛阳}}, {text: 从开封到郑州, intent: book_ticket, slots: {origin: 开封, destination: 郑州}},4、业务逻辑设计bert模型虽然有着自己的独特优点但是也存在一定缺陷bert模型是单论语义编码器所以记忆功能需要手动实现。单次目的性对话周期可以通过模型槽位来实现例如用户想预定明天北京到上海的机票通过模型槽位的方式即可实现以下功能用户我想预定机票 机器人客服请问您要从哪里出发 用户北京 机器人客服请问目的地是哪 用户上海 机器人客服请问出发时间是什么时候 用户明天上午 机器人客服好的已为您预定明天上午从北京到上海的机票。这样一次单目的性对话即可完成系统可根据模型意图结合对应槽位进行话术变更本例中槽位分别是“出发地,目的地,时间。多次目的性对话就需要手动进行存储和调取来精准识别用户意图。例如用户完成以上对话后又发起新的订票对话我们就需要判断用户是否要改签或者退订上次的机票。所以多轮对话就要根据实际业务场景进行灵活改动三、测试样例按照以上方案做了一个小的测试样例用户可以通过页面回话输入问题得到相应回答。由于没有回话存储和数据入库所以多轮对话没法做出正确调整只是作为展示样例供参考。如有合作意向可邮箱或主页联系训练数据没有全面覆盖只是简单演示模型智能客服测试系统http://123.56.168.73:5000/