Views
No views yet
facebook/mbart-large-50-many-to-many-mmt on the GECTurk-generation dataset for the task of Turkish grammar correction. It takes Turkish sentences with grammatical mistakes as input and generates grammatically corrected Turkish text."tr_TR" language code for both input and output, and works without needing task-specific prefixes.1from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
2
3tokenizer = AutoTokenizer.from_pretrained("yeniguno/mbart50-turkish-grammar-corrector")
4model = AutoModelForSeq2SeqLM.from_pretrained("yeniguno/mbart50-turkish-grammar-corrector")
5
6def correct_turkish(text):
7 tokenizer.src_lang = "tr_TR"
8 encoded = tokenizer(text, return_tensors="pt", max_length=128, truncation=True)
9
10 input_ids = encoded["input_ids"].to(model.device)
11
12 generated_ids = model.generate(
13 input_ids,
14 max_length=128,
15 num_beams=4,
16 forced_bos_token_id=tokenizer.lang_code_to_id["tr_TR"]
17 )
18 return tokenizer.decode(generated_ids[0], skip_special_tokens=True)
19
20print(correct_turkish("Alide geldi.")) # Ali de geldi.
21Seq2SeqTrainer.