zoukankan      html  css  js  c++  java
  • Rasa学习记录 01

    Rasa的安装和简单的测试

    怪雨是新手,刚刚接触Rasa,以下内容不一定正确。有错误的地方欢迎指出。

    什么是Rasa:

    ​ 我的理解是一开源的机器学习框架用于AI助手和机器人。基于两个主要的模块

    • NLU:自然语言理解(Natural Language Understanding,简称NLU)技术
    • Core:核心 保存对话并决定下一步做什么

    安装Rasa:

    怪雨的系统:manjaro18+kde

    安装前先更新同步数据库:sudo pacman -Syy

    系统已经安装过以下内容的,可以跳过这一步(这一步也只是确保不会因为缺少什么而报错)

    ​ - 安装pip3sudo pacman -S python-pip

    ​ - 安装相关的依赖的python3的库pip install numpy pandas jieba sklearn

    安装Rasa和Rasa-x 并初始化Rasa

    pip install rasa-x --extra-index-url https://pypi.rasa.com/simple

    rasa init
    ​ rasax就是Rasa 带界面的工具安装后终端运行rasax会自动弹出浏览器进入Rasax界面

    测试自带的数据


    现在就可以测试自带的简单数据了

    不过对话要按照自己编写的stories来对话

    输入/stop就能推出Rasa shell

    输入Rasa shell就能再次进入对话!


    查看项目里的文件内容

    1. 创建一个项目:

      rasa init --no-prompt 不加后面的--no-prompt的话会详细的问你需要设置什么

    2. 查看训练数据

      1. 可以通过cat data/nlu.md来查看 (以下是markdown的格式)
      ## intent:affirm
      - yes
      - indeed
      - of course
      - that sounds good
      - correct
      
      ## intent:deny
      - no
      - never
      - I don't think so
      - don't like that
      - no way
      - not really
      

      ​ ##后面是intents(意图) 就是以下的几条消息所要表达的意图

      ​ -后面跟的就是消息了

      ​ 意思就是把这一组消息都是这一意图

    3. 为你的模型配置

      你可以通过cat config.yml来查看配置文件

      # Configuration for Rasa NLU.
      # https://rasa.com/docs/rasa/nlu/components/
      language: en
      pipeline: supervised_embeddings
      
      # Configuration for Rasa Core.
      # https://rasa.com/docs/rasa/core/policies/
      policies:
        - name: MemoizationPolicy
        - name: KerasPolicy
        - name: MappingPolicy
      

      这些文件定义了你这个模型会使用的NLU和CORE组件

      NLUpipeline的选择:

      • 如果训练样例小于1000的 使用pipeline: "pretrained_embeddings_spacy"

      • 如果训练样例大于1000的 使用pipeline: "supervised_embeddings"

        以上两个是最重要的两个pipelines

    4. 编写自己的第一个Stories

      这个文档是教你的助手如何去回应消息的

      strories就是机器和用户的对话,core models通过真实的对话学习来训练自己。

      同样cat data/stories.md查看一下里面的内容(截取部分)

      ## happy path
      * greet
        - utter_greet
      * mood_great
        - utter_happy
      
      ## sad path 1
      * greet
        - utter_greet
      * mood_unhappy
        - utter_cheer_up
        - utter_did_that_help
      * affirm
        - utter_happy
      

      *greet * 后面的是用户发送的消息(语句的意图或是实体)

      - utter_greet - 后面是action (机器人需要执行的操作,可以是回一段消息或是自定义操作)

      ​ action中如果是回消息的话需要 回话必须要以utter_开头且与domain里面定义的一致

      ​ 如果是自定义操作虽然没有强制要求不过最好以action_开头

      action这里还大有内容,后面学习了更新到后面的文章

    5. 定义一个Domain

      [^]: 这里说域的话好像不太合适 保留英文Domain吧

      老样子查看cat domain.yml

      intents:
      - greet
      - goodbye
      - affirm
      - deny
      - mood_great
      - mood_unhappy
      templates:
        utter_greet:
        - text: Hey! How are you?
        utter_cheer_up:
        - text: 'Here is something to cheer you up:'
          image: https://i.imgur.com/nGF1K8f.jpg
        utter_did_that_help:
        - text: Did that help you?
        utter_happy:
        - text: Great carry on!
        utter_goodbye:
        - text: Bye
      actions:
      - utter_greet
      - utter_cheer_up
      - utter_did_that_help
      - utter_happy
      - utter_goodbye
      
      
      intents 你期待用户说的话(意图)
      actions 机器人能做的和能说的
      templates 机器人回话模板
    6. 训练模型

      每次一的更新内容,我们都需要重新训练我们的模型

      执行下列代码

      rasa train
      echo "Finished training."
      
    7. 与机器人对话

      执行rasa shell


    举一反三(自己的第一个机器人)

    1. 修改 data/nlu.md 中加入中文

      截取内容如下

      ## intent:affirm
      - yes
      - indeed
      - of course
      - that sounds good
      - correct
      - 是的
      - 当然
      - 正确
      
    2. 修改cat config.yml的内容

      language: en 改为 language: zh

    3. 修改domain.yml内容

      修改templates: utter 的text的文本内容

      templates:
        utter_greet:
        - text: 嗨!生活还好吗
        utter_cheer_up:
        - text: '希望这张图片能让你心情有所好转:'
          image: https://i.imgur.com/nGF1K8f.jpg
        utter_did_that_help:
        - text: 对你有帮助吗?
        utter_happy:
        - text: 加油!继续!
        utter_goodbye:
        - text: 再见
      
    4. 尝试训练

      rasa train

    5. 运行

      rasa shell

  • 相关阅读:
    mysq 日期相减
    说说时间观与时间管理——北漂18年(71)
    ionic之切换开关
    ionic之单选框
    SELECT ... LOCK IN SHARE MODE和SELECT ... FOR UPDATE locks在RR模式下可以看到最新的记录
    14.5.2.3 Consistent Nonlocking Reads 一致性非锁定读
    14.5.2.2 autocommit, Commit, and Rollback
    14.5.2 事务隔离级别
    对于唯一索引使用唯一条件搜索, InnoDB 只锁定找到的index record,不是它之前的区间
    mysql explain 解释
  • 原文地址:https://www.cnblogs.com/am5sia/p/11548802.html
Copyright © 2011-2022 走看看