def __init__(self, opts, vocab, classes): # opts = tf.app.flags.FLAGS object self.opt = opts self.vocab = vocab self.classes = classes batch_size = self.opt.batch_size dropout_rate = self.opt.dropout_rate glove_embeddings = tf.constant(self.vocab.embeddings(), dtype=tf.float32) self.emb = tf.get_variable("embeddings", initializer=glove_embeddings) # create placeholders self.encoder_inputs = tf.placeholder(shape=[batch_size, None], dtype=tf.int32, name='encoder_inputs') self.encoder_input_lengths = tf.placeholder( shape=[batch_size], dtype=tf.int32, name='encoder_input_lengths') self.is_training = tf.placeholder(shape=[], dtype=tf.bool, name='is_training') self.target_labels = tf.placeholder(shape=[batch_size], dtype=tf.int32, name='target_labels') self.keep_prob = get_keep_prob(dropout_rate, self.is_training) self.graph_built = False self.train_op_added = False
def __init__(self, opts, vocab): # opts = tf.app.flags.FLAGS object self.opt = opts self.vocab = vocab batch_size = self.opt.batch_size dropout_rate = self.opt.dropout_rate self.emb = tf.get_variable( "embeddings", shape=[vocab.size(), vocab.emb_size()], initializer=tf.contrib.layers.xavier_initializer()) # create placeholders self.encoder_inputs = tf.placeholder(shape=[batch_size, None], dtype=tf.int32, name='encoder_inputs') self.encoder_input_lengths = tf.placeholder( shape=[batch_size], dtype=tf.int32, name='encoder_input_lengths') self.decoder_targets = tf.placeholder(shape=[batch_size, None], dtype=tf.int32, name='decoder_targets') self.decoder_target_lengths = tf.placeholder( shape=[batch_size], dtype=tf.int32, name='decoder_target_lengths') self.decoder_inputs = tf.placeholder(shape=[batch_size, None], dtype=tf.int32, name='decoder_inputs') self.decoder_input_lengths = tf.placeholder( shape=[batch_size], dtype=tf.int32, name='decoder_input_lengths') self.max_decoder_length = tf.placeholder(shape=[], dtype=tf.int32, name='max_decoder_length') self.max_encoder_length = tf.placeholder(shape=[], dtype=tf.int32, name='max_encoder_length') self.is_training = tf.placeholder(shape=[], dtype=tf.bool, name='is_training') self.memory_vectors = tf.placeholder(shape=[batch_size, None], dtype=tf.int32, name='memory_vectors') self.memory_vector_lengths = tf.placeholder( shape=[batch_size], dtype=tf.int32, name='memory_vector_lengths') self.oov_size = tf.placeholder(shape=[], dtype=tf.int32, name='oov_size') self.memory_vectors_full_vocab = tf.placeholder( shape=[batch_size, None], dtype=tf.int32, name='memory_vectors_full_vocab') self.memory_elmo_token_ids = tf.placeholder(shape=[batch_size, None], dtype=tf.int32) self.query_elmo_token_ids = tf.placeholder(shape=[batch_size, None], dtype=tf.int32) self.elmo_batcher = TokenBatcher(self.opt.elmo_vocab_file) self.keep_prob = get_keep_prob(dropout_rate, self.is_training) self.oov_dicts = Queue() self.graph_built = False self.train_op_added = False self.elmo_bilm = BidirectionalLanguageModel( self.opt.elmo_options_file, self.opt.elmo_weight_file, use_character_inputs=False, embedding_weight_file=self.opt.elmo_token_embedding_file)