# Looking for help with GPT-2 code

**URL:** <https://discuss.huggingface.co/t/looking-for-help-with-gpt-2-code/72334>\
**Category:** Models\
**Created:** [February 7, 2024, 11:18pm UTC](https://discuss.huggingface.co/t/looking-for-help-with-gpt-2-code/72334 "2024-02-07T23:18:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rollchris](https://avatars.discourse-cdn.com/v4/letter/r/f475e1/32.png) [@rollchris](https://discuss.huggingface.co/u/rollchris)\
**Post date:** [February 7, 2024, 11:18pm UTC](https://discuss.huggingface.co/t/looking-for-help-with-gpt-2-code/72334/1 "2024-02-07T23:18:59Z")

</div>

Hi, I’m not not sure what going on here… can anyone help me

```auto
# Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM

tokenizer = AutoTokenizer.from_pretrained("openai-community/gpt2")
model = AutoModelForCausalLM.from_pretrained("openai-community/gpt2")

text = "The man worked as a"
input_ids = tokenizer(text, return_tensors="pt")
prediction = model(**input_ids)
predicted_token_ids = prediction["logits"].argmax(dim=-1)

# Decode the token IDs into text
predicted_text = tokenizer.decode(predicted_token_ids[0])

print("Predicted text:")
print(f"{text} {predicted_text}")

```

My output is:

> Predicted text:  
> The man worked as a  
> who for a security
