我正在构建一个基于seq2seq-class的翻译机。该类假定编码器和解码器部分使用不同的词汇表。因此,它还希望这两种方法的嵌入方式不同。
但是,我正在尝试在一种语言中使用它。因此,我希望这两个嵌入是一个。(背景是将外行的术语翻译成专家的术语,使用相同的语言)
目前相关代码为:
编码端:在EmbeddingWrapper()的python/ops/rnn_cell.py中:
with vs.variable_scope(scope or "EmbeddingWrapper"):
additional_info_size with vs.variable_scope(scope or type(self).__name__):
with ops.device("/cpu:0"):
embedding = vs.get_variable("embedding", [self._embedding_classes, self._embedding_size], initializer=initializer)
embedded = embedding_ops.embedding_lookup(embedding, array_ops.reshape(inputs, [-1]))解码器端:在embedding_rnn_decoder()的python/ops/seq2seq.py中:
with variable_scope.variable_scope(scope or "embedding_rnn_decoder"):
with ops.device("/cpu:0"):
embedding = variable_scope.get_variable("embedding", [num_symbols, embedding_size])
loop_function = _extract_sksk_argmax_and_embed(
embedding, output_projection,
update_embedding_for_previous) if feed_previous else None
emb_inp = (embedding_ops.embedding_lookup(embedding, i) for i in decoder_inputs)知道如何优雅地让这两个人使用相同的嵌入矩阵吗?
发布于 2016-09-10 03:53:35
您可以在调用创建第二个嵌入的函数时使用重用变量作用域。如果您使用具有相同名称的作用域并设置为reuse=True,则嵌入将被重用。有关sharing variables的文档是相关的。
https://stackoverflow.com/questions/39408828
复制相似问题