Views
No views yet
1from transformers import T5ForConditionalGeneration, T5Tokenizer
2
3# Load model and tokenizer
4model = T5ForConditionalGeneration.from_pretrained("Tegence/grammar-correction-model")
5tokenizer = T5Tokenizer.from_pretrained("Tegence/grammar-correction-model")
6
7# Prepare input (add the prefix "correct grammar: ")
8incorrect_text = "She dont like to eat vegetables but she like fruits."
9input_text = f"correct grammar: {incorrect_text}"
10
11# Tokenize and generate
12input_ids = tokenizer(input_text, return_tensors="pt").input_ids
13outputs = model.generate(input_ids)
14corrected_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
15
16print(corrected_text)
17# Expected output: "She doesn't like to eat vegetables but she likes fruits."1@misc{grammar-correction-model,
2 author = {AdmitEase},
3 title = {Grammar Correction Model},
4 year = {2025},
5 publisher = {Hugging Face},
6 howpublished = {\url{https://huggingface.co/Tegence/grammar-correction-model}}
7}