# Getting outputs of mode.predict() per sentence input

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgetting-outputs-of-mode-predict-per-sentence-input%2F7037%3E%5C
**Category:** Models\
**Created:** [June 21, 2021, 1:19pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgetting-outputs-of-mode-predict-per-sentence-input%2F7037 "2021-06-21T13:19:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinurad13](https://avatars.discourse-cdn.com/v4/letter/v/e274bd/32.png) [@vinurad13](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fvinurad13)%5C
**Post date:** [June 21, 2021, 1:19pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgetting-outputs-of-mode-predict-per-sentence-input%2F7037%2F1 "2021-06-21T13:19:28Z")

</div>

Hi,  
I am using a TF XLM-R base classifier model-checkpoint (“jplu/tf-xlm-roberta-base”) and the tf keras native’train()’ method. On prediction (mode.predict()) I get an output logits array having 166632 length. I am providing an input of 786 data points (sentence) only. I think the 166632 is the product of the no. of input ids (212) from tokenization (from Autotokenizer) and input dataset length, but I’m not sure how that can be explained. Can someone explain how to derive prediction result per each sentence from this mode.predict output?

```auto
test_encodings = tokenizer(X_test, truncation=True, padding=True)

test_dataset = tf.data.Dataset.from_tensor_slices((
    dict(test_encodings),
    y_test
))
test_dataset

<TensorSliceDataset shapes: ({input_ids: (212,), attention_mask: (212,)}, ()), types: ({input_ids: tf.int32, attention_mask: tf.int32}, tf.int64)>

```

I form train and validation datasets similarly, for fine -tuning. when predicting,

```auto
out=model.predict(test_dataset)
len(out.logits)
out
166632
TFSequenceClassifierOutput(loss=None, logits=array([[-0.27663636, 0.68009704, 1.0416636 , -0.9192458],
       [-0.27665925, 0.68014 , 1.0416217 , -0.91923165],
       [-0.27644584, 0.6797307 , 1.0419688 , -0.91936153],
       ...,
       [-0.25672776, 0.64896476, 1.0766468 , -0.92797905],
       [-0.2567277 , 0.64896476, 1.0766468 , -0.9279789],
       [-0.2567277 , 0.64896476, 1.0766468 , -0.9279789]],
      dtype=float32), hidden_states=None, attentions=None)

```

Thanks

---

<div class="post-metadata">

**Author:** ![lewtun](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/lewtun/32/30995_2.png) [@lewtun](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Flewtun)%5C
**Post date:** [June 21, 2021, 2:48pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgetting-outputs-of-mode-predict-per-sentence-input%2F7037%2F2 "2021-06-21T14:48:19Z")

</div>

hey @vinurad13 what shape does `test_encodings["input_ids"]` have?

without seeing the details behind `X_test` my guess is that you need to reshape your inputs so that `input_ids` has shape `(batch_size, max_seq_length)`

---

<div class="post-metadata">

**Author:** ![vinurad13](https://avatars.discourse-cdn.com/v4/letter/v/e274bd/32.png) [@vinurad13](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fvinurad13)%5C
**Post date:** [June 21, 2021, 4:34pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgetting-outputs-of-mode-predict-per-sentence-input%2F7037%2F3 "2021-06-21T16:34:16Z")

</div>

Hi, thanks for replying. This is the shape, (786 is the test dataset size)

```auto
np.array(test.encodings['input_ids']).shape
(786, 212)

```

I am obtaining X\_test, y\_test from a csv read and train-test split and get their tokens as above. How can I reshape the `input_ids` in the tokenization step? it also warns,

```auto
Asking to truncate to max_length but no maximum length is provided and the model has no predefined maximum length. Default to no truncation.

```

Furthermore, I used the trainer() API before trying the native Keras methods with the same inputs and input shapes. trainer.evaluate() and trainer.predict() gave proper outputs which are similar to input test dataset lengths.

---

<div class="post-metadata">

**Author:** ![vinurad13](https://avatars.discourse-cdn.com/v4/letter/v/e274bd/32.png) [@vinurad13](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fvinurad13)%5C
**Post date:** [June 21, 2021, 5:44pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fgetting-outputs-of-mode-predict-per-sentence-input%2F7037%2F4 "2021-06-21T17:44:25Z")

</div>

Hi,

Found that it gives the correct length of output if I feed the input like below;

```auto
out=model.predict(test_dataset.shuffle(500).batch(16))

```

where buffer\_size and batch size could be changed. it seems that the dataset object should be always fed like this (not directly)
