Views
No views yet
1from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
2
3model = AutoModelForSeq2SeqLM.from_pretrained('s-nlp/mt0-xl-detox-orpo', device_map="auto")
4tokenizer = AutoTokenizer.from_pretrained('s-nlp/mt0-xl-detox-orpo')
5
6LANG_PROMPTS = {
7 'zh': '排毒:',
8 'es': 'Desintoxicar: ',
9 'ru': 'Детоксифицируй: ',
10 'ar': 'إزالة السموم: ',
11 'hi': 'विषहरण: ',
12 'uk': 'Детоксифікуй: ',
13 'de': 'Entgiften: ',
14 'am': 'መርዝ መርዝ: ',
15 'en': 'Detoxify: ',
16}
17
18def detoxify(text, lang, model, tokenizer):
19 encodings = tokenizer(LANG_PROMPTS[lang] + text, return_tensors='pt').to(model.device)
20
21 outputs = model.generate(**encodings.to(model.device),
22 max_length=128,
23 num_beams=10,
24 no_repeat_ngram_size=3,
25 repetition_penalty=1.2,
26 num_beam_groups=5,
27 diversity_penalty=2.5,
28 num_return_sequences=5,
29 early_stopping=True,
30 )
31
32 return tokenizer.batch_decode(outputs, skip_special_tokens=True)@inproceedings{smurfcat_at_pan,
author = {Elisei Rykov and
Konstantin Zaytsev and
Ivan Anisimov and
Alexandr Voronin},
editor = {Guglielmo Faggioli and
Nicola Ferro and
Petra Galusc{\'{a}}kov{\'{a}} and
Alba Garc{\'{\i}}a Seco de Herrera},
title = {SmurfCat at {PAN} 2024 TextDetox: Alignment of Multilingual Transformers
for Text Detoxification},
booktitle = {Working Notes of the Conference and Labs of the Evaluation Forum {(CLEF}
2024), Grenoble, France, 9-12 September, 2024},
series = {{CEUR} Workshop Proceedings},
volume = {3740},
pages = {2866--2871},
publisher = {CEUR-WS.org},
year = {2024},
url = {https://ceur-ws.org/Vol-3740/paper-276.pdf},
timestamp = {Wed, 21 Aug 2024 22:46:00 +0200},
biburl = {https://dblp.org/rec/conf/clef/RykovZAV24.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}