69 lines
2.7 KiB
Markdown
69 lines
2.7 KiB
Markdown
|
|
---
|
||
|
|
base_model: manotham/Thai-dialogue-transalate_sft_80K
|
||
|
|
tags:
|
||
|
|
- translation
|
||
|
|
- emotion-conditional
|
||
|
|
- text-generation-inference
|
||
|
|
- transformers
|
||
|
|
- unsloth
|
||
|
|
- qwen3
|
||
|
|
license: apache-2.0
|
||
|
|
language:
|
||
|
|
- en
|
||
|
|
- th
|
||
|
|
---
|
||
|
|
|
||
|
|
# Emotion-Conditioned English-to-Thai Translator (Warm-up SFT)
|
||
|
|
|
||
|
|
- **Developed by:** manotham
|
||
|
|
- **License:** apache-2.0
|
||
|
|
- **Base Model:** `manotham/Thai-dialogue-transalate_sft_80K`
|
||
|
|
- **Architecture:** Qwen3
|
||
|
|
|
||
|
|
This model is an experimental fine-tune aimed at adding **Emotion-Conditioned Translation** capabilities to the base English-to-Thai translation model. By specifying an emotion tag in the prompt, the model adjusts its vocabulary, tone, and sentence structure to match the requested emotional context.
|
||
|
|
|
||
|
|
This model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
||
|
|
|
||
|
|
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
||
|
|
|
||
|
|
## 🎯 Supported Emotion Labels
|
||
|
|
The model has been explicitly trained to recognize and adapt to the following 11 emotion tags:
|
||
|
|
`anger`, `contempt`, `disgust`, `fear`, `frustration`, `gratitude`, `joy`, `love`, `neutral`, `sadness`, `surprise`
|
||
|
|
|
||
|
|
## 💻 Usage / Prompt Format
|
||
|
|
|
||
|
|
This model uses the **ChatML** template. To trigger the emotion-conditional translation, include the `[Emotion: <label>]` tag in your instruction. We recommend using `apply_chat_template` from the `transformers` library for the best results.
|
||
|
|
|
||
|
|
### Python Inference Example
|
||
|
|
```python
|
||
|
|
from transformers import AutoTokenizer, AutoModelForCausalLM
|
||
|
|
|
||
|
|
model_name = "manotham/Thai-dialogue-transalate_emotion"
|
||
|
|
|
||
|
|
# 1. Load the model and tokenizer
|
||
|
|
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
||
|
|
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto")
|
||
|
|
|
||
|
|
# 2. Prepare the instruction with the desired emotion
|
||
|
|
instruction = "Translate this English sentence into natural Thai. [Emotion: sadness]\nI worked so hard on preparing for that exam, but the score was far below what I expected."
|
||
|
|
|
||
|
|
messages = [
|
||
|
|
{"role": "user", "content": instruction},
|
||
|
|
]
|
||
|
|
|
||
|
|
# 3. Apply chat template automatically
|
||
|
|
inputs = tokenizer.apply_chat_template(
|
||
|
|
messages,
|
||
|
|
add_generation_prompt=True,
|
||
|
|
tokenize=True,
|
||
|
|
return_dict=True,
|
||
|
|
return_tensors="pt",
|
||
|
|
).to(model.device)
|
||
|
|
|
||
|
|
# 4. Generate output
|
||
|
|
outputs = model.generate(**inputs, max_new_tokens=128)
|
||
|
|
|
||
|
|
# 5. Decode and print only the generated response
|
||
|
|
response = tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True)
|
||
|
|
print(response)
|
||
|
|
# Expected Output: ฉันพยายามอย่างหนักเพื่อเตรียมตัวสอบแต่ผลลัพธ์กลับต่ำกว่าที่คาดไว้มาก
|