0

I am doing some sentiment analysis with Tensorflow, but there is a problem I can't solve:

I have one tensor (input) shaped as [?, 38] [batch_size, max_word_length] and one (prediction) shaped as [?, 3] [batch_size, predicted_label].
My goal is to combine both tensors into a single tensor with the shape of [?, 38, 3].
This tensor is used as the input of my second stage.

Seems easy, but i can't find a way of doing it.

Can (and will) you tell me how to do this?

Someone
  • 215
  • 3
  • 7

1 Answers1

0

This is impossible. You have tensor, which contains batch_size * max_word_length elements and tensor which contains batch_size * predicted_label elements. Hence there are

batch_size * (max_word_length + predicted_label)

elements. And now you want to create new tensor [batch_size, max_word_length, predicted_label] with

batch_size * max_word_length * predicted_label

elements. You don't have enough elements for this.

Vladimir Bystricky
  • 1,320
  • 1
  • 11
  • 13
  • Well, yeah you are right, so `tf.concat([input, prediction], 1)` leading to `[?, 41]` is the way to go. But how do I perform this on a different feature encoder which gives me a tensor like `[None, 38, 78, 109]` e.g. `[batch_size, words_per_line, chars_per_word, possible_chars_one_hot]` – Someone Jul 24 '17 at 14:26
  • And you joined this tensor with what? – Vladimir Bystricky Jul 24 '17 at 15:34
  • I want to join the `[None, 38, 78, 109]` e.g. `[batch_size, words_per_line, chars_per_word, possible_chars_one_hot]` tensor with the `[?, 3] [batch_size, predicted_label]` tensor. So I have all the information for the next stage in one place. If this is not possible I need to have a neuronal net with 2 inputs, something like [this](https://stackoverflow.com/questions/40318457/how-to-build-a-multiple-input-graph-with-tensor-flow). B.t.w. thank you for your help. – Someone Jul 24 '17 at 15:42
  • Hm. I don't have experience with NN for chars-words and etc. I use NN for CV. But in CV I feed to NN two tensors: one - batch of images `[batch_size, height, width, channels]` and second - batch of labels corresponding to images `[batch_size, labels_for_one_image_cnt]`. I don't concatenate this two tensor, but this is not a problem. But I am not sure this is same with your case. – Vladimir Bystricky Jul 24 '17 at 15:54