correction.py 349 B

1234567891011
  1. from happytransformer import HappyTextToText, TTSettings
  2. # Initialize the model
  3. happy_tt = HappyTextToText("T5", "vennify/t5-base-grammar-correction")
  4. # Define the settings
  5. args = TTSettings(num_beams=5, min_length=1)
  6. def correct_grammar(text: str) -> str:
  7. result = happy_tt.generate_text(f"grammar: {text}", args=args)
  8. return result.text