I am trying to construct a custom estimator for my ML Engine package and I seem to be having trouble properly constructing my decoder input sequence in the correct format. Consider the following where label1, label2 is supposed to be a sequence of labels.
label1, label2 = tf.decode_csv(rows, record_defaults=[[""], [""]])
labels = tf.stack([label1, label2], axis=1)
label_index = tf.contrib.lookup.index_table_from_file(
vocabulary_file = label_file)
label_idx = label_index.lookup(labels)
features = dict(zip(['decoder_input'], [label_idx]))
these "features" are then passed as the decoder input as below. When I go to use the decoder_input as input into my custom estimator, I run into the an error 'TypeError: 'Tensor' object is not iterable.' here:
outputs, state = tf.contrib.legacy_seq2seq.embedding_rnn_decoder(
decoder_inputs = features['decoder_input'],
initial_state = curr_layer,
cell = tf.contrib.rnn.GRUCell(hidden_units),
num_symbols = n_labels,
embedding_size = embedding_dims, # should not be hard-coded
feed_previous = False)
The full stack trace (below) suggests that the portion of code causing the issue is for 'for i in decoder_inputs' from line 296 so it seems pretty clear to me that the issue is in how I construct my decoder_input in the input_fn(). However, I can't seem to figure out how to make the Tensor object an iterable list of sequences.
Stacktrace:
File "/Users/user/anaconda/envs/tensorflow-
cloud/lib/python2.7/sitepackages/tensorflow/contrib/legacy_seq2seq/python/ops/seq2seq.py", line 296, in embedding_rnn_decoder
for i in decoder_inputs)
File "/Users/user/anaconda/envs/tensorflow-cloud/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 541, in __iter__
raise TypeError("'Tensor' object is not iterable.")
TypeError: 'Tensor' object is not iterable.
Can anybody help spot how I should correctly format my labels so that they are iterable? The documentation says that decoder_inputs should be "A list of 1D batch-sized int32 Tensors (decoder inputs)." so I thought that by staIs there a more appropriate way to generate the sequence of labels than tf.stack()?