在seq2seq中对编码器和解码器使用相同的嵌入

2024-09-30 04:27:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在构建一个基于seq2seq类的翻译机器。该类假定编码器和解码器部分使用不同的词汇表。因此,它也期望二者具有不同的嵌入。在

但是,我试图在一种语言中使用这个。因此,我希望这两个嵌入是一个。(背景是用同一种语言将外行术语翻译成专家术语)

目前相关代码为:

编码器侧: 在python/ops/rnn中_细胞.py在EmbeddingWrapper()中:

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]))

解码器侧: 在python/ops/seq2中顺序图在嵌入_rnn_decoder()中:

^{pr2}$

你知道如何优雅地让这两个使用相同的嵌入矩阵吗?在


Tags: orself语言sizewithembedding编码器解码器
1条回答
网友
1楼 · 发布于 2024-09-30 04:27:13

在调用创建第二个嵌入的函数时,可以使用可重用变量范围。如果使用具有相同名称的作用域并设置reuse=True,则将重用嵌入。关于sharing variables的文档是相关的。在

相关问题 更多 >

    热门问题