Version: 3.x

rasa.nlu.classifiers.diet_classifier

DIETClassifier Objects

@DefaultV1Recipe.register(
[
DefaultV1Recipe.ComponentType.INTENT_CLASSIFIER,
DefaultV1Recipe.ComponentType.ENTITY_EXTRACTOR,
],
is_trainable=True,
)
class DIETClassifier(GraphComponent, IntentClassifier, EntityExtractorMixin)

A multi-task model for intent classification and entity extraction.

DIET is Dual Intent and Entity Transformer. The architecture is based on a transformer which is shared for both tasks. A sequence of entity labels is predicted through a Conditional Random Field (CRF) tagging layer on top of the transformer output sequence corresponding to the input sequence of tokens. The transformer output for the __CLS__ token and intent labels are embedded into a single semantic vector space. We use the dot-product loss to maximize the similarity with the target label and minimize similarities with negative samples.

required_components

@classmethod
def required_components(cls) -> List[Type]

Components that should be included in the pipeline before this component.

get_default_config

@staticmethod
def get_default_config() -> Dict[Text, Any]

The component's default config (see parent class for full docstring).

__init__

def __init__(
config: Dict[Text, Any],
model_storage: ModelStorage,
resource: Resource,
execution_context: ExecutionContext,
index_label_id_mapping: Optional[Dict[int, Text]] = None,
entity_tag_specs: Optional[List[EntityTagSpec]] = None,
model: Optional[RasaModel] = None,
sparse_feature_sizes: Optional[Dict[Text, Dict[Text, List[int]]]] = None
) -> None

Declare instance variables with default values.

create

@classmethod
def create(cls, config: Dict[Text, Any], model_storage: ModelStorage,
resource: Resource,
execution_context: ExecutionContext) -> DIETClassifier

Creates a new untrained component (see parent class for full docstring).

label_key

@property
def label_key() -> Optional[Text]

Return key if intent classification is activated.

label_sub_key

@property
def label_sub_key() -> Optional[Text]

Return sub key if intent classification is activated.

preprocess_train_data

def preprocess_train_data(training_data: TrainingData) -> RasaModelData

Prepares data for training.

Performs sanity checks on training data, extracts encodings for labels.

train

def train(training_data: TrainingData) -> Resource

Train the embedding intent classifier on a data set.

process

def process(messages: List[Message]) -> List[Message]

Augments the message with intents, entities, and diagnostic data.

persist

def persist() -> None

Persist this model into the passed directory.

load

@classmethod
def load(cls: Type[DIETClassifierT], config: Dict[Text, Any],
model_storage: ModelStorage, resource: Resource,
execution_context: ExecutionContext,
**kwargs: Any) -> DIETClassifierT

Loads a policy from the storage (see parent class for full docstring).

DIET Objects

class DIET(TransformerRasaModel)

batch_loss

def batch_loss(
batch_in: Union[Tuple[tf.Tensor, ...], Tuple[np.ndarray,
...]]) -> tf.Tensor

Calculates the loss for the given batch.

Arguments:

  • batch_in - The batch.

Returns:

The loss of the given batch.

prepare_for_predict

def prepare_for_predict() -> None

Prepares the model for prediction.

batch_predict

def batch_predict(
batch_in: Union[Tuple[tf.Tensor, ...], Tuple[np.ndarray, ...]]
) -> Dict[Text, tf.Tensor]

Predicts the output of the given batch.

Arguments:

  • batch_in - The batch.

Returns:

The output to predict.