我想使用余弦相似度来识别意图并将其传递给 RASA Core

I want to use cosine similarity to identify the intent and pass it to RASA Core

我想使用余弦相似度来识别意图并将其传递给 RASA Core。换句话说,我想用其他一些相似度计算方法来替换NLU部分。 怎么做?

目前,Rasa-NLU 中实现了四个分类器:

如果默认使用embedding_intent_classifier.py,则使用余弦相似度:

"similarity_type": 'cosine',  # string 'cosine' or 'inner'

如何自定义您的管道?

language: "en"

pipeline:
- name: "tokenizer_whitespace"
- name: "ner_crf"
- name: "ner_synonyms"
- name: "intent_featurizer_count_vectors"
- name: "intent_classifier_tensorflow_embedding"

有关详细信息,请参阅 here

如何定义自己的组件?

从父对象继承 Component 并实现您自己的对象。如果您需要定义 tfidfcosine,请阅读 here, and then compare your code with here

from rasa_nlu.components import Component

class MyComponent(Component):
 def __init__(self, component_config=None):
     pass

 def train(self, training_data, cfg, **kwargs):
     pass

 def process(self, message, **kwargs):
     pass

 def persist(self, model_dir):
     pass

 @classmethod
 def load(cls, model_dir=None, model_metadata=None, cached_component=None,
          **kwargs):

也不要忘记将其添加到管道中:

pipeline:
- name: "MyComponent"