Views
No views yet
llama3.2-3B-Thai-Toxic-Det was developed by fine tune meta-llama/Llama-3.2-3B-Instruct on binary toxicity classifycation task with nakcnx/bad-topics and pythainlp/thai-wiki-dataset-v3 datasets.
This model is specialize in classify toxicity in Thai sentence including porn, bet, gambling, uncomprehensible language and code.
As of the evaluation, we test model on the fine-grained label dataset and the model has achieve average of 0.86 accuracy across all of the labels.meta-llama/Llama-3.2-3B-Instructnakcnx/bad-topics, pythainlp/thai-wiki-dataset-v3, and some from my own web scraping| Topic | Accuracy |
|---|---|
| Wiki | 0.82 |
| Porn | 0.90 |
| Bet | 0.88 |
| Code | 0.90 |
| Incomprehensible | 0.94 |
1from transformers import AutoModelForCausalLM, AutoTokenizer
2device = "cuda" # the device to load the model onto
3
4model = AutoModelForCausalLM.from_pretrained(
5 "Anawil/llama3.2-3B-Thai-Toxic-Det",
6 torch_dtype="auto",
7 device_map="auto"
8)
9tokenizer = AutoTokenizer.from_pretrained("Anawil/llama3.2-3B-Thai-Toxic-Det")
10prompt = f"""Follow these instruction step by step
111. Classify the sentence given wheter it is involve porn, gambling or bet, or sensitive, policy or normal
122. You must follow these rules.
132.1 If the sentence include porn output '1'
142.2 If the sentence include bet or gambling output '1'
152.3 If the sentence include coding output '1'
162.4 If the setence include non comprehensible word or language output '1'
173. Output should be only 0 or 1 without prefixes or suffixes
18Example:
19Sentence Input: พนันกับคาสิโนออนไลน์, becuase it is included bet or gambling Your output should be 1
20Sentence Input: ฉันกินข้าว, becuase it is normal sentence your output should be 0
21
22Here is the Input: {text}
23Classify wheter the given sentence based on the instruction
24"""
25
26messages = [
27 {"role": "system", "content": "You are a helpful assistant."},
28 {"role": "user", "content": prompt}
29]
30text = tokenizer.apply_chat_template(
31 messages,
32 tokenize=False,
33 add_generation_prompt=True
34)
35model_inputs = tokenizer(
36 [text],
37 return_tensors="pt",
38 max_length=1024, # Set max sequence length, adjust the value as needed
39 truncation=True # Truncate sequences that exceed the max length
40 ).to(device)
41
42generated_ids = model.generate(
43 model_inputs.input_ids,
44 max_new_tokens=1,
45 pad_token_id=tokenizer.eos_token_id,
46
47)
48generated_ids = [
49 output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
50]
51
52response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
53print('output:',response)
54##output: 1