# TrOCR inference

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftrocr-inference%2F12237%3E%5C
**Category:** Beginners\
**Created:** [November 24, 2021, 11:33am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftrocr-inference%2F12237 "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](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FKforcode)%5C
**Post date:** [November 24, 2021, 11:33am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftrocr-inference%2F12237%2F1 "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](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnielsr)%5C
**Post date:** [November 24, 2021, 12:20pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ftrocr-inference%2F12237%2F2 "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).
