【问题标题】:chatbot: how to correctly determine intents?聊天机器人:如何正确判断意图?
【发布时间】:2017-08-21 13:47:44
【问题描述】:

例如,确定以下意图之间差异的常用技术是什么?

  1. 当前温度是多少? 在这种情况下,直接响应将是当前温度。

  2. 当前温度是否为 22 度? 在这种情况下,适当的回答是是或否。

我正在构建一个封闭域聊天机器人(例如 Siri),我想知道 Python 中是否有任何我可以阅读的技术。

【问题讨论】:

  • 检查里面是否有数字
  • 我应该很清楚 - 这只是一个例子。这可能是一个没有任何数字的问题,但它仍然是第 2 类问题。
  • 这对于 Stack Overflow 问题来说太宽泛了。

标签: python chatbot


【解决方案1】:

我曾经接触过编程,试图了解机器人是如何工作的。多么小的世界。我几乎不记得我是怎么做的了,但让我们假设您根据您的机器人可以读取的事件构建聊天。一个非常基本的方法来确定每个事件的响应是一个巨大的 IF ELIF 内容列表,其中包含嵌套行为(理想情况下分为方法)。

def handleevent (message, user, date, font, whatever):
    if "current temperature" in message:
        send_text_to_chat("The temperature is 22 degrees")
    elif "is current temperature" in message and "?" in message:
        specific_temp_asked(message)
    elif "potato" in message: # you could do hundred of behaviours, and nested ones.
        if user == "apple":
            send_text_to_chat("Hi apple!")
        else:
            send_text_to_chat("I am a potato bot")
    elif "who am I?" in message: # example using the event data
        send_text_to_chat("you are " + user)
    else:
        send_text_to_chat("Be more specific")

然后您必须像这样对每个特定情况进行编码:

def specific_temp_asked(message):
    temperature = None
    split_message = message.split(" ")
    for i in split_message:
        try:
            int(i)
            temperature = i
            break
        except:
            pass
    if not temperature == None:
        real_temperature = check_temp(somehow)
        if real_temperature == temperature:
            send_text_to_chat("Yes")
        else:
            send_text_to_chat("Nope")

最后说明:这绝不是最好的方法,但如果你正在学习,我会在不太复杂的情况下完成工作,然后你慢慢改进代码。

【讨论】:

  • 感谢您抽出时间回复。发布问题后,我在 Siri 上尝试了这个(不确定 Cortana(或其他机器人)的表现如何),但它对这两个问题的回答相同。所以,可能是我想多了,也可能不是。
  • 机器人会给您提供与您编码一样精确的答案。我的机器人一次有 2500 个可能的答案,然后我就厌烦了。但是对于这 2500 个中的每一个,它都有特定的理由来回答。诀窍是使用关键字。例如,如果检测到“温度”,他会告诉你温度,不管你真正问的是什么。您还可以存储同一个问题的多个答案并随机选择一个。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-09-29
  • 1970-01-01
  • 2022-12-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多