code/char_model.py
def add_embedding_layer(self, emb_matrix):
        """
        Adds word embedding layer to the graph.

        Inputs:
          emb_matrix: shape (400002, embedding_size).
            The GloVe vectors, plus vectors for PAD and UNK.
        """
        with vs.variable_scope("embeddings"):

            # Note: the embedding matrix is a tf.constant which means it's not a trainable parameter
            embedding_matrix = tf.constant(emb_matrix, dtype=tf.float32, name="emb_matrix") # shape (400002, embedding_size)

            # Get the word embeddings for the context and question,
            # using the placeholders self.context_ids and self.qn_ids
            self.context_embs = embedding_ops.embedding_lookup(embedding_matrix, self.context_ids) # shape (batch_size, context_len, embedding_size)
            self.qn_embs = embedding_ops.embedding_lookup(embedding_matrix, self.qn_ids) # shape (batch_size, question_len, embedding_size)

            # Chars
            char_embedding_matrix = tf.constant(self.char_emb_matrix, dtype=tf.float32, name="char_emb_matrix")  # shape (96, char_embedding_size)
            self.char_emb_matrix = None # release memory, hopefully
            self.context_char_embs = tf.reshape(embedding_ops.embedding_lookup(char_embedding_matrix, self.context_char_ids),
                                                [-1, self.FLAGS.char_limit, self.FLAGS.char_embedding_size]) # shape (batch_size * context_len, char_limit, embedding_size)
            self.qn_char_embs = tf.reshape(embedding_ops.embedding_lookup(char_embedding_matrix, self.qn_char_ids),
                                                [-1, self.FLAGS.char_limit, self.FLAGS.char_embedding_size]) # shape (batch_size * question_len, char_limit, embedding_size)

        Adds word embedding layer to the graph.

        Inputs:
          emb_matrix: shape (400002, embedding_size).
            The GloVe vectors, plus vectors for PAD and UNK.
        
Adds word embedding layer to the graph.
Adds word embedding layer to the graph .
def add_embedding_layer(self, emb_matrix):
        with vs.variable_scope("embeddings"):
            embedding_matrix = tf.constant(emb_matrix, dtype=tf.float32, name="emb_matrix") 
            self.context_embs = embedding_ops.embedding_lookup(embedding_matrix, self.context_ids) 
            self.qn_embs = embedding_ops.embedding_lookup(embedding_matrix, self.qn_ids) 
            char_embedding_matrix = tf.constant(self.char_emb_matrix, dtype=tf.float32, name="char_emb_matrix")  
            self.char_emb_matrix = None 
            self.context_char_embs = tf.reshape(embedding_ops.embedding_lookup(char_embedding_matrix, self.context_char_ids),
                                                [-1, self.FLAGS.char_limit, self.FLAGS.char_embedding_size]) 
            self.qn_char_embs = tf.reshape(embedding_ops.embedding_lookup(char_embedding_matrix, self.qn_char_ids),
                                                [-1, self.FLAGS.char_limit, self.FLAGS.char_embedding_size]) 
def add_embedding_layer ( self , emb_matrix ) : with vs . variable_scope ( "embeddings" ) : embedding_matrix = tf . constant ( emb_matrix , dtype = tf . float32 , name = "emb_matrix" ) self . context_embs = embedding_ops . embedding_lookup ( embedding_matrix , self . context_ids ) self . qn_embs = embedding_ops . embedding_lookup ( embedding_matrix , self . qn_ids ) char_embedding_matrix = tf . constant ( self . char_emb_matrix , dtype = tf . float32 , name = "char_emb_matrix" ) self . char_emb_matrix = None self . context_char_embs = tf . reshape ( embedding_ops . embedding_lookup ( char_embedding_matrix , self . context_char_ids ) , [ - 1 , self . FLAGS . char_limit , self . FLAGS . char_embedding_size ] ) self . qn_char_embs = tf . reshape ( embedding_ops . embedding_lookup ( char_embedding_matrix , self . qn_char_ids ) , [ - 1 , self . FLAGS . char_limit , self . FLAGS . char_embedding_size ] )
Adds word embedding layer to the graph.
Adds word embedding layer to the graph .
"""
        Adds word embedding layer to the graph.

        Inputs:
          emb_matrix: shape (400002, embedding_size).
            The GloVe vectors, plus vectors for PAD and UNK.
        """ # Note: the embedding matrix is a tf.constant which means it's not a trainable parameter # shape (400002, embedding_size) # Get the word embeddings for the context and question, # using the placeholders self.context_ids and self.qn_ids # shape (batch_size, context_len, embedding_size) # shape (batch_size, question_len, embedding_size) # Chars # shape (96, char_embedding_size) # release memory, hopefully # shape (batch_size * context_len, char_limit, embedding_size) # shape (batch_size * question_len, char_limit, embedding_size)
self
emb_matrix