deeppavlov.models.seq2seq_go_bot

class deeppavlov.models.seq2seq_go_bot.bot.Seq2SeqGoalOrientedBot(network: deeppavlov.core.models.component.Component, source_vocab: deeppavlov.core.models.component.Component, target_vocab: deeppavlov.core.models.component.Component, start_of_sequence_token: str, end_of_sequence_token: str, debug: bool = False, save_path: str = None, **kwargs)[source]

A goal-oriented bot based on a sequence-to-sequence rnn. For implementation details see Seq2SeqGoalOrientedBotNetwork. Pretrained for KvretDatasetReader dataset.

Parameters:
  • network – object of Seq2SeqGoalOrientedBotNetwork class.
  • source_vocab – vocabulary of input tokens.
  • target_vocab – vocabulary of bot response tokens.
  • start_of_sequence_token – token that defines start of input sequence.
  • end_of_sequence_token – token that defines end of input sequence and start of output sequence.
  • debug – whether to display debug output.
  • **kwargs – parameters passed to parent NNModel class.
class deeppavlov.models.seq2seq_go_bot.network.Seq2SeqGoalOrientedBotNetwork(hidden_size: int, source_vocab_size: int, target_vocab_size: int, target_start_of_sequence_index: int, target_end_of_sequence_index: int, learning_rate: float, **kwargs)[source]

The GoalOrientedBotNetwork is a recurrent network that encodes user utterance and generates response in a sequence-to-sequence manner.

For network architecture is similar to https://arxiv.org/abs/1705.05414 .

Parameters:
  • hidden_size – RNN hidden layer size.
  • target_start_of_sequence_index – index of a start of sequence token during decoding.
  • target_end_of_sequence_index – index of an end of sequence token during decoding.
  • source_vocab_size – size of a vocabulary of encoder tokens.
  • target_vocab_size – size of a vocabulary of decoder tokens.
  • learning_rate – training learning rate.
  • **kwargs – parameters passed to a parent TFModel class.
load(*args, **kwargs)[source]

Load model parameters from self.load_path

save(*args, **kwargs)[source]

Save model parameters to self.save_path

class deeppavlov.models.seq2seq_go_bot.kb.KnowledgeBase(save_path: str, load_path: str = None, tokenizer: Callable = None, *args, **kwargs)[source]

A custom dictionary that encodes knowledge facts from KvretDatasetReader data.

Example

>>> from models.seq2seq_go_bot.kb import KnowledgeBase
>>> kb = KnowledgeBase(save_path="kb.json", load_path="kb.json")
>>> kb.fit(['person1'], [['name', 'hair', 'eyes']], [[{'name': 'Sasha', 'hair': 'long dark', 'eyes': 'light blue '}]])

>>> kb(['person1'])
[[('sasha_hair', 'long dark'), ('sasha_eyes', 'light blue ')]]

>>> kb(['person_that_doesnt_exist'])
[[]]
Parameters:
  • save_path – path to save the dictionary with knowledge.
  • load_path – path to load the json with knowledge.
  • tokenizer – tokenizer used to split entity values into tokens.
  • **kwargs – parameters passed to parent Estimator.
class deeppavlov.models.seq2seq_go_bot.kb.KnowledgeBaseEntityNormalizer(kb: deeppavlov.models.seq2seq_go_bot.kb.KnowledgeBase, denormalize: bool = False, **kwargs)[source]

Uses instance of KnowledgeBase to normalize or to undo normalization of entities in the input utterance.

To normalize is to substitute all mentions of database entities with their normalized form.

To undo normalization is to substitute all mentions of database normalized entities with their original form.

Example

>>> from models.seq2seq_go_bot.kb import KnowledgeBase
>>> kb = KnowledgeBase(save_path="kb.json", load_path="kb.json")
>>> kb.fit(['person1'], [['name', 'hair', 'eyes']], [[{'name': 'Sasha', 'hair': 'long dark', 'eyes': 'light blue '}]])
>>> kb(['person1'])
[[('sasha_hair', 'long dark'), ('sasha_eyes', 'light blue ')]]

>>> from models.seq2seq_go_bot.kb import KnowledgeBaseEntityNormalizer
>>> normalizer = KnowledgeBaseEntityNormalizer(kb=kb, denormalize=False)
>>> normalizer(['person1'], [["some", "guy", "with", "long", "dark", "hair", "said", "hi"]])
[['some', 'guy', 'with', 'sasha_hair', 'hair', 'said', 'hi']]

>>> denormalizer = KnowledgeBaseEntityNormalizer(kb=kb, denormalize=True)
>>> denormalizer(['person1'], [['some', 'guy', 'with', 'sasha_hair', 'hair', 'said', 'hi']])
[['some', 'guy', 'with', 'long', 'dark', 'hair', 'said', 'hi']]
Parameters:
  • kb – knowledge base of type KnowledgeBase.
  • denormalize – flag indicates whether to normalize or to undo normalization (“denormalize”).
  • **kwargs – parameters passed to parent Component class.