Views
No views yet
@inproceedings{thanh-nguyen-2024-vihatet5,
title = "{V}i{H}ate{T}5: Enhancing Hate Speech Detection in {V}ietnamese With a Unified Text-to-Text Transformer Model",
author = "Thanh Nguyen, Luan",
editor = "Ku, Lun-Wei and Martins, Andre and Srikumar, Vivek",
booktitle = "Findings of the Association for Computational Linguistics ACL 2024",
month = aug,
year = "2024",
address = "Bangkok, Thailand and virtual meeting",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2024.findings-acl.355",
pages = "5948--5961"
}1from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
2
3tokenizer = AutoTokenizer.from_pretrained("tarudesu/ViHateT5-base-HSD")
4model = AutoModelForSeq2SeqLM.from_pretrained("tarudesu/ViHateT5-base-HSD")
5
6def generate_output(input_text, prefix):
7 # Add prefix
8 prefixed_input_text = prefix + ': ' + input_text
9
10 # Tokenize input text
11 input_ids = tokenizer.encode(prefixed_input_text, return_tensors="pt")
12
13 # Generate output
14 output_ids = model.generate(input_ids, max_length=256)
15
16 # Decode the generated output
17 output_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
18
19 return output_text
20
21sample = 'Tôi ghét bạn vl luôn!'
22prefix = 'hate-spans-detection' # Choose 1 from 3 prefixes ['hate-speech-detection', 'toxic-speech-detection', 'hate-spans-detection']
23
24result = generate_output(sample, prefix)
25print('Result: ', result)