0

I have a problem on making forecasting model(lstm) model now with tensorflow. I try to use embedding_lookup with multiple categorical columns. This is my data (shape[100, 12, 16])

[[[1, 1, 1, 7, 1, -1, 26, 9],
  [1, 5, 2, -5, 2, 20, 25, 8],
  [1, 4, 3, 1, 1, 32, 1, 7],
  ...]]

for forecasting, each row has multiple features, and I changed these features to categorical data(0, 1, 2...). after then, I'd like to use embedding layer for each columns and then concat all for using as an input data to LSTM. How can I use embedding layer and concat each others?

This is my code

def get_var(self, name='', shape=None, dtype=tf.float32):
    return tf.get_variable(name, shape, dtype=dtype, initializer=self.initializer)
def get_embedding(self, data='', name='', shape=[], dtype=tf.float32):
    return tf.nn.embedding_lookup(self.get_var(name=name, shape=shape), data)


emb_concat = self.get_embedding(tf.cast(data[:,:, 0], 'int32'), name='emb_ap2id'+type, shape=[3, 2])

emb = self.get_embedding(tf.cast(data[:,:, 1], 'int32'), name='emb_month'+type, shape=[12, 11])
emb_concat = tf.concat(emb_concat, emb, axis=2)

It isn't working and I got an error msg.

result img

Ben
  • 45
  • 1
  • 1
  • 6

0 Answers0