您的位置:首页 > 大数据 > 人工智能

使用aiml/lsh实现在线聊天机器人

2016-09-01 10:52 417 查看
你需要了解的相关知识,eliza(nltk实现的一个简单的聊天应用),aiml(人工智能标记语言),短文本相似性匹配,大部分在线的机器人基本都是通过question-anwser匹配的方式来实现人与机器之间的交互,目前来说效果并不好。本文实现的在线聊天机器人程序采用以下几种方式,aiml+短文件匹配+第三方调用。

实现思路:先定义aiml匹配的规则,准备qa样本数据通过lsh来生成模型,对于用户新输入的一个问题,优先从qa样本只匹配最相似的问题给出回答,如果没有则从aiml定义中寻找答案,如果还是没有,调用第三方的接口回答。

aiml配置文件如下:

<?xml version="1.0" encoding="UTF-8"?>

<aiml version="1.0">

<meta name="language" content="zh"/>

<category>
<pattern>* 再见</pattern>
<template>
<srai>BYE</srai>
</template>
</category>

<category>
<pattern>再见</pattern>
<template>
<srai>BYE</srai>
</template>
</category>

<category>
<pattern>BYE</pattern>
<template>
<random>
<li>再见<get name="name"/>.
</li>
<li>再见啦,<get name="name"/>.
</li>
<li>下次见,<get name="name"/>.
</li>
<li>谢谢你陪我聊天,<get name="name"/>.
</li>
<li>改天见,<get name="name"/>.
</li>
</random>
</template>
</category>

<category>
<pattern>谢谢</pattern>
<template>
<random>
<li>不客气.</li>
<li>你太客气了.</li>
</random>
</template>
</category>

<category>
<pattern>你好</pattern>
<template>
<srai>HELLO</srai>
</template>
</category>

<category>
<pattern>HELLO</pattern>
<template>
<random>
<li>你好.</li>
<li>你也好.</li>
<li>你好啊.</li>
</random>
</template>
</category>

<category>
<pattern>* 名字</pattern>
<template>
<srai>NAME</srai>
</template>
</category>
<category>
<pattern>NAME</pattern>
<template>
<random>
<li>我是测试机器人.</li>
<li>你可以叫我vs.</li>
</random>
</template>
</category>

<category>
<pattern>* 几岁 *</pattern>
<template>
<srai>AGE</srai>
</template>
</category>

<category>
<pattern>AGE</pattern>
<template>
我刚出生没有多久呢
</template>
</category>

<category>
<pattern>* 什么问题 *</pattern>
<template>
<srai>EVERYTHING</srai>
</template>
</category>
<category>
<pattern>EVERYTHING</pattern>
<template>
just so so,不过你可以试一试,我擅长解决法律问题而已
</template>
</category>

<category>
<pattern>* 目标 *</pattern>
<template>
<srai>TARGET</srai>
</template>
</category>
<category>
<pattern>TARGET</pattern>
<template>
我有一个小目标,先看能不能赚个1个亿
</template>
</category>
</aiml>


在线聊天截图:







以上在线聊天机器人实现不是最优的,还有很多地方需要改进。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