374 lines
18 KiB
Markdown
374 lines
18 KiB
Markdown
---
|
||
license: gemma
|
||
language:
|
||
- en
|
||
- zh
|
||
base_model:
|
||
- google/gemma-3-4b-pt
|
||
library_name: transformers
|
||
tags:
|
||
- Taiwan
|
||
- R.O.C
|
||
- zhtw
|
||
- SLM
|
||
- Gemma-3
|
||
- gemma3
|
||
datasets:
|
||
- lianghsun/tw-reasoning-instruct
|
||
- lianghsun/tw-contract-review-chat
|
||
- minyichen/tw-instruct-R1-200k
|
||
- minyichen/tw_mm_R1
|
||
- minyichen/LongPaper_multitask_zh_tw_R1
|
||
- nvidia/Nemotron-Instruction-Following-Chat-v1
|
||
|
||
model-index:
|
||
- name: gemma-3-4B-T1-it
|
||
results:
|
||
- task:
|
||
type: question-answering
|
||
name: Single Choice Question
|
||
dataset:
|
||
type: ikala/tmmluplus
|
||
name: tmmlu+
|
||
config: all
|
||
split: test
|
||
revision: c0e8ae955997300d5dbf0e382bf0ba5115f85e8c
|
||
metrics:
|
||
- name: single choice
|
||
type: accuracy
|
||
value: 47.44
|
||
- task:
|
||
type: question-answering
|
||
name: Single Choice Question
|
||
dataset:
|
||
type: cais/mmlu
|
||
name: mmlu
|
||
config: all
|
||
split: test
|
||
revision: c30699e
|
||
metrics:
|
||
- name: single choice
|
||
type: accuracy
|
||
value: 59.13
|
||
- task:
|
||
type: question-answering
|
||
name: Single Choice Question
|
||
dataset:
|
||
type: lianghsun/tw-legal-benchmark-v1
|
||
name: tw-legal-benchmark-v1
|
||
config: all
|
||
split: test
|
||
revision: 66c3a5f
|
||
metrics:
|
||
- name: single choice
|
||
type: accuracy
|
||
value: 44.18
|
||
metrics:
|
||
- accuracy
|
||
---
|
||
|
||
|
||
|
||
# Model Card for gemma-3-4B-T1-it
|
||
|
||
<div align="center" style="line-height: 1;">
|
||
<a href="https://discord.gg/Cx737yw4ed" target="_blank" style="margin: 2px;">
|
||
<img alt="Discord" src="https://img.shields.io/badge/Discord-Twinkle%20AI-7289da?logo=discord&logoColor=white&color=7289da" style="display: inline-block; vertical-align: middle;"/>
|
||
</a>
|
||
<a href="https://huggingface.co/twinkle-ai" target="_blank" style="margin: 2px;">
|
||
<img alt="Hugging Face" src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Twinkle%20AI-ffc107?color=ffc107&logoColor=white" style="display: inline-block; vertical-align: middle;"/>
|
||
</a>
|
||
<!-- Gemma 模型在 Hugging Face 上為 gated,使用者需同意 Google usage license -->
|
||
<a href="https://huggingface.co/google/gemma-3-4b-pt" style="margin: 2px;">
|
||
<img alt="License" src="https://img.shields.io/badge/License-gemma-f5de53?&color=0081fb" style="display: inline-block; vertical-align: middle;"/>
|
||
</a>
|
||
<a href="https://huggingface.co/twinkle-ai/gemma-3-4B-T1-it/blob/main/README.md" target="_blank" style="margin: 2px;">
|
||
<img alt="繁體中文" src="https://img.shields.io/badge/README-繁體中文-4E9A06?logo=google-translate&logoColor=white" style="display: inline-block; vertical-align: middle;"/>
|
||
</a>
|
||
</div>
|
||
|
||

