# TrOCR inference

**URL:** <https://discuss.huggingface.co/t/trocr-inference/12237>\
**Category:** Beginners\
**Created:** [November 24, 2021, 11:33am UTC](https://discuss.huggingface.co/t/trocr-inference/12237 "2021-11-24T11:33:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kforcode](https://avatars.discourse-cdn.com/v4/letter/k/57b2e6/32.png) [@Kforcode](https://discuss.huggingface.co/u/Kforcode)\
**Post date:** [November 24, 2021, 11:33am UTC](https://discuss.huggingface.co/t/trocr-inference/12237/1 "2021-11-24T11:33:51Z")

</div>

@nielsr, i am using trocr-printed for inference using the below code and its working fine except for  
the len of (tuple\_of\_logits) , it’s always 19, no matter what batch\_size i use, even when i override the  
model.decoder.config.max\_length from 20 to 10, the len(tuple\_of\_logits) is always 19.

can you please help me figure out, what am I missing here?

```auto
for batch in tqdm(test_dataloader):
    # predict using generate
    pixel_values = batch["pixel_values"].to(device)
    outputs = model.generate(pixel_values, output_scores=True, return_dict_in_generate=True)
    tuple_of_logits = outputs.scores
    print(len(tuple_of_logits))

```

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](https://discuss.huggingface.co/u/nielsr)\
**Post date:** [November 24, 2021, 12:20pm UTC](https://discuss.huggingface.co/t/trocr-inference/12237/2 "2021-11-24T12:20:59Z")

</div>

Hi,

You can adjust the maximum number of tokens by specifying the `max_length` parameter of the generate method:

```auto
outputs = model.generate(pixel_values, output_scores=True, return_dict_in_generate=True, max_length=10)

```

Note that this is explained in the [docs](https://huggingface.co/transformers/main_classes/model.html?highlight=generate#transformers.generation_tf_utils.TFGenerationMixin.generate).
