Training Exactly One Intent

rasa-core
(Anthony Fowler) #1

I am following the guide here: Python API to test out a custom intent. I notice that unless my training data json has more than one intent, the python API consistently returns no found intents.

Training data:

{
  "rasa_nlu_data": {
    "regex_features": [],
    "common_examples": [
      {
        "text": "what is the temperature today?",
        "intent": "intent_3"
      },
      {
        "text": "what is the weather today?",
        "intent": "intent_3"
      },
      {
        "text": "will it rain today?",
        "intent": "intent_3"
      }
    ],
    "lookup_tables": [],
    "entity_synonyms": []
  }
}

Config:

language: en
pipeline: pretrained_embeddings_spacy

Code:

from rasa_nlu.training_data import load_data
from rasa_nlu.model import Trainer
from rasa_nlu import config

training_data = load_data('training_data.json)
trainer = Trainer(config.load("config.yml"))
trainer.train(training_data)
model_directory = trainer.persist('model_dir') 
from rasa_nlu.model import Interpreter

interpreter = Interpreter.load(model_directory)
interpreter.parse("what is the weather today?")

Response with one intent:

{'intent_ranking': [], 'entities': [], 'text': 'what is the weather today?', 'intent': None}

I found that if I add another intent to the common examples of my training data, then I get a good response:

New training Data:

{
  "rasa_nlu_data": {
    "regex_features": [],
    "common_examples": [
      {
        "text": "what is the temperature today?",
        "intent": "intent_3"
      },
      {
        "text": "what is the weather today?",
        "intent": "intent_3"
      },
      {
        "text": "will it rain today?",
        "intent": "intent_3"
      },
      {
        "text": "how much does that cost?",
        "intent": "intent_4"
      },
      {
        "text": "what is the price?",
        "intent": "intent_4"
      }
    ],
    "lookup_tables": [],
    "entity_synonyms": []
  }
}

Response with new training data:

{'intent_ranking': [{'confidence': 0.8170498642280895, 'name': 'intent_3'}, {'confidence': 0.18295013577191052, 'name': 'intent_4'}], 'entities': [], 'text': 'what is the weather today?', 'intent': {'confidence': 0.8170498642280895, 'name': 'intent_3'}}

Why I am I seeing this behavior? Is it possible to train exactly one intent?

(Ella Rohm-Ensing) #2

Hi @afowler, if you only have one intent in your data, an intent classifier component will not train, as it doesn’t have any classification work to do. If you only want to do entity extraction, simply remove the intent classifier from your pipeline.

(Anthony Fowler) #3

@erohmensing I don’t think that entity extraction is what I am shooting for here. I am looking to train a model so that it can sense the existence or non-existence of a particular intent. Perhaps I am approaching this incorrectly; what I am trying to do is something similar to the quickstart for wit.ai: Wit — Quickstart, where one intent is created and then is able to be detected when queried. Is such functionality not available on Rasa?

(Ella Rohm-Ensing) #4

Ah okay I see. No, in Rasa, you need to have at least 2 classes, there is no existence or non-existence of intents, just classification between the different provided intents. Therefore having 1 intent is pretty pointless because if it is the only option, it would be predicted with confidence 1 every time. Therefore we don’t train an intent classifier if there’s only 1 class.