A GPT model trained on Harry Potter books, created by
Camilo Vega, AI Consultant and Professor. The model generates text in the style of the Harry Potter saga.
1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3# Load model and tokenizer
4tokenizer = AutoTokenizer.from_pretrained("CamiloVega/HarryPotterGPT-v2")
5model = AutoModelForCausalLM.from_pretrained("CamiloVega/HarryPotterGPT-v2")
6
7# Generate text
8prompt = "Harry looked at Hermione and"
9inputs = tokenizer(prompt, return_tensors="pt")
10outputs = model.generate(**inputs, max_length=100, temperature=0.7, top_k=50)
11generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
12print(generated_text)
This model was trained exclusively on Harry Potter books, so its knowledge is limited to that context. It works best with prompts related to the Harry Potter universe.
This model is part of an educational project on building language models from scratch. More details available at
https://github.com/CamiloVga/HarryPotterGPT