Update README.md
Browse files
README.md
CHANGED
|
@@ -1,7 +1,33 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
```python
|
| 7 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
@@ -16,18 +42,16 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
| 16 |
device_map="auto",
|
| 17 |
)
|
| 18 |
|
| 19 |
-
### Translate Thai to English
|
| 20 |
# messages = [
|
| 21 |
# {"role": "system", "content": "Translate the following text into English."},
|
| 22 |
-
# {"role": "user", "content": "
|
| 23 |
# ]
|
| 24 |
|
| 25 |
-
### Translate English to Thai
|
| 26 |
messages = [
|
| 27 |
{"role": "system", "content": "Translate the following text into Thai."},
|
| 28 |
-
{"role": "user", "content": "
|
| 29 |
]
|
| 30 |
-
|
| 31 |
input_ids = tokenizer.apply_chat_template(
|
| 32 |
messages,
|
| 33 |
add_generation_prompt=True,
|
|
@@ -36,11 +60,55 @@ input_ids = tokenizer.apply_chat_template(
|
|
| 36 |
|
| 37 |
outputs = model.generate(
|
| 38 |
input_ids,
|
| 39 |
-
max_new_tokens=
|
| 40 |
-
|
| 41 |
-
temperature=0.3,
|
| 42 |
)
|
| 43 |
response = outputs[0][input_ids.shape[-1]:]
|
| 44 |
print(tokenizer.decode(response, skip_special_tokens=True))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
```
|
|
|
|
| 1 |
+
|
| 2 |
+
**Typhoon translate**
|
| 3 |
+
|
| 4 |
+
**Typhoon translate** is a lightweight, 4-billion-parameter language model designed specifically for high-quality Thai ↔ English translation—right from your local device.
|
| 5 |
+
|
| 6 |
+
Unlike general-purpose models, Typhoon Translate is fine-tuned for translation tasks and works best with dedicated prompts. Its strength lies in generating natural, fluent translations while preserving meaning and tone in both directions.
|
| 7 |
+
|
| 8 |
+
Note: For optimal results, use the system prompts:
|
| 9 |
+
`Translate the following text into Thai.` or
|
| 10 |
+
`Translate the following text into English.`
|
| 11 |
+
|
| 12 |
+
## **Performance**
|
| 13 |
+
|
| 14 |
+
We used GPT-4o-mini as an "AI judge" in AlpacaEval 2.0, comparing Typhoon Translate against its own generations and other top systems.
|
| 15 |
+
|
| 16 |
+
![EN -> TH performance]()
|
| 17 |
+
|
| 18 |
+
![TH -> EN performance]()
|
| 19 |
+
|
| 20 |
+
## **Model Description**
|
| 21 |
+
|
| 22 |
+
- **Model type**: A 4B instruct decoder-only model based on Gemma3 architecture.
|
| 23 |
+
- **Requirement**: transformers 4.51.1 or newer.
|
| 24 |
+
- **Primary Language(s)**: Thai 🇹🇭 and English 🇬🇧
|
| 25 |
+
- **License**: [Gemma License](https://github.com/google-deepmind/gemma/blob/main/LICENSE)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
## Quickstart
|
| 29 |
+
|
| 30 |
+
This code snippet shows how to use the Typhoon translation model for Thai or English text generation using the transformers library with a specific prompt.
|
| 31 |
|
| 32 |
```python
|
| 33 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
|
|
| 42 |
device_map="auto",
|
| 43 |
)
|
| 44 |
|
|
|
|
| 45 |
# messages = [
|
| 46 |
# {"role": "system", "content": "Translate the following text into English."},
|
| 47 |
+
# {"role": "user", "content": "ขออนุญาตสอบถามข้อมูลเพิ่มเติมได้ไหมครับ"},
|
| 48 |
# ]
|
| 49 |
|
| 50 |
+
# ### Translate English to Thai
|
| 51 |
messages = [
|
| 52 |
{"role": "system", "content": "Translate the following text into Thai."},
|
| 53 |
+
{"role": "user", "content": "What is machine learning?"},
|
| 54 |
]
|
|
|
|
| 55 |
input_ids = tokenizer.apply_chat_template(
|
| 56 |
messages,
|
| 57 |
add_generation_prompt=True,
|
|
|
|
| 60 |
|
| 61 |
outputs = model.generate(
|
| 62 |
input_ids,
|
| 63 |
+
max_new_tokens=8192,
|
| 64 |
+
temperature=0.2,
|
|
|
|
| 65 |
)
|
| 66 |
response = outputs[0][input_ids.shape[-1]:]
|
| 67 |
print(tokenizer.decode(response, skip_special_tokens=True))
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
## Deploy as Server
|
| 71 |
+
|
| 72 |
+
This section shows how to run Typhoon translate as an OpenAI-compatible API server using vllm.
|
| 73 |
+
|
| 74 |
+
- SGLang:
|
| 75 |
+
```base
|
| 76 |
+
python3 -m sglang.launch_server scb10x/typhoon-translate-4b --context-length 16000 --dtype bfloat16
|
| 77 |
+
```
|
| 78 |
+
- vLLM:
|
| 79 |
+
```bash
|
| 80 |
+
vllm serve scb10x/typhoon-translate-4b --max-model-len 16000 --dtype bfloat16
|
| 81 |
+
```
|
| 82 |
+
## Best Practices
|
| 83 |
+
To achieve optimal performance, we recommend the following settings:
|
| 84 |
+
- Use system prompt `Translate the following text into Thai.` for English to Thai translation and `Translate the following text into English.` for Thai to English translation.
|
| 85 |
+
- Set low temperature.
|
| 86 |
+
- Using an context length of 8192 tokens.
|
| 87 |
+
|
| 88 |
+
## Intended Uses & Limitations
|
| 89 |
+
This is a task-specific model intended to be used only with the provided prompts. It does not include any guardrails. Due to the nature of large language models (LLMs), a certain level of hallucination may occur. We recommend that developers carefully assess these risks in the context of their specific use case.
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
## **Follow us**
|
| 93 |
+
|
| 94 |
+
**https://twitter.com/opentyphoon**
|
| 95 |
+
|
| 96 |
+
## **Support**
|
| 97 |
+
|
| 98 |
+
**https://discord.gg/us5gAYmrxw**
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
## **Citation**
|
| 102 |
|
| 103 |
+
- If you find Typhoon2 useful for your work, please cite it using:
|
| 104 |
+
```
|
| 105 |
+
@misc{typhoon2,
|
| 106 |
+
title={Typhoon 2: A Family of Open Text and Multimodal Thai Large Language Models},
|
| 107 |
+
author={Kunat Pipatanakul and Potsawee Manakul and Natapong Nitarach and Warit Sirichotedumrong and Surapon Nonesung and Teetouch Jaknamon and Parinthapat Pengpun and Pittawat Taveekitworachai and Adisai Na-Thalang and Sittipong Sripaisarnmongkol and Krisanapong Jirayoot and Kasima Tharnpipitchai},
|
| 108 |
+
year={2024},
|
| 109 |
+
eprint={2412.13702},
|
| 110 |
+
archivePrefix={arXiv},
|
| 111 |
+
primaryClass={cs.CL},
|
| 112 |
+
url={https://arxiv.org/abs/2412.13702},
|
| 113 |
+
}
|
| 114 |
```
|