Code Monkey home page Code Monkey logo

rasachatbot's Introduction

OverView

一个基于Rasa Stack, 带有WebUI的知识问答机器人

后端 前端

功能截图

Demo

技术架构

pipeline 参考

模块化

Action - Rasa NLU - Rasa Core - Web Server

Context保存

将所需要的entities放入不同slot中(通过Rasa-core实现)

基于意图(Intent-based)的对话

这是当NLP算法使用intents和entities进行对话时,通过识别用户声明中的名词和动词,然后与它的dictionary交叉引用,让bot可以执行有效的操作。

...

Rasa NLU

使用自然语言理解进行意图识别和实体提取

Example:

rquest(part) "张青红的生日什么时候"

response

{
  "intent": "view_defendant_data",
  "entities": {
    "defendant" : "张青红",
    "item" : "生日"
  }
}

Pipeline

假设我们在config文件中这样设置pipeline"pipeline": ["Component A", "Component B", "Last Component"] 那么其生命周期如下: LifeCircleComponent A调用开始之前, rasa nlu会首先根据nlu的训练集创建一个Context(no more than a python dict). Context用于在各个Component之间传递消息。 比如, 我们可以让Component A去根据训练集计算特征向量, 训练完成后将结果保存在Context中, 传递到下一个Component。 Component B 可以获取这些特征向量, 并根据其做意图分类。在所有Component完成后, 最后的Context中保存这个模型的元数据(metadata).

language: "zh"

pipeline:
- name: "nlp_mitie"
  model: "data/total_word_feature_extractor_zh.dat"
- name: "tokenizer_jieba" 
- name: "ner_mitie" 
- name: "ner_synonyms"
- name: "intent_entity_featurizer_regex"
- name: "intent_featurizer_mitie"
- name: "intent_classifier_sklearn"

MITIE是一个MIT信息提取库,该库使用了最先进的统计机器学习工具构建。它类似于word2vec中的word embedding。MITIE模型,在NLU(自然语言理解)系统中,完成实体识别和意图提示的任务。 ”nlp_mitie”初始化MITIE ”tokenizer_jieba”用jieba来做分词 ”ner_mitie”和”ner_synonyms”做实体识别 ”intent_featurizer_mitie”为意图识别做特征提取”intent_classifier_sklearn”使用sklearn做意图识别的分类。

Training

我们的训练集data.json

{
  "rasa_nlu_data": {
    "common_examples": [
      {
        "text": "张青红的生日什么时候",
        "intent": "viewDefendantData",
        "entities": [
          {
            "start": 4,
            "end": 6,
            "value": "生日",
            "entity": "item"
          },
          {
            "start": 0,
            "end": 3,
            "value": "张青红",
            "entity": "defendant"
          }
        ]
      }
    ]
  }
}

也可以通过可视化工具(rasa-nlu-trainer)进行实体的标注等 Rasa-nlu-trainer

Run as a service

curl -XPOST localhost:5000/parse -d '{"q":"张青红的生日是什么时候", "project":"CriminalMiner", "model":"nlu"}'

Rasa Core

用于对话管理

技术架构

Core技术架构

  1. Rasa_Core首先接收到信息, 将信息传递给Interpreter, Interpreter将信息打包为一个字典(dict), 这个dict包括原始信息(original text), 意图(intent)的找到的所有实体(entities)
  2. Tracker保持对话的状态.
  3. Policy 接收到当前Tracker的状态
  4. Policy选择执行哪个动作(Action)
  5. 被选中的Action同时被Tracker记录
  6. Action执行后产生回应

Training

基于对话

## story_01
* greet
  - utter_greet
## story_02
* goodbye
  - utter_goodbye
## story_03
* viewCaseDefendantsNum
  - action_view_case_defendants_num
## story_04
* viewCaseDefendants
  - action_view_case_defendants
## story_05
* viewCase
  - utter_ask_case

Interactive Learning

在交互式学习模式下, 我们可以为Bot对话提供反馈. 这是一个非常强有力的方式去检测Bot能做什么, 同时也是修改错误最简单的方式. 基于机器学习的对话的有点就在于当bot不知道如何回答或者回答错误时, 我们可以及时的反馈给bot. 有些人称这种方式为Software 2.0

同时在这个训练过程中, 是可视化的, 在我看来, 是个究极阉割版的TensorBoard

Action

进行数据校验, 和数据交互. 采用Py2Neo与数据库(Neo4j)进行交互.

rasachatbot's People

Contributors

wangyizhen avatar bing-zhub avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.