tatk.dst.mdbt package¶
Submodules¶
tatk.dst.mdbt.mdbt module¶
-
class
tatk.dst.mdbt.mdbt.
MDBT
(ontology_vectors, ontology, slots, data_dir)¶ Bases:
tatk.dst.dst.DST
A multi-domain belief tracker, adopted from https://github.com/osmanio2/multi-domain-belief-tracking.
-
__init__
(ontology_vectors, ontology, slots, data_dir)¶ Initialize self. See help(type(self)) for accurate signature.
-
detect_requestable_slots
(observation)¶
-
init_session
()¶ Init the class variables for a new session.
-
normalize_history
(history)¶ Replace zero-length history.
-
restore
()¶
-
update
(user_act=None)¶ Update the dialog state.
-
update_batch
(batch_action)¶
-
tatk.dst.mdbt.mdbt_util module¶
-
class
tatk.dst.mdbt.mdbt_util.
GRU
(W_h, U_h, M_h, W_m, U_m, label_size, reuse=None, binary_output=False)¶ Bases:
tensorflow.python.ops.rnn_cell_impl.RNNCell
Create a Gated Recurrent unit to unroll the network through time for combining the current and previous belief states
-
__init__
(W_h, U_h, M_h, W_m, U_m, label_size, reuse=None, binary_output=False)¶
-
property
output_size
¶ Integer or TensorShape: size of outputs produced by this cell.
-
property
state_size
¶ size(s) of state(s) used by this cell.
It can be represented by an Integer, a TensorShape or a tuple of Integers or TensorShapes.
-
-
tatk.dst.mdbt.mdbt_util.
define_CNN_model
(utter, num_filters=300, name='r')¶ Better code for defining the CNN model.
-
tatk.dst.mdbt.mdbt_util.
evaluate_model
(sess, model_variables, val_data, summary, batch_id, i)¶ Evaluate the model against validation set
- Parameters
sess – training session
model_variables – all model input variables
val_data – validation data
summary – For tensorboard
batch_id – where we are in the training data
i – the index of the validation data to load
- Returns
evaluation accuracy and the summary
-
tatk.dst.mdbt.mdbt_util.
generate_batch
(dialogues, batch_no, batch_size, ontology_size)¶ Generate examples for minibatch training
- Parameters
dialogues – list(num of turns, user_input vectors, system_response vectors, labels)
batch_no – where we are in the training data
batch_size – number of dialogues to generate
ontology_size – no_slots
- Returns
list(user_input, system_response, labels, user_sentence_length, system_sentence_length, number of turns)
-
tatk.dst.mdbt.mdbt_util.
get_available_devs
()¶
-
tatk.dst.mdbt.mdbt_util.
get_metrics
(predictions, true_predictions, no_turns, mask, num_slots)¶
-
tatk.dst.mdbt.mdbt_util.
load_ontology
(url, word_vectors)¶ Load the ontology from a file
- Parameters
url – to the ontology
word_vectors – dictionary of the word embeddings [words, vector_dimension]
- Returns
list([domain-slot-value]), [no_slots, vector_dimension]
-
tatk.dst.mdbt.mdbt_util.
load_word_vectors
(url)¶ Load the word embeddings from the url
- Parameters
url – to the word vectors
- Returns
dict of word and vector values
-
tatk.dst.mdbt.mdbt_util.
load_woz_data
(data, word_vectors, ontology, url=True)¶ Load the woz3 data and extract feature vectors
- Parameters
data – the data to load
word_vectors – word embeddings
ontology – list of domain-slot-value
url – Is the data coming from a url, default true
- Returns
list(num of turns, user_input vectors, system_response vectors, labels)
-
tatk.dst.mdbt.mdbt_util.
load_woz_data_new
(data, word_vectors, ontology, url=False)¶ Ported from load_woz_data, using tatk.util.dataloader pkg
- Parameters
data – the data to load
word_vectors – word embeddings
ontology – list of domain-slot-value
url – Is the data coming from a url, default true
- Returns
list(num of turns, user_input vectors, system_response vectors, labels)
-
tatk.dst.mdbt.mdbt_util.
lstm_model
(text_input, utterance_length, num_hidden, name, net_type, bidir)¶ Define an Lstm model that will run across the user input and system act
- Parameters
text_input – [batch_size, max_num_turns, max_utterance_size, vector_dimension]
utterance_length – number words in every utterance [batch_size, max_num_turns, 1]
num_hidden – – int –
name – The name of lstm network
net_type – type of the network (“lstm” or “gru” or “rnn”)
bidir – use a bidirectional network – bool –
- Returns
output at each state [batch_size, max_num_turns, max_utterance_size, num_hidden], output of the final state [batch_size, max_num_turns, num_hidden]
-
tatk.dst.mdbt.mdbt_util.
model_definition
(ontology, num_slots, slots, num_hidden=None, net_type=None, bidir=None, test=False, dev=None)¶ Create neural belief tracker model that is defined in my notes. It consists of encoding the user and system input, then use the ontology to decode the encoder in manner that detects if a domain-slot-value class is mentioned
- Parameters
ontology – numpy array of the embedded vectors of the ontology [num_slots, 3*vector_dimension]
num_slots – number of ontology classes –int–
slots – indices of the values of each slot list of lists of ints
num_hidden – Number of hidden units or dimension of the hidden space
net_type – The type of the encoder network cnn, lstm, gru, rnn …etc
bidir – For recurrent networks should it be bidirectional
test – This is testing mode (no back-propagation)
dev – Device to run the model on (cpu or gpu)
- Returns
All input variable/placeholders output metrics (precision, recall, f1-score) and trainer
-
tatk.dst.mdbt.mdbt_util.
normalise_word_vectors
(word_vectors, norm=1.0)¶ This method normalises the collection of word vectors provided in the word_vectors dictionary.
-
tatk.dst.mdbt.mdbt_util.
process_booking
(ontolog_term, usr_input, previous_terms)¶
-
tatk.dst.mdbt.mdbt_util.
process_history
(sessions, word_vectors, ontology)¶ Load the woz3 data and extract feature vectors
- Parameters
data – the data to load
word_vectors – word embeddings
ontology – list of domain-slot-value
url – Is the data coming from a url, default true
- Returns
list(num of turns, user_input vectors, system_response vectors, labels)
-
tatk.dst.mdbt.mdbt_util.
process_text
(text, word_vectors, ontology=None, print_mode=False)¶ Process a line/sentence converting words to feature vectors
- Parameters
text – sentence
word_vectors – word embeddings
ontology – The ontology to do exact matching
print_mode – Log the cases where the word is not in the pre-trained word vectors
- Returns
[length of sentence, 300]
-
tatk.dst.mdbt.mdbt_util.
process_turn
(turn, word_vectors, ontology)¶ Process a single turn extracting and processing user text, system response and labels
- Parameters
turn – dict
word_vectors – word embeddings
ontology – list(domain-slot-value)
- Returns
([utterance length, 300], [utterance length, 300], [no_slots])
-
tatk.dst.mdbt.mdbt_util.
track_dialogue
(data, ontology, predictions, y)¶
-
tatk.dst.mdbt.mdbt_util.
xavier_vector
(word, D=300)¶ Returns a D-dimensional vector for the word.
We hash the word to always get the same vector for the given word.