讲完一个故事后,Rasa 特工停止回应

Rasa agent stop responding after one story has spoken

我用 rasa 写了一个简单的机器人。为了处理消息,我创建了 flask 应用程序并将代理加载到该应用程序中。我从请求中收到用户消息和 ID,并将其放入代理 handle_text 方法,然后我得到了响应。问题是,在我讲了一个在我的 story.md 中定义的故事后,我的代理停止回答。

这是我的烧瓶应用程序

app = Flask(__name__)


# Define rasa interpreter
interpreter = None

# Define rasa agent
agent = None


@app.route('/')
def index():

    # Receive message from request
    message = request.args.get('msg')

    # Receive user id from request
    user_id = request.args.get('uid')

    #  Validation
    if not message:
        return 'No message specified in field \'msg\''
    if not user_id:
        return 'No user id specified in field \'uid\''

    # Put received message into rasa agent
    answers = agent.handle_text(message, sender_id=user_id)

    # Define text for the response
    text = None

    if len(answers) > 0:
        text = "User: {} | {}".format(user_id, answers[0].get('text'))
    else:
        text = "User: {} | Nothing to answer".format(user_id)

    return text


if __name__ == '__main__':

    # Load rasa interpreter
    interpreter = RasaNLUInterpreter(NLU_PATH)

    # Load rasa agent
    agent = Agent.load(CORE_PATH, interpreter=interpreter)

    app.run()


我的 stories.md 是

## Simple flow
* greet
  - utter_greet
* bye 
  - utter_bye 
## Order pizza
* greet
  - utter_greet
* order_pizza_type
  - utter_finish_order_pizza
* bye
  - utter_bye
## Story
* order_pizza_type
  - utter_finish_order_pizza
## Generated Story -1054914010798310995
* greet
    - utter_greet
* order_pizza_type{"Country": "mexican"}
    - utter_finish_order_pizza
* bye
    - utter_bye
## New Story
* greet
  - utter_greet
* order_pizza_wish
  - utter_finish_order_pizza
* bye
    - utter_bye

和我的config.yml

language: "en"

pipeline:
- name: "nlp_spacy"
- name: "tokenizer_spacy"
- name: "ner_crf"
- name: "tokenizer_whitespace"
- name: "intent_featurizer_count_vectors"
- name: "intent_classifier_tensorflow_embedding"
  intent_tokenization_flag: true
  intent_split_symbol: "+"

policies:
  - name: "KerasPolicy"
    featurizer:
    - name: MaxHistoryTrackerFeaturizer
      max_history: 5
      state_featurizer:
        - name: BinarySingleStateFeaturizer
  - name: "MemoizationPolicy"
    max_history: 5
  - name: "FallbackPolicy"
    nlu_threshold: 0.4
    core_threshold: 0.3

我的预期结果

$ curl -X GET "https://localhost?msg=hello&uid=1"
$ curl -X GET "https://localhost?msg=I want to order pizza&uid=1"
$ curl -X GET "https://localhost?msg=Bye&uid=1"
$ curl -X GET "https://localhost?msg=hello&uid=1"

回应

> User: 1 | Hey! How are you?
> User: 1 | Ok I will deliver pizza for you
> User: 1 | Bye
> User: 1 | Hey! How are you?

但我的实际结果是

$ curl -X GET "https://localhost?msg=hello&uid=1"
$ curl -X GET "https://localhost?msg=I want to order pizza&uid=1"
$ curl -X GET "https://localhost?msg=Bye&uid=1"
$ curl -X GET "https://localhost?msg=hello&uid=1"

回应

> User: 1 | Hey! How are you?
> User: 1 | Ok I will deliver pizza for you
> User: 1 | Bye
> User: 1 | Nothing to answer

正如您所看到的,在讲完一个故事情节后 "hello" 第二条消息没有回复。

与评论中的建议相同我建议使用 interactive learning 调试您的机器人并创建新的训练故事。目前您的训练数据非常稀疏。

您是否使用 augmentation 进行训练?如果您没有以不同方式指定参数,则默认扩充设置为 20.

如果您正在使用增强功能,我建议您也添加另一个短篇小说来处理独立的 greet:

## Simple flow
* greet
  - utter_greet

还有一件事: 建议使用一般意图,并通过识别的实体进行区分。 因此,与其使用 order_pizza_typeorder_pizza_wish,不如使用 order_pizza 甚至 order 的意图,然后使用 food_typeproduct_to_order 的插槽(例如 pizza)等等。如果你有非常相似的意图,例如 order_pizza_typeorder_pizza_wish,NLU 将很难区分它们。