dialoguekit.nlu.models.diet_classifier_rasa

Rasa DIET classifier.

More information about the DIET classifier https://rasa.com/docs/rasa/reference/rasa/nlu/classifiers/diet_classifier/

A short description of how we use Rasa as a component library can be seen at: https://iai-group.github.io/DialogueKit/nlu.html#rasa-as-a-component-library

Classes

IntentClassifierRasa

Initializes the intent classifier.

Module Contents

class dialoguekit.nlu.models.diet_classifier_rasa.IntentClassifierRasa(intents: List[dialoguekit.core.intent.Intent], training_data_path: str | None = '', model_path: str | None = '.rasa')

Bases: dialoguekit.nlu.intent_classifier.IntentClassifier, dialoguekit.nlu.slot_annotator.SlotValueAnnotator

Initializes the intent classifier.

The training data path may be used with a Rasa nlu.yml file. It is also possible to use the self.train_model function with a list of Utterance and a list of Intent.

Parameters:
  • intents – List of allowed intents.

  • training_data_path – Path to the training data yml. Defaults to empty string.

  • model_path – Path to where rasa trained model will be stored. Defaults to ‘.rasa’.

init_pipeline() None

Creates classifier and initialize.

A component pipeline of Rasa components is created and initialized. The DIET classifier object then is created with the pipeline.

Raises:

TypeError if training_data_path is not a string.

train_model(utterances: List[dialoguekit.core.utterance.Utterance] | None = None, labels: List[dialoguekit.core.intent.Intent] | None = None) None

Trains a model based on a set of labeled utterances.

If no utterances or labels are provided ‘training_data_path’ in the init is used for training the model. The utterances and labels are used for creating a rasa nlu document which is used for the training.

Parameters:
  • utterances – List of Utterance instances.

  • labels – List of associated intent labels.

classify_intent(utterance: dialoguekit.core.utterance.Utterance) dialoguekit.core.intent.Intent

Classifies the intent of an utterance.

The utterance is transformed to a Rasa Message before being classified. If the utterance has already been processed a cache is used. Since DIET also extracts entities the cache is used if the same Classifier object is used.

Parameters:

utterance – An utterance.

Returns:

Predicted intent.

Return type:

Intent

get_annotations(utterance: dialoguekit.core.utterance.Utterance) List[dialoguekit.core.slot_value_annotation.SlotValueAnnotation]

Extracts entities using rasa DIET classifier.

Extracts entities using rasa DIET. Since this model does both intent classification and entity extraction, the cache is used if the same Utterance has been processes before.

Parameters:

utterance – User utterance.

Returns:

List of extracted entities.

create_component(component_class: Type[rasa.engine.graph.GraphComponent], config: Dict[Text, Any], idx: int, model_storage: rasa.engine.storage.local_model_storage.LocalModelStorage) rasa.engine.graph.GraphComponent

Creates a Rasa pipeline component.

Parameters:
  • component_class – Class of the component.

  • config – Component configuration.

  • idx – Id of component in pipeline.

  • model_storage – Pipeline component storage.

Returns:

The pipeline component.

process_utterance(utterance: dialoguekit.core.utterance.Utterance) None

Processes utterance and adds result to the cache.

If it is the first time this utterance is processed it is added to the cache. Next time the same utterance is processed it is skipped, as its processing result is in the cache.

Parameters:

utterance – Agent or User Utterance.

process_message(loaded_pipeline: List[rasa.engine.graph.GraphComponent], message: rasa.shared.nlu.training_data.message.Message) rasa.shared.nlu.training_data.message.Message

Processes a Rasa Message through a pipeline.

Parameters:
  • loaded_pipeline – Rasa pipeline.

  • message – Rasa message.

Returns:

Processed message with data.

abstract save_model(file_path: str) None

Saves the trained model to a file.

Parameters:

file_path – File path.

Raises:

NotImplementedError – If not implemented in derived class.

abstract load_model(file_path: str) None

Loads a model from a file.

Parameters:

file_path – File path.

Raises:

NotImplementedError – If not implemented in derived class.