Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tensorflow 如何在一层中使用多个RNN单元?_Tensorflow - Fatal编程技术网

Tensorflow 如何在一层中使用多个RNN单元?

Tensorflow 如何在一层中使用多个RNN单元?,tensorflow,Tensorflow,我想在我的模型中使用多个GRU单元。但不是以堆栈格式! 也就是说,例如,有两种类型的输入,即单词序列和词性特征。我想将它们分别输入两个独立的GRU单元,然后使用输出继续工作。当我自定义序列模型时,我必须在每个时间步获得2个输出。 现在我的代码是: def create_cell(self, Scope, cell_size): with tf.variable_scope(Scope, reuse = None): if not self.forward_only and

我想在我的模型中使用多个GRU单元。但不是以堆栈格式! 也就是说,例如,有两种类型的输入,即单词序列和词性特征。我想将它们分别输入两个独立的GRU单元,然后使用输出继续工作。当我自定义序列模型时,我必须在每个时间步获得2个输出。 现在我的代码是:

def create_cell(self, Scope, cell_size):
    with tf.variable_scope(Scope, reuse = None):
        if not self.forward_only and self.dropout_keep_prob < 1.0:
            single_cell = GRUCell(cell_size)
            single_cell = DropoutWrapper(single_cell, input_keep_prob = dropout_keep_prob, output_keep_prob = dropout_keep_prob)
        else:
            single_cell = GRUCell(cell_size)
    return single_cell
我使用dict为不同类型的输入存储不同的GRU

for step in range(self.max_sequence_length):
    for i in range(len(types)):
        type = types[i]
        curgru = grus[type]
        out, state = curgru(input[:,step,:], states[type])
        states[type] = state
但是,第一次执行循环(我的意思是I==0)时,它就工作了。然后,当i==1时,
out的行,state=curgru(输入[:,步骤,:],states[type])
引发一个错误:
gru单元/门/内核已存在,不允许。您的意思是在VarScope中设置reuse=True吗?

但我不想在不同类型的输入之间重用GRU单元。那么我能做些什么来解决这个问题呢?

我已经解决了它==。GRUCell的函数调用()有一个参数“scope”,我给它分配了与curgru相同的变量scope

for step in range(self.max_sequence_length):
    for i in range(len(types)):
        type = types[i]
        curgru = grus[type]
        out, state = curgru(input[:,step,:], states[type])
        states[type] = state