ModuleNotFoundError: Cannot find class 'DIETClassifier' from global namespace

while training my model i get this import error.

rasa-worker_1      |     return class_from_module_path(component_name)
rasa-worker_1      |   File "/build/lib/python3.6/site-packages/rasa/utils/common.py", line 211, in class_from_module_path
rasa-worker_1      |     raise ImportError(f"Cannot retrieve class from path {module_path}.")
rasa-worker_1      | ImportError: Cannot retrieve class from path DIETClassifier.
rasa-worker_1      | 
rasa-worker_1      | During handling of the above exception, another exception occurred:
rasa-worker_1      | 
rasa-worker_1      | Traceback (most recent call last):
rasa-worker_1      |   File "/build/lib/python3.6/site-packages/rasa/server.py", line 799, in train
rasa-worker_1      |     None, functools.partial(train_model, **info)
rasa-worker_1      |   File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
rasa-worker_1      |     result = self.fn(*self.args, **self.kwargs)
rasa-worker_1      |   File "/build/lib/python3.6/site-packages/rasa/train.py", line 50, in train
rasa-worker_1      |     additional_arguments=additional_arguments,
rasa-worker_1      |   File "uvloop/loop.pyx", line 1456, in uvloop.loop.Loop.run_until_complete
rasa-worker_1      |   File "/build/lib/python3.6/site-packages/rasa/train.py", line 101, in train_async
rasa-worker_1      |     additional_arguments,
rasa-worker_1      |   File "/build/lib/python3.6/site-packages/rasa/train.py", line 188, in _train_async_internal
rasa-worker_1      |     additional_arguments=additional_arguments,
rasa-worker_1      |   File "/build/lib/python3.6/site-packages/rasa/train.py", line 245, in _do_training
rasa-worker_1      |     persist_nlu_training_data=persist_nlu_training_data,
rasa-worker_1      |   File "/build/lib/python3.6/site-packages/rasa/train.py", line 474, in _train_nlu_with_validated_data
rasa-worker_1      |     persist_nlu_training_data=persist_nlu_training_data,
rasa-worker_1      |   File "/build/lib/python3.6/site-packages/rasa/nlu/train.py", line 74, in train
rasa-worker_1      |     trainer = Trainer(nlu_config, component_builder)
rasa-worker_1      |   File "/build/lib/python3.6/site-packages/rasa/nlu/model.py", line 144, in __init__
rasa-worker_1      |     components.validate_requirements(cfg.component_names)
rasa-worker_1      |   File "/build/lib/python3.6/site-packages/rasa/nlu/components.py", line 39, in validate_requirements
rasa-worker_1      |     component_class = registry.get_component_class(component_name)
rasa-worker_1      |   File "/build/lib/python3.6/site-packages/rasa/nlu/registry.py", line 181, in get_component_class
rasa-worker_1      |     raise ModuleNotFoundError(exception_message)
rasa-worker_1      | ModuleNotFoundError: Cannot find class 'DIETClassifier' from global namespace. Please check that there is no typo in the class name and that you have imported the class into the global namespace.
rasa-worker_1      | ```

I am running rasa 1.7.4

Which Rasa Open Source version are you using? And can you please share the content of your config.yml? :pray:

Did we get the solution for this issue, I am also stuck with the same problem ?

I am using Rasa 2.2.6 the latest version …

1 Like

Did we get the solution for this issue, I am also stuck with the same problem ? I did faced the same issue with class WhitespaceTokenizer, so i found the class name for WhitespaceTokenizer and added it to config.yml and it solved the issue. but was unable to find the complete class name for DIETClassifier so getting the mentioned error.

Please help me out. Let me know if more detail is required.

 pip                       21.2.2           
 python                    3.8.13               
 rasa                      2.8.0                  
 rasa-nlu                  0.13.3                   
 ruamel-yaml               0.16.13

config.yml that i am using is as below

language: en

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: rasa_nlu.tokenizers.whitespace_tokenizer.WhitespaceTokenizer
   - name: rasa_nlu.featurizers.regex_featurizer.RegexFeaturizer
#   - name: LexicalSyntacticFeaturizer
   - name: rasa_nlu.featurizers.count_vectors_featurizer.CountVectorsFeaturizer
   - name: rasa_nlu.featurizers.count_vectors_featurizer.CountVectorsFeaturizer
     analyzer: char_wb
     min_ngram: 1
     max_ngram: 4
#   - name: DIETClassifier
#     epochs: 100
#     constrain_similarities: true
   - name: rasa_nlu.extractors.entity_synonyms.EntitySynonymMapper
#   - name: ResponseSelector
#     epochs: 100
#     constrain_similarities: true
#   - 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: MemoizationPolicy
#   - name: RulePolicy
#   - name: UnexpecTEDIntentPolicy
#     max_history: 5
#     epochs: 100
#   - name: TEDPolicy
#     max_history: 5
#     epochs: 100
#     constrain_similarities: true

The python code that i am using to load nlu.json and train a model is as follows, can any please review the below code.

from rasa_nlu.training_data  import load_data
from rasa_nlu.config import RasaNLUModelConfig
from rasa_nlu.model import Trainer
from rasa_nlu import config
from rasa_nlu.model import Metadata, Interpreter


def load(js_filename):
    train_data = load_data(js_filename)
    trainer = Trainer(config.load("config.yml"))

    trainer.train(train_data)
    model_directory = trainer.persist('models/')
    interpreter = Interpreter.load(model_directory)
    return interpreter


if __name__ == "__main__":
    interpreter = load('data/nlu.json')
    user_text = u"hey"
    print(interpreter.parse(user_text))