|
||
|
||
<!-- Provide a quick summary of what the model is/does. -->
|
||
**gemma-3-4B-T1-it** is a Traditional Chinese instruction-tuned model specifically designed for the context of Taiwan (Republic of China). Built upon the [google/gemma-3-4b-pt](https://huggingface.co/google/gemma-3-4b-pt) architecture, this model deeply integrates Taiwan's humanities, social context, and local terminology. It is capable of flexibly handling diverse tasks such as legal provision interpretation, academic material compilation, and daily situational dialogue.
|
||
|
||
Furthermore, this model has been strengthened in **Function Calling** structure understanding and output stability, providing a solid foundation for building AI Agents or tool-oriented applications. The model itself does not presuppose specific task workflows, making it suitable for integration with application-layer tool definitions and control logic to progressively develop Agent systems that meet practical needs.
|
||
|
||
⚠️ **Key Specification:** This model is a **Single Modality** version (text-only).
|
||
|
||
## Model Details
|
||
|
||
Following the widespread resonance of the [Formosa-1 Series](https://huggingface.co/collections/twinkle-ai/formosa-1-series) in the Traditional Chinese open-source community, Twinkle AI continues to dedicate itself to solving the pain points of "insufficient model localization" and "cultural context gaps." `gemma-3-4B-T1-Instruct` is the team's brand-new attempt based on the Google Gemma 3 architecture. Unlike models that merely perform language translation, the T1 Series places greater emphasis on "Taiwan's local humanities and social depth." We understand that language is a carrier of culture; a good Traditional Chinese model should not only know how to write Traditional Chinese characters but also understand Taiwan's historical context, social norms, and legal system.
|
||
|
||
### Key Features
|
||
* **Cultural Alignment (Deep Localization & Humanities/Social Context):**
|
||
* Enhanced training on data specific to Taiwan's **Humanities & Social Sciences.**
|
||
* Corrected common biases in Large Language Models regarding Taiwanese terminology (e.g., legal terms, government agency titles, place names, and descriptions of historical events), ensuring generated content aligns with the cognitive habits of Taiwanese readers.
|
||
|
||
* **Agent Base: Enhanced Function Calling Capabilities:**
|
||
* During the training phase, we specifically reinforced the **Function Calling** format, equipping the model with excellent structural understanding and tool invocation potential.
|
||
* The model can accurately identify when to call external tools (APIs), precisely extract parameters, and generate final responses based on tool results. Users can further reinforce and integrate the model with domain data, tool definitions, and workflow designs according to their application scenarios (such as RAG, internal enterprise systems, automated processes, professional decision support, etc.).
|
||
* **Multi-domain Expertise:**
|
||
* **Legal Practice:** Understands the structure of Taiwan's legal provisions and can assist in basic provision interpretation and legal document support (Note: For assistance only; not formal legal advice).
|
||
* **Education Support:** Suitable for compiling teaching materials, exam question analyses, and syllabuses that align with Taiwan's curriculum style.
|
||
* **Life Applications:** Possesses high **Instruction Following** capabilities, providing precise and natural Traditional Chinese responses for creative writing, daily chat, or information organization.
|
||
|
||
### Model Description
|
||
|
||
- **Developed by:** [Liang Hsun Huang](https://huggingface.co/lianghsun)、[Min Yi Chen](https://huggingface.co/minyichen)、[Wen Bin Lin](https://huggingface.co/tedslin) & [Dave Sung](https://huggingface.co/k1dave6412) (All authors have contributed equally to this work.)
|
||
- **Funded by:** [APMIC](https://www.apmic.ai/) & [Jerry Wu](https://huggingface.co/JerryWu)
|
||
- **Base model:** [google/gemma-3-4b-pt](https://huggingface.co/google/gemma-3-4b-pt)
|
||
- **Model type:** Gemma3ForConditionalGeneration (Transformers)
|
||
- **Language(s) (NLP):** Traditional Chinese & English
|
||
- **License:** gemma (Google usage license; gated on Hugging Face)
|
||
|
||
### Model Sources
|
||
|
||
- **Repository:** [twinkle-ai/gemma-3-4B-T1-it](https://huggingface.co/twinkle-ai/gemma-3-4B-T1-it)
|
||
|
||
## Evaluation
|
||
|
||
### Results
|
||
|
||
The table below uses the [🌟 Twinkle Eval](https://github.com/ai-twinkle/Eval) benchmark framework.
|
||
|
||
|
||
| Model | Evaluation Mode | TMMLU+(%) | Taiwan Legal (%) | MMLU(%) | Runs | Option Ordering |
|
||
|------------------------------------|:---------:|:----------------:|:----------------:|:----------------:|:---------:|:---------:|
|
||
| [google/gemma-3-4b-it](https://huggingface.co/google/gemma-3-4b-it) | box | 35.12 (±0.018) | 32.69 (±0.021) | 41.03 (±0.019) | 3 | Random |
|
||
| 🌟[twinkle-ai/Llama-3.2-3B-F1-Instruct](https://huggingface.co/twinkle-ai/Llama-3.2-3B-F1-Instruct) (ours) | box | 44.11 (±0.018) | 35.24 (±0.012) | 50.64 (±0.019) | 3 | Random |
|
||
| 🌟[twinkle-ai/gemma-3-4B-T1-it](https://huggingface.co/twinkle-ai/gemma-3-4B-T1-it) (ours) | box | 47.44 (±0.018)| 44.18 (±0.022) | 59.13 (±0.021)| 3 | Random |
|
||
|
||
### Function Calling Benchmark
|
||
|
||
We utilized the **BFCL (Berkeley Function Calling Leaderboard)** to evaluate the model's performance in Function Calling tasks.
|
||
|
||
The metrics used are as follows:
|
||
* AST Accuracy: Compares the structural similarity between the model-generated function call and the target answer on the Abstract Syntax Tree (AST).
|
||
* It covers four types of questions:
|
||
* Simple Function
|
||
* Multiple Function
|
||
* Parallel Function
|
||
* Parallel Multiple Function
|
||
|
||
| Model | Overall Accuracy | AST Accuracy (S.) | AST Accuracy (M.) | AST Accuracy (P.) | AST Accuracy (P.M.) |
|
||
|-----------------|------------------|-------------------|-------------------|-------------------|---------------------|
|
||
| [google/gemma-3-4b-it](https://huggingface.co/google/gemma-3-4b-it) | 61 | 64 | 88 | 56 | 36 |
|
||
| 🌟[twinkle-ai/Llama-3.2-3B-F1-Instruct](https://huggingface.co/twinkle-ai/Llama-3.2-3B-F1-Instruct) (ours) | **91** | 93 | 95 | 91 | 87 |
|
||
| 🌟[twinkle-ai/gemma-3-4B-T1-it](https://huggingface.co/twinkle-ai/gemma-3-4B-T1-it) (ours) | 84.5 | 88 | 89 | 80 | 81 |
|
||
|
||
---
|
||
## Model Responses
|
||
|
||
The following examples demonstrate the differences between **gemma-3-4B-it (Original)** and **🌟 gemma-3-4B-T1-it (Ours)** in Taiwan-specific contexts.
|
||
> Note: In the image, 👈 denotes gemma-3-4B-it; 👉 denotes 🌟gemma-3-4B-T1-it.
|
||
|
||
### Geographical Knowledge
|
||
|
||

|
||
|
||
### Taiwanese Slang
|
||
|
||

|
||
|
||
### Localized Translation
|
||
> Translations generated by foreign models almost exclusively use Mainland Chinese terminology.
|
||
|
||

|
||
|
||
### The Pride of Taiwan
|
||
|
||

|
||
|
||
### Taiwanese Memes
|
||
|
||

|
||
|
||
## 🔧 Tool Calling
|
||
|
||
This model is trained using the **Hermes** format and supports **Parallel calling**. Below is a complete example workflow. The Tool calling template is already integrated into the `chat_template`.
|
||
|
||
### 1️⃣ Start vLLM Backend
|
||
|
||
```bash
|
||
vllm serve twinkle-ai/gemma-3-4B-T1-it \
|
||
--port 8000 \
|
||
--enable-auto-tool-choice \
|
||
--tool-call-parser hermes
|
||
```
|
||
|
||
### 2️⃣ Define Tools (Functions)
|
||
|
||
```python
|
||
def get_weather(location: str, unit: str):
|
||
return f"{location}的氣溫是{unit}26度,晴朗無風"
|
||
|
||
def search(query: str):
|
||
return "川普終於宣布對等關稅政策,針對 18 個經濟體課徵一半的對等關稅,並從 4/5 起對所有進口產品徵收10%的基準關稅!美國將針對被認定為不當貿易行為(不公平貿易) 的國家,於 4/9 起課徵報復型對等關稅 (Discounted Reciprocal Tariff),例如:日本將被課徵 24% 的關稅,歐盟則為 20%,以取代普遍性的 10% 關稅。\n針對中國則開啟新一波 34% 關稅,並疊加於先前已實施的關稅上,這將使中國進口商品的基本關稅稅率達到 54%,而且這尚未包含拜登總統任內或川普第一任期所施加的額外關稅。加拿大與墨西哥則不適用這套對等關稅制度,但川普認為這些國家在芬太尼危機與非法移民問題尚未完全解決,因此計畫對這兩國的大多數進口商品施加 25% 關稅。另外原本針對汽車與多數其他商品的關稅豁免將於 4/2 到期。\n台灣的部分,美國擬向台灣課徵32%的對等關稅,雖然並未針對晶片特別課徵關稅,但仍在記者會中提到台灣搶奪所有的電腦與半導體晶片,最終促成台積電對美國投資計劃額外加碼 1,000 億美元的歷史性投資;歐盟則課徵20%的對等關稅。最後是汽車關稅將於 4/2 起,對所有外國製造的汽車課徵25% 關稅。"
|
||
|
||
tools = [
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "get_weather",
|
||
"description": "Get the current weather in a given location",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"location": {"type": "string", "description": "國家或城市名, e.g., 'Taipei'、'Jaipei'"},
|
||
"unit": {"type": "string", "description": "氣溫單位,亞洲城市使用攝氏;歐美城市使用華氏", "enum": ["celsius", "fahrenheit"]}
|
||
},
|
||
"required": ["location", "unit"]
|
||
}
|
||
}
|
||
},
|
||
{
|
||
"type": "function",
|
||
"function": {
|
||
"name": "search",
|
||
"description": "這是一個類似 Google 的搜尋引擎,關於知識、天氣、股票、電影、小說、百科等等問題,如果你不確定答案就搜尋一下。",
|
||
"parameters": {
|
||
"type": "object",
|
||
"properties": {
|
||
"query": {"type": "string", "description": "should be a search query, e.g., '2024 南韓 戒嚴'"}
|
||
},
|
||
"required": ["query"]
|
||
}
|
||
}
|
||
}
|
||
]
|
||
```
|
||
|
||
### 3️⃣ Execute Tool Calls
|
||
|
||
> **⚠️ Note: `system_prompt` is optional unless the tool requires a time reference.**
|
||
```python
|
||
response = client.chat.completions.create(
|
||
model=client.models.list().data[0].id,
|
||
messages=[
|
||
{"role": "system", "content": "記住你的知識截止於 2024/12,今天是 2025/4/7"},
|
||
{"role": "user", "content": "台北氣溫如何? 另外,告訴我川普最新關稅政策"},
|
||
],
|
||
max_tokens=1500,
|
||
temperature=0.6,
|
||
top_p=0.95,
|
||
tools=tools,
|
||
tool_choice="auto"
|
||
)
|
||
|
||
print(response.choices[0].message.tool_calls)
|
||
```
|
||
|
||
#### ⚙️ Tool Calls List:
|
||
|
||
|
||
```json
|
||
[ChatCompletionMessageToolCall(id='chatcmpl-tool-35e74420119349999913a10133b84bd3', function=Function(arguments='{"location": "Taipei", "unit": "celsius"}', name='get_weather'), type='function'), ChatCompletionMessageToolCall(id='chatcmpl-tool-7ffdcb98e59f4134a6171defe7f2e31b', function=Function(arguments='{"query": "Donald Trump latest tariffs policy"}', name='search'), type='function')]
|
||
```
|
||
|
||
### 4️⃣ Generate Final Answer
|
||
|
||
```python
|
||
response = client.chat.completions.create(
|
||
model=client.models.list().data[0].id,
|
||
messages=[
|
||
{"role": "system", "content": "記住你的知識截止於 2024/12,今天是 2025/4/7"},
|
||
{"role": "user", "content": "台北氣溫如何? 另外,告訴我川普最新關稅政策"},
|
||
{
|
||
"role": "assistant",
|
||
"content": "",
|
||
"tool_calls": [
|
||
{
|
||
"id": response.choices[0].message.tool_calls[0].id,
|
||
"type": "function",
|
||
"function": {
|
||
"name": response.choices[0].message.tool_calls[0].function.name,
|
||
"arguments": response.choices[0].message.tool_calls[0].function.arguments
|
||
}
|
||
},
|
||
{
|
||
"id": response.choices[0].message.tool_calls[1].id,
|
||
"type": "function",
|
||
"function": {
|
||
"name": response.choices[0].message.tool_calls[1].function.name,
|
||
"arguments": response.choices[0].message.tool_calls[1].function.arguments
|
||
}
|
||
}
|
||
]
|
||
},
|
||
{
|
||
"role": "tool",
|
||
"content": search(**json.loads(response.choices[0].message.tool_calls[0].function.arguments)),
|
||
"tool_call_id": response.choices[0].message.tool_calls[0].id # tool_call_id 必須要帶,才能正確配對 工具 及 tool_call
|
||
},
|
||
{
|
||
"role": "tool",
|
||
"content": get_weather(**json.loads(response.choices[0].message.tool_calls[1].function.arguments)),
|
||
"tool_call_id": response.choices[0].message.tool_calls[1].id # tool_call_id 必須要帶,才能正確配對 工具 及 tool_call
|
||
}
|
||
],
|
||
max_tokens=1500,
|
||
temperature=0.6,
|
||
top_p=0.95,
|
||
tools=tools,
|
||
tool_choice="auto"
|
||
)
|
||
|
||
print(response.choices[0].message.content)
|
||
```
|
||
|
||
#### 📋 Final Output Content:
|
||
|
||
```text
|
||
以下是您請求的資訊:
|
||
|
||
**臺北市氣溫**
|
||
- 目前的氣溫為 **26°C**(攝氏)
|
||
- 天候狀況:晴朗無風
|
||
|
||
**川普最新關稅政策概述**
|
||
1. **對等關稅政策**
|
||
- 對 18 個經濟體課徵 50% 的對等關稅
|
||
- 自 4 月 5 日起,所有進口產品全面徵收 10% 基本關稅
|
||
|
||
2. **報復型對等關稅**
|
||
- 日本 24%、歐盟 20%
|
||
|
||
3. **對中國的高額關稅**
|
||
- 增加至 54%(原有關稅 + 新增 34%)
|
||
|
||
4. **特殊案例**
|
||
- 加拿大與墨西哥不適用,但其他商品課徵 25%
|
||
- 汽車與部分商品的免稅即將到期
|
||
|
||
5. **對台灣的影響**
|
||
- 美國計畫對台灣課徵 32% 關稅,但晶片暫無額外課稅
|
||
|
||
6. **全球視角**
|
||
- 歐盟與日本關稅比例相對較高
|
||
```
|
||
|
||
|
||
## Citation
|
||
|
||
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
||
```yaml
|
||
@misc{twinkleai2025gemma3t1,
|
||
title = {gemma-3-4B-T1-it: A Traditional Chinese Instruction-Tuned Language Model for Taiwan},
|
||
author = {Huang, Liang Hsun and Chen, Min Yi and Lin, Wen Bin and Sung, Dave},
|
||
year = {2025},
|
||
howpublished = {\url{https://huggingface.co/twinkle-ai/gemma-3-4B-T1-it}},
|
||
note = {Twinkle AI and APMIC. All authors contributed equally.}
|
||
}
|
||
```
|
||
|
||
## Acknowledge
|
||
We would like to express our gratitude to [APMIC](https://apmic.ai/) for providing computing power support, enabling the successful completion of this project training. Special thanks to [CNA](https://focustaiwan.tw/) and all partners who provided valuable assistance.
|
||
|
||
## Model Card Authors
|
||
|
||
[Twinkle AI](https://huggingface.co/twinkle-ai)
|
||
|
||
## Model Card Contact
|
||
|
||
[Twinkle AI](https://huggingface.co/twinkle-ai) |