搭建 rasa 框架流程

  1. 先初始化一个空工程,添加 compents、pre_models 路径
    在这里插入图片描述
  2. 在 config.yml 中增加 pipeline:定义 tokenizer 和 featurizer 和 classifier 等
language: en
pipeline:
  - name: WhitespaceTokenizer
    intent_tokenization_flag: True
  - name: LanguageModelFeaturizer
  - name: RegexFeaturizer
  - name: LexicalSyntacticFeaturizer
  - name: CountVectorsFeaturizer
  - name: CountVectorsFeaturizer
    analyzer: char_wb
    min_ngram: 1
    max_ngram: 4
  - name: DIETClassifier
    epochs: 200
policies:
- name: TEDPolicy
  epochs: 200

# Configuration for Rasa NLU.
# https://rasa.com/docs/rasa/nlu/components/
language: zh

pipeline:
  # # No configuration for the NLU pipeline was provided. The following default pipeline was used to train your model.
  # # If you'd like to customize it, uncomment and adjust the pipeline.
  # # See https://rasa.com/docs/rasa/tuning-your-model for more information.
  - name: compoments.nlu.tokenizers.bert_tokenizer.CustomBertTokenizer
    cache_dir: ./tmp
    model_weights: pre_models
  - name: LanguageModelFeaturizer
    cache_dir: ./tmp
    model_name: bert
    model_weights: pre_models
  - name: DIETClassifier
    epochs: 100
  - name: RegexEntityExtractor
  - name: EntitySynonymMapper
  - name: ResponseSelector
    epochs: 100
    retrieval_intent: rasa_faq
  - name: FallbackClassifier
    threshold: 0.3
    ambiguity_threshold: 0.1

# Configuration for Rasa Core.
# https://rasa.com/docs/rasa/core/policies/
policies:
# # No configuration for policies was provided. The following default policies were used to train your model.
# # If you'd like to customize them, uncomment and adjust the policies.
# # See https://rasa.com/docs/rasa/policies for more information.
   - name: AugmentedMemoizationPolicy
   - name: TEDPolicy
     max_history: 5
     epochs: 100
   - name: compoments.polices.ask_again_policy.AskAgainRulePolicy
     core_fallback_threshold: 0.5
     ask_again_intent: "再问一次"
     need_ask_again_intents:
      - "查询天气"

  1. 定义 domain.yml 文件:这里主要需要定义 intents、responses、slots、entities、(forms)、actions 等
version: "2.0"

intents:
  - greet
  - goodbye
  - affirm
  - deny
  - mood_great
  - mood_unhappy
  - bot_challenge

responses:
  utter_greet:
  - text: "Hey! How are you?"
    buttons:
    - title: "great"
      payload: "/mood_great"
    - title: "super sad"
      payload: "/mood_unhappy"

  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"

  utter_iamabot:
  - text: "I am a bot, powered by Rasa."

session_config:
  session_expiration_time: 60  # value in minutes
  carry_over_slots_to_new_session: true

version: "2.0"

actions:
 - utter_greet
 - utter_suggest_cuisine
 - utter_search_restaurants

intents:
 - greet
 - affirm
 - deny
 - search_restaurant

responses:
  utter_greet:
  - text: "hi!"
  utter_suggest_cuisine:
  - text: "how about greek food?"
  - text: "how about chinese food?"
  - text: "how about italian food?"
  - text: "how about sushi?"
  utter_search_restaurants:
  - text: "great! here's what I found ..."

  1. 定义 data 里的 yml 文件(默认 train 的路径是 data,这些 yml 文件就是训练数据)其中 nlu.yml 是 nlu 模型的训练数据,stories.yml、 rules.yml是 core 模型的训练数据
version: "2.0"

nlu:
  - intent: greet
    examples: |
      - 你好
      -- 您好
      - 早上好
      - 下午好
      - 晚上好
      --- intent: goodbye
    examples: |
      - good afternoon
      - cu
      - good by
      - cee you later
      - good night
      - bye
      - goodbye
      - have a nice day
      - see you around
      - bye bye
      - see you later
      - 明天见
      - 下次再见
      - 有缘再见
      - 江湖再见

version: "2.0"

stories:

- story: happy path
  steps:
  - intent: greet
  - action: utter_greet
  - intent: mood_great
  - action: utter_happy

  1. 以上定义完成后就可以训练 rasa train nlu 模型了,会自动保存在 model 文件夹下,命名是时间戳 + .tar.gz
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值