Sangram - 10 months ago 290

Python Question

I am new to tensorflow (1 day of experience).

I am trying following small code to create a simple GRU based RNN with single layer and hidden size of 100 as follows:

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

But I am getting following error for last line (i.e. call to

`cell()`

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

What am I doing wrong?

Answer

Input to the `GRUCell`

's call operator are expected to be 2-D tensors with `tf.float32`

type. The following ought to work :

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