在训练文本模型期间,您将切换嵌入矩阵,以便将索引映射到向量。因此,嵌入层的输入是索引而不是向量本身?我问我在恢复元文件时在预测过程中会如何发生?保存模型时,嵌入词典位于哪个文件中?
此外,在预测期间如何处理没有索引的看不见的单词?
self.embedding_mat=embedding_mat
with tf.variable_scope('embeddings'):
word_embeddings = tf.constant(self.embedding_mat, dtype=tf.float32, name="embedding")
self.embedded_x1 = tf.nn.embedding_lookup(word_embeddings, self.x1)
self.embedded_x2 = tf.nn.embedding_lookup(word_embeddings, self.x2)
graph = tf.Graph()
with graph.as_default():
sess = tf.Session()
checkpoint = tf.train.latest_checkpoint('components/{}/{}/'.format(model_dir, model_name))
saver = tf.train.import_meta_graph(checkpoint + '.meta')
saver.restore(sess, checkpoint)
x1 = tf.get_collection('x1')[0]
x2 = tf.get_collection('x2')[0]
predictions = tf.get_collection('prediction')[0]