Bert-THUCNews icon indicating copy to clipboard operation
Bert-THUCNews copied to clipboard

输入格式不一致

Open xuanhui0129 opened this issue 5 years ago • 2 comments

您好,我在跑您的代码时出现 Cannot feed value of shape (30, 768) for Tensor 'input_x:0', which has shape '(?, 512, 768)', 我看您用到了双向RNN,但是用bert只表示了句向量,表示输入格式和定义的不一致,不知道您那是否有这个问题。

xuanhui0129 avatar May 15 '19 11:05 xuanhui0129

同问。。。请问作者在吗?

johnny0213 avatar Jun 08 '19 05:06 johnny0213

用下面的workaround,可以绕过上述错误。但是在运行中报别的错误。。。 :(

        [rows, cols] = x_batch.shape
        print('x_batch actual=', x_batch.shape)
        #如果rows<512,则扩充至512行:
        if rows < 512:
            delta = 512 - rows
            x_batch = np.r_[ x_batch, np.zeros([delta,768]) ]
            print('x_batch expansion=', x_batch.shape)

        #加上括号,[x_batch],符合input shape要求:
        feed_dict = feed_data([x_batch], y_batch, config.dropout_keep_prob) 

johnny0213 avatar Jun 08 '19 07:06 johnny0213