Views
No views yet
tabularisai/multilingual-emotion-classification.1from unsloth import FastLanguageModel
2import torch
3
4model, tokenizer = FastLanguageModel.from_pretrained(
5 model_name="manotham/Thai-dialogue-translate_emotion_mdpov2_ckp269",
6 max_seq_length=1024,
7 load_in_4bit=True,
8)
9
10FastLanguageModel.for_inference(model)
11
12def translate_with_emotion(text, emotion):
13
14 messages = [
15 {
16 "role": "user",
17 "content": f"Translate this English sentence into natural Thai.\n[Emotion: {emotion}]\n{text}"
18 }
19 ]
20
21 inputs = tokenizer.apply_chat_template(
22 messages,
23 tokenize=True,
24 add_generation_prompt=True,
25 return_tensors="pt"
26 ).to("cuda")
27
28 with torch.inference_mode():
29 outputs = model.generate(
30 inputs,
31 max_new_tokens=128,
32 )
33
34 return tokenizer.decode(
35 outputs[0][inputs.shape[-1]:],
36 skip_special_tokens=True
37 )
38
39print(
40 translate_with_emotion(
41 "I found you in this broken world.",
42 "joy"
43 )
44)I don’t want to save this world anymore… I just want to stay by your side until the end.
ฉันไม่อยากช่วยโลกใบนี้อีกแล้ว ฉันแค่อยากอยู่ข้างๆ เธอจนถึงท้ายที่สุดเท่านั้น
If justice only chooses the strong, then I’ll become the monster this world fears most.
ถ้าความยุติธรรมเลือกคนที่แข็งแกร่งเท่านั้น ฉันก็จะกลายเป็นสัตว์ประหลาดที่โลกนี้กลัวที่สุด
This is your so-called hero? I’ve seen weaker NPCs in a beginner dungeon.
นี่คือฮีโร่ที่พวกแกอ้างถึงงั้นเหรอ? ข้าเคยเห็น NPC ที่อ่อนแอกว่านี้ในดันเจี้ยนระดับมือใหม่เลยนะ