huggingface / transformers

🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
https://huggingface.co/transformers
Apache License 2.0
135.4k stars 27.09k forks source link

Conditional generation with T5 #10176

Closed ShivanshuPurohit closed 3 years ago

ShivanshuPurohit commented 3 years ago

Environment info

Who can help

Information

Model I am using (Bert, XLNet ...): T5

The problem arises when using:

To reproduce

Steps to reproduce the behavior:

  1. Run the code above

Expected behavior

To see the generated text. Rather, the model outputs a torch Tensor like so tensor([[ 0, 363, 19, 8, 1784, 13, 1473, 58, 1]]) How do I get words out of it rather than a tensor?

NielsRogge commented 3 years ago

You can decode them back to a string using T5Tokenizer, like so:

tokenizer.decode(outputs.squeeze().tolist(), skip_special_tokens=True)

Btw, for a really good guide on the different generation strategies of models like T5, see this blog post: https://huggingface.co/blog/how-to-generate

ShivanshuPurohit commented 3 years ago

This post was really helpful, thanks!