tensorflow 的 GRUCell 中输入和隐藏状态的大小应该是多少 (python)?

What should be the size of input and hidden state in GRUCell of tensorflow (python)?

我是 tensorflow 新手(1 天经验)。

我正在尝试按照小代码创建一个简单的基于 GRU 的 RNN,单层隐藏大小为 100,如下所示:

import pickle
import numpy as np
import pandas as pd
import tensorflow as tf

# parameters
batch_size = 50
hidden_size = 100

# create network graph
input_data = tf.placeholder(tf.int32, [batch_size])
output_data = tf.placeholder(tf.int32, [batch_size])

cell = tf.nn.rnn_cell.GRUCell(hidden_size)

initial_state = cell.zero_state(batch_size, tf.float32)

hidden_state = initial_state

output_of_cell, hidden_state = cell(input_data, hidden_state)

但是最后一行出现以下错误(即调用 cell()

Linear is expecting 2D arguments: [[50], [50, 100]]

我做错了什么?

GRUCell 的调用运算符的输入应为 tf.float32 类型的二维张量。以下应该有效:

input_data = tf.placeholder(tf.float32, [batch_size, input_size])

cell = tf.nn.rnn_cell.GRUCell(hidden_size)

initial_state = cell.zero_state(batch_size, tf.float32)

hidden_state = initial_state

output_of_cell, hidden_state = cell(input_data, hidden_state)