simple_intent_classifier#

class besser.bot.nlp.intent_classifier.simple_intent_classifier.SimpleIntentClassifier(nlp_engine, state)[source]#

Bases: IntentClassifier

A Simple Intent Classifier.

It works using a simple Keras Neural Network (the prediction model) for text classification.

Parameters:
  • nlp_engine (NLPEngine) – the NLPEngine that handles the NLP processes of the bot

  • state (State) – the state the intent classifier belongs to

_tokenizer#

The intent classifier tokenizer

Type:

Tokenizer

_model#

The intent classifier language model

Type:

Sequential

num_words#

Max num of words to keep in the index of words

Type:

int

lower#

Weather to transform the sentences to lowercase or not

Type:

bool

oov_token#

Token for the out of vocabulary words

Type:

str

num_epochs#

Number of epochs to be run during training

Type:

int

embedding_dim#

Number of embedding dimensions to be used when embedding the words

Type:

int

input_max_num_tokens#

Max length for the vector representing a sentence

Type:

int

discard_oov_sentences#

Weather to automatically assign zero probabilities to sentences with all tokens being oov ones or not

Type:

bool

check_exact_prediction_match#

Whether to check for exact match between the sentence to predict and one of the training sentences or not

Type:

bool

activation_last_layer#

The activation function of the last layer

Type:

str

activation_hidden_layers#

The activation function of the hidden layers

Type:

str

lr#

Learning rate for the optimizer

Type:

float

__intent_label_mapping#

A mapping of the intent labels and their corresponding intents.

__total_labels_training_sentences#

The label (identifying the intent) of all training sentences.

__total_training_sentences#

All the processed training sentences of all intents of the intent classifier’s state.

__total_training_sequences#

All the training sequences of all intents of the intent classifier’s state.

_abc_impl = <_abc._abc_data object>#
predict(message)[source]#

Predict the intent of a given message.

Instead of returning only the intent with the highest likelihood, return all predictions. Predictions include not only the intent scores but other information extracted from the message.

Parameters:

message (str) – the message to predict the intent

Returns:

the list of predictions made by the intent classifier.

Return type:

list[IntentClassifierPrediction]

train()[source]#

Train the intent classifier.