deeppavlov.models.go_bot¶
-
class
deeppavlov.models.go_bot.go_bot.
GoalOrientedBot
(tokenizer: deeppavlov.core.models.component.Component, tracker: deeppavlov.models.go_bot.tracker.featurized_tracker.FeaturizedTracker, nlg_manager: deeppavlov.models.go_bot.nlg.nlg_manager_interface.NLGManagerInterface, save_path: str, hidden_size: int = 128, dropout_rate: float = 0.0, l2_reg_coef: float = 0.0, dense_size: int = None, attention_mechanism: dict = None, network_parameters: Optional[Dict[str, Any]] = None, load_path: str = None, word_vocab: deeppavlov.core.models.component.Component = None, bow_embedder: deeppavlov.core.models.component.Component = None, embedder: deeppavlov.core.models.component.Component = None, slot_filler: deeppavlov.core.models.component.Component = None, intent_classifier: deeppavlov.core.models.component.Component = None, database: deeppavlov.core.models.component.Component = None, use_action_mask: bool = False, debug: bool = False, **kwargs)[source]¶ The dialogue bot is based on https://arxiv.org/abs/1702.03274, which introduces Hybrid Code Networks that combine an RNN with domain-specific knowledge and system action templates.
The network handles dialogue policy management. Inputs features of an utterance and predicts label of a bot action (classification task).
An LSTM with a dense layer for input features and a dense layer for it’s output. Softmax is used as an output activation function.
- Parameters
tokenizer – one of tokenizers from deeppavlov.models.tokenizers module.
tracker – dialogue state tracker from deeppavlov.models.go_bot.tracker.
hidden_size – size of rnn hidden layer.
dropout_rate – probability of weights dropping out.
l2_reg_coef – l2 regularization weight (applied to input and output layer).
dense_size – rnn input size.
attention_mechanism –
describes attention applied to embeddings of input tokens.
type – type of attention mechanism, possible values are
'general'
,'bahdanau'
,'light_general'
,'light_bahdanau'
,'cs_general'
and'cs_bahdanau'
.hidden_size – attention hidden state size.
max_num_tokens – maximum number of input tokens.
depth – number of averages used in constrained attentions (
'cs_bahdanau'
or'cs_general'
).action_as_key – whether to use action from previous time step as key to attention.
intent_as_key – use utterance intents as attention key or not.
projected_align – whether to use output projection.
network_parameters – dictionary with network parameters (for compatibility with release 0.1.1, deprecated in the future)
word_vocab – vocabulary of input word tokens (
SimpleVocabulary
recommended).bow_embedder – instance of one-hot word encoder
BoWEmbedder
.embedder – one of embedders from deeppavlov.models.embedders module.
slot_filler – component that outputs slot values for a given utterance (
DstcSlotFillingNetwork
recommended).intent_classifier – component that outputs intents probability distribution for a given utterance (
KerasClassificationModel
recommended).database – database that will be used during inference to perform
api_call_action
actions and get'db_result'
result (Sqlite3Database
recommended).use_action_mask – if
True
, network output will be applied with a mask over allowed actions.debug – whether to display debug output.
-
extract_features_from_utterance_text
(text, tracker, keep_tracker_state=False) → deeppavlov.models.go_bot.dto.dataset_features.UtteranceFeatures[source]¶ Extract ML features for the input text and the respective tracker. Features are aggregated from the * NLU; * text BOW-encoding&embedding; * tracker memory.
- Parameters
text – the text to infer to
tracker – the tracker that tracks the dialogue from which the text is taken
keep_tracker_state – if True, the tracker state will not be updated during the prediction. Used to keep tracker’s state intact when predicting the action to perform right after the api call action is predicted and performed.
- Returns
the utterance features object containing the numpy-vectorized features extracted from the utterance
-
prepare_dialogue_training_data
(dialogue_utterances_contexts_info: List[dict], dialogue_utterances_responses_info: List[dict]) → deeppavlov.models.go_bot.dto.dataset_features.DialogueDataEntry[source]¶ Parse the passed dialogue information to the dialogue information object.
- Parameters
dialogue_utterances_contexts_info – the dictionary containing the dialogue utterances training information
dialogue_utterances_responses_info – the dictionary containing the dialogue utterances responses training information
- Returns
the dialogue data object containing the numpy-vectorized features and target extracted from the utterance data
-
prepare_dialogues_batches_training_data
(batch_dialogues_utterances_contexts_info: List[List[dict]], batch_dialogues_utterances_responses_info: List[List[dict]]) → deeppavlov.models.go_bot.dto.dataset_features.BatchDialoguesDataset[source]¶ Parse the passed dialogue information to the dialogue information object.
- Parameters
batch_dialogues_utterances_contexts_info – the dictionary containing the dialogue utterances training information
batch_dialogues_utterances_responses_info – the dictionary containing the dialogue utterances responses training information
- Returns
the dialogue data object containing the numpy-vectorized features and target extracted from the utterance data
-
prepare_utterance_training_data
(utterance_context_info_dict: dict, utterance_response_info_dict: dict) → deeppavlov.models.go_bot.dto.dataset_features.UtteranceDataEntry[source]¶ Parse the passed utterance information to the utterance information object.
- Parameters
utterance_context_info_dict – the dictionary containing the utterance training information
utterance_response_info_dict – the dictionary containing the utterance response training information
- Returns
the utterance data object containing the numpy-vectorized features and target extracted from the utterance data
-
class
deeppavlov.models.go_bot.policy.policy_network.
PolicyNetwork
(*args, **kwargs)[source]¶ the Policy Network is a ML model whose goal is to choose the right system response when in dialogue with user.
-
calc_attn_key
(nlu_response: deeppavlov.models.go_bot.nlu.dto.nlu_response.NLUResponse, tracker_knowledge: deeppavlov.models.go_bot.tracker.dto.dst_knowledge.DSTKnowledge)[source]¶ - Parameters
nlu_response – nlu analysis output, currently only intents data is used
tracker_knowledge – one-hot-encoded previous executed action
- Returns
vector representing an attention key
-
static
calc_attn_key_size
(shared_go_bot_params: deeppavlov.models.go_bot.dto.shared_gobot_params.SharedGoBotParams, action_as_key: bool, intent_as_key: bool) → int[source]¶ - Parameters
shared_go_bot_params – GO-bot hyperparams used in various parts of the pipeline
action_as_key – True if actions are part of attention keys
intent_as_key – True if intents are part of attention keys
- Returns
the calculated attention key shape of policy network
-
static
calc_input_size
(tokens_dims: deeppavlov.models.go_bot.nlu.tokens_vectorizer.TokensVectorRepresentationParams, shared_go_bot_params: deeppavlov.models.go_bot.dto.shared_gobot_params.SharedGoBotParams, attention_params: Optional[deeppavlov.models.go_bot.policy.dto.attn_params.GobotAttnParams]) → int[source]¶ - Parameters
tokens_dims – the tokens vectors dimensions
shared_go_bot_params – GO-bot hyperparams used in various parts of the pipeline
attention_params – the params of attention mechanism of the network for which input size is calculated
- Returns
the calculated input shape of policy network
-
-
class
deeppavlov.models.go_bot.nlg.nlg_manager_interface.
NLGManagerInterface
[source]¶