0

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?

exAres
  • 4,806
  • 16
  • 53
  • 95

1 Answers1

0

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)
keveman
  • 8,427
  • 1
  • 38
  • 46
  • Actually using `input_data = tf.placeholder(tf.float32, [batch_size, 1])` worked. I then had to reshape my input data from an array of length `50` to a `50X1` matrix. – exAres Jul 06 '16 at 19:56
  • Edited to account for `input_size`. Yes, in general, your input vector can be of arbitrary size. – keveman Jul 06 '16 at 19:59
  • Thanks! I think you will be able to help me further. Could you please take a look at: http://stackoverflow.com/questions/38233056/how-can-i-complete-following-gru-based-rnn-written-in-tensorflow – exAres Jul 06 '16 at 20:21