RasaHQ / rasa

💬 Open source machine learning framework to automate text- and voice-based conversations: NLU, dialogue management, connect to Slack, Facebook, and more - Create chatbots and voice assistants
https://rasa.com/docs/rasa/
Apache License 2.0
18.63k stars 4.6k forks source link

Silent failure when the number of intents is less than 2 #4390

Closed furqan-shakoor closed 4 years ago

furqan-shakoor commented 5 years ago

Rasa version: '0.15.1'

Rasa X version (if used & relevant):

Python version: 3.7

Operating system (windows, osx, ...): MacOS

Issue: If the number of intents in an application is less than 2, the application does not correctly classify any inputs to an intent.

The endpoints /train and /parse both return 200 in such a case, indicating no errors. But the server logs show the following errors when /parse is called

2019-09-04 17:16:23+0200 [-] 2019-09-04 17:16:23 WARNING  rasa_nlu.classifiers.embedding_intent_classifier  - Failed to load nlu model. Maybe path /Users/furqan/sandbox/furqs/a3ea383570354a609776bbfeb26493dd/2 doesn't exist
2019-09-04 17:16:23+0200 [-] 2019-09-04 17:16:23 ERROR    rasa_nlu.classifiers.embedding_intent_classifier  - There is no trained tf.session: component is either not trained or didn't receive enough training data

I traced the error to the following snippet of code in embedding_intent_classifier.py, in the function train

        intent_dict = self._create_intent_dict(training_data)
        if len(intent_dict) < 2:
            logger.error("Can not train an intent classifier. "
                         "Need at least 2 different classes. "
                         "Skipping training of intent classifier.")
            return

Since this block bails out of the train function, as a consequence the training of the EmbeddingIntentClassifier never goes through and the relevant training files are never saved.

Eventually when /train is called, the load function of EmbeddingIntentClassifier fails because of the snippet if model_dir and meta.get("file"). This translates into the session attribute not being set and then the process method failing because self.session is None

I believe the /train endpoint should return an error in such a case and let the user know that train was in fact not successful

sara-tagger commented 5 years ago

Thanks for the issue, @Ghostvv will get back to you about it soon!

You may find help in the docs and the forum, too 🤗
erohmensing commented 5 years ago

This makes sense. Would you be interested in contributing a fix @furqan-shakoor ?

jeanfrancois8512 commented 5 years ago

I have reproduced the behavior in 0.15.1. If failing early is the good behavior when training a component, one way to do it is:

        intent_dict = self._create_intent_dict(training_data)
        if len(intent_dict) < 2:
            raise Exception("Can not train an intent classifier. "
                         "Need at least 2 different classes. "
                         "Skipping training of intent classifier.")

This will make the server return a 500 status code with the message as content. I haven't tested this in master. The server has changed since 0.15.1 and more test will be needed.

lucianaribeiro commented 4 years ago

I would like to work on that

erohmensing commented 4 years ago

awesome @lucianaribeiro 🎉would be great if you could look into this issue on master. Let us know if you need any help! Maybe @jeanfrancois8512 can also help!

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

erohmensing commented 4 years ago

not stale, in discussion atm

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

This issue has been automatically closed due to inactivity. Please create a new issue if you need more help.