如何在Rasa NLU中使用lookup_tables?

问题描述 投票:0回答:1

我尝试在文档中查找信息: https://learning.rasa.com/conversational-ai-with-rasa/entities/ 在这里 https://rasa.com/docs/rasa/nlu-training-data/#lookup-tables

但我无法找到端到端的实现

我在我的项目中创建了带有颜色的txt,在我的配置中我写道:

  lookup_tables:
    colors:
      elements: "colors.txt"

在我的 nlu.yml 中:

- intent: what_colors
  examples: |
      - Do you like [red](colors)
      - I like [blue](colors)?
      - I love [green](colors)

在我的故事.yml中:

- story: what colors do you like
  steps:
  - intent: greet
  - action: utter_greet
  - intent: what_colors
  - action: action_colors

我也有 actions.py:

class ActionColors(Action):

    def name(self) -> Text:
        return "action_colors"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

        color = next(tracker.get_latest_entity_values("color"), None)

        colors_names = np.loadtxt('colors.txt')

        if color  in colors_names:
            dispatcher.utter_message(text="You choose: " + color + ".")
        else:
            dispatcher.utter_message(text=f"There is no color like: {color} in colors file.")

        return []

在我的域中我有:

entities:
 - colors

当我训练、运行 rasa actions 和 rasa shell 时,我会问“你喜欢红色吗?”我只得到后备响应,我做错了什么?在文档中的哪里可以找到实现“查找表”的完整路径?

我知道 config.yml 需要“RegexEntityExtractor”和“RegexFeaturizer”,但是当我实现这个时,我得到了:

“用户警告:无法从模型存储加载 RegexEntityExtractor。如果无法训练模型,则可能会发生这种情况,因为无法从给定的训练数据中提取正则表达式 - 因此无法持久化。”

rasa rasa-nlu
1个回答
0
投票

我发现我的主要问题是 config.yml 错误

这是我的查找表工作时的 config.yml:

pipeline:
    - name: WhitespaceTokenizer
    - name: RegexFeaturizer
    - name: RegexEntityExtractor
    - name: LexicalSyntacticFeaturizer
    - name: CountVectorsFeaturizer
    - name: CountVectorsFeaturizer
      analyzer: char_wb
      min_ngram: 1
      max_ngram: 4
    - name: DIETClassifier
      epochs: 100
      constrain_similarities: True
    - name: EntitySynonymMapper
    - name: FallbackClassifier
      threshold: 0.7
      ambiguity_threshold: 0.1

policies:

我对 txt 仍然有问题,但是当我将它们放入我的 nlu.yml 中时,它们正在工作:

- intent: zamówienie
  examples: |
      - What color do you know [green](color)
      - What color do you like [green](color)
      - Do you know [green](color), it is my favorite color!

- lookup: Restaurant
  examples: |
    - green
    - red
    - purple
    - yellow
    - black
    - white
    - grey
    - orange
    - pink
© www.soinside.com 2019 - 2024. All rights reserved.