from transformers import T5Tokenizer, T5ForConditionalGeneration
Load the tokenizer and model
tokenizer = T5Tokenizer.from_pretrained("t5-small") # Correct model name
model = T5ForConditionalGeneration.from_pretrained("t5-small")
Input: Natural language description for webpage generation
input_text = "Generate a basic HTML page with a heading 'Welcome' and a paragraph 'Hello, World!'."
output_code = """
Welcome
Hello, World!
"""
Tokenize the inputs
input_ids = tokenizer(input_text, return_tensors="pt").input_ids # Corrected variable name
labels = tokenizer(output_code, return_tensors="pt").input_ids
Compute the loss (for fine-tuning or evaluation)
loss = model(input_ids=input_ids, labels=labels).loss
print(f"Loss: {loss.item()}")