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,ValueError:这两种结构不';没有相同的嵌套结构 将tensorflow导入为tf vocab_num=4000 单词尺寸=300 问题编码=无 答案_num=1000 普通尺寸=256 内存尺寸=256 问题_encode=tf.placeholder( tf.int64,[None,None],'question_encode') 使用tf.variable_作用域(“嵌入”): 嵌入矩阵=tf.get\u变量( “嵌入矩阵”, [vocab_num,word_dim],正则化器=tf.nn.l2_损失) 问题嵌入=tf.nn.embedding\u查找( 嵌入矩阵,问题编码,name='word\u嵌入') 打印(“问题嵌入”,问题嵌入) shape=tf.shape(问题编码) 批次大小=形状[0] 问题长度=tf.常数(15) time=tf.constant(0,name='time') 最大长度=tf.常数(20) q_cell=tf.nn.rnn_cell.LSTMCell(单词) q_状态=q_单元格。零_状态(批量大小,tf.float32) word\u embed\u W=tf.get\u变量('word\u embed\u W',[word\u dim,common\u dim],正则化器=tf.nn.l2\u loss) word\u embed\u b=tf.get\u变量('word\u embed\u b',[common\u dim]) 单词嵌入=问题嵌入[:,时间] out=tf.ones((1256)) 时间=tf常数(0) out=tf.zero((最大长度-问题长度,256)) 定义一个步骤(时间、q状态、单词列表): “”“模型的一个时间步。”“” 单词嵌入=问题嵌入[:,时间] 使用tf.variable_scope('lstm_q'): q_输出,q_状态=q_单元(字嵌入,q_状态) 使用tf.name_scope('transform_w'): word=tf.nn.xw\u加上( 单词嵌入,单词嵌入W,单词嵌入b) word=tf.nn.tanh(word) 单词列表=tf.concat([单词列表,单词],轴=0) 返回时间+1,q_状态,单词列表 #主回路 时间,q_状态,out_u=tf.while_循环( cond=λ时间,*\时间_Tensorflow_Deep Learning_Nlp - Fatal编程技术网

Tensorflow,ValueError:这两种结构不';没有相同的嵌套结构 将tensorflow导入为tf vocab_num=4000 单词尺寸=300 问题编码=无 答案_num=1000 普通尺寸=256 内存尺寸=256 问题_encode=tf.placeholder( tf.int64,[None,None],'question_encode') 使用tf.variable_作用域(“嵌入”): 嵌入矩阵=tf.get\u变量( “嵌入矩阵”, [vocab_num,word_dim],正则化器=tf.nn.l2_损失) 问题嵌入=tf.nn.embedding\u查找( 嵌入矩阵,问题编码,name='word\u嵌入') 打印(“问题嵌入”,问题嵌入) shape=tf.shape(问题编码) 批次大小=形状[0] 问题长度=tf.常数(15) time=tf.constant(0,name='time') 最大长度=tf.常数(20) q_cell=tf.nn.rnn_cell.LSTMCell(单词) q_状态=q_单元格。零_状态(批量大小,tf.float32) word\u embed\u W=tf.get\u变量('word\u embed\u W',[word\u dim,common\u dim],正则化器=tf.nn.l2\u loss) word\u embed\u b=tf.get\u变量('word\u embed\u b',[common\u dim]) 单词嵌入=问题嵌入[:,时间] out=tf.ones((1256)) 时间=tf常数(0) out=tf.zero((最大长度-问题长度,256)) 定义一个步骤(时间、q状态、单词列表): “”“模型的一个时间步。”“” 单词嵌入=问题嵌入[:,时间] 使用tf.variable_scope('lstm_q'): q_输出,q_状态=q_单元(字嵌入,q_状态) 使用tf.name_scope('transform_w'): word=tf.nn.xw\u加上( 单词嵌入,单词嵌入W,单词嵌入b) word=tf.nn.tanh(word) 单词列表=tf.concat([单词列表,单词],轴=0) 返回时间+1,q_状态,单词列表 #主回路 时间,q_状态,out_u=tf.while_循环( cond=λ时间,*\时间

Tensorflow,ValueError:这两种结构不';没有相同的嵌套结构 将tensorflow导入为tf vocab_num=4000 单词尺寸=300 问题编码=无 答案_num=1000 普通尺寸=256 内存尺寸=256 问题_encode=tf.placeholder( tf.int64,[None,None],'question_encode') 使用tf.variable_作用域(“嵌入”): 嵌入矩阵=tf.get\u变量( “嵌入矩阵”, [vocab_num,word_dim],正则化器=tf.nn.l2_损失) 问题嵌入=tf.nn.embedding\u查找( 嵌入矩阵,问题编码,name='word\u嵌入') 打印(“问题嵌入”,问题嵌入) shape=tf.shape(问题编码) 批次大小=形状[0] 问题长度=tf.常数(15) time=tf.constant(0,name='time') 最大长度=tf.常数(20) q_cell=tf.nn.rnn_cell.LSTMCell(单词) q_状态=q_单元格。零_状态(批量大小,tf.float32) word\u embed\u W=tf.get\u变量('word\u embed\u W',[word\u dim,common\u dim],正则化器=tf.nn.l2\u loss) word\u embed\u b=tf.get\u变量('word\u embed\u b',[common\u dim]) 单词嵌入=问题嵌入[:,时间] out=tf.ones((1256)) 时间=tf常数(0) out=tf.zero((最大长度-问题长度,256)) 定义一个步骤(时间、q状态、单词列表): “”“模型的一个时间步。”“” 单词嵌入=问题嵌入[:,时间] 使用tf.variable_scope('lstm_q'): q_输出,q_状态=q_单元(字嵌入,q_状态) 使用tf.name_scope('transform_w'): word=tf.nn.xw\u加上( 单词嵌入,单词嵌入W,单词嵌入b) word=tf.nn.tanh(word) 单词列表=tf.concat([单词列表,单词],轴=0) 返回时间+1,q_状态,单词列表 #主回路 时间,q_状态,out_u=tf.while_循环( cond=λ时间,*\时间,tensorflow,deep-learning,nlp,Tensorflow,Deep Learning,Nlp,出现问题时: import tensorflow as tf vocab_num = 4000 word_dim = 300 question_encode = None answer_num = 1000 common_dim = 256 memory_dim = 256 question_encode = tf.placeholder( tf.int64, [None, None], 'question_encode') with tf.variable_scope('embed

出现问题时:

import tensorflow as tf

vocab_num = 4000
word_dim = 300
question_encode = None
answer_num = 1000
common_dim = 256
memory_dim = 256

question_encode = tf.placeholder(
    tf.int64, [None, None], 'question_encode')
with tf.variable_scope('embedding'):
    embedding_matrix = tf.get_variable(
        'embedding_matrix',
        [vocab_num, word_dim], regularizer=tf.nn.l2_loss)
    question_embedding = tf.nn.embedding_lookup(
        embedding_matrix, question_encode, name='word_embedding')
    print('question_embedding', question_embedding)

shape = tf.shape(question_encode)
batch_size = shape[0]
question_length = tf.constant(15)
time = tf.constant(0, name='time')
max_length = tf.constant(20)
q_cell = tf.nn.rnn_cell.LSTMCell(word_dim)
q_state = q_cell.zero_state(batch_size, tf.float32)

word_embed_W = tf.get_variable('word_embed_W', [word_dim, common_dim], regularizer=tf.nn.l2_loss)
word_embed_b = tf.get_variable('word_embed_b', [common_dim])
word_embedding = question_embedding[:, time]
out_ = tf.ones((1, 256))

time = tf.constant(0)
out = tf.zeros((max_length - question_length, 256))

def _one_step(time, q_state, word_list):
    """One time step of model."""
    word_embedding = question_embedding[:, time]
    with tf.variable_scope('lstm_q'):
        q_output, q_state = q_cell(word_embedding, q_state)
    with tf.name_scope('transform_w'):
        word = tf.nn.xw_plus_b(
            word_embedding, word_embed_W, word_embed_b)
        word = tf.nn.tanh(word)
    word_list = tf.concat([word_list, word], axis=0)

    return time + 1, q_state, word_list

# main loop
time, q_state, out_ = tf.while_loop(
    cond=lambda time, *_: time < question_length,
    body=_one_step,
    loop_vars=[time, q_state, out_],
    shape_invariants=[time.get_shape(), tf.TensorShape([None, 256])]
)

word_list = tf.concat([out_, out], axis=0)
sess = tf.Session()
sess.run(tf.global_variables_initializer())
res = sess.run(out)

ValueError:这两个结构没有相同的嵌套结构。
第一个结构:type=list str=[,LSTMStateTuple(c=,h=),]
第二种结构:type=list str=[TensorShape([]),TensorShape([Dimension(None),Dimension(256)])]
我试图实现的是一个矩阵,每个单词拼接在一起,但随着q_状态的改变,结果证明是错误的

但是我试过很多方法都是错误的,所以我希望得到你的帮助 但是我试过很多方法都是错误的,所以我希望得到你的帮助
但是我试过很多方法都是错误的,所以我希望得到你的帮助。你输入的变量是三个,而形状不变量是两个。因此,错误显示两个结构没有相同的嵌套结构。您只需要添加
q\u state
的结构


ValueError: The two structures don't have the same nested structure.

First structure: type=list str=[<tf.Tensor 'Const_2:0' shape=() dtype=int32>, LSTMStateTuple(c=<tf.Tensor 'LSTMCellZeroState/zeros:0' shape=(?, 300) dtype=float32>, h=<tf.Tensor 'LSTMCellZeroState/zeros_1:0' shape=(?, 300) dtype=float32>), <tf.Tensor 'ones:0' shape=(1, 256) dtype=float32>]

Second structure: type=list str=[TensorShape([]), TensorShape([Dimension(None), Dimension(256)])]
#主回路
时间,q_状态,out_u=tf.while_循环(
cond=λ时间,*\时间<问题长度,
正文=_一步,
循环变量=[时间,q状态,输出],
shape_不变量=[time.get_shape()
,tf.nn.rnn_cell.LSTMStateTuple(tf.TensorShape([None,300]),tf.TensorShape([None,300]))
,tf.TensorShape([None,256])]
)

@YangBinWei很乐意帮忙。如果答案解决了你的问题,别忘了接受它。
# main loop
time, q_state, out_ = tf.while_loop(
    cond=lambda time, *_: time < question_length,
    body=_one_step,
    loop_vars=[time, q_state, out_],
    shape_invariants=[time.get_shape()
        ,tf.nn.rnn_cell.LSTMStateTuple(tf.TensorShape([None, 300]),tf.TensorShape([None, 300]))
        ,tf.TensorShape([None, 256])]
)