tarudesu commited on
Commit
1fef985
1 Parent(s): e938733

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +21 -0
README.md CHANGED
@@ -50,6 +50,27 @@ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
50
 
51
  tokenizer = AutoTokenizer.from_pretrained("tarudesu/ViHateT5-base-HSD")
52
  model = AutoModelForSeq2SeqLM.from_pretrained("tarudesu/ViHateT5-base-HSD")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  ```
54
 
55
  Please feel free to contact us by email luannt@uit.edu.vn if you have any further information!
 
50
 
51
  tokenizer = AutoTokenizer.from_pretrained("tarudesu/ViHateT5-base-HSD")
52
  model = AutoModelForSeq2SeqLM.from_pretrained("tarudesu/ViHateT5-base-HSD")
53
+
54
+ def generate_output(input_text, prefix):
55
+ # Add prefix
56
+ prefixed_input_text = prefix + ': ' + input_text
57
+
58
+ # Tokenize input text
59
+ input_ids = tokenizer.encode(prefixed_input_text, return_tensors="pt")
60
+
61
+ # Generate output
62
+ output_ids = model.generate(input_ids, max_length=256)
63
+
64
+ # Decode the generated output
65
+ output_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)
66
+
67
+ return output_text
68
+
69
+ sample = 'Tôi ghét bạn vl luôn!'
70
+ prefix = 'hate-spans-detection' # Choose 1 from 3 prefixes ['hate-speech-detection', 'toxic-speech-detection', 'hate-spans-detection']
71
+
72
+ result = generate_output(sample, prefix)
73
+ print('Result: ', result)
74
  ```
75
 
76
  Please feel free to contact us by email luannt@uit.edu.vn if you have any further information!