mav23 commited on
Commit
27b2d38
1 Parent(s): 89be844

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ openthaigpt1.5-7b-instruct.Q4_0.gguf filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ license_name: qwen
4
+ language:
5
+ - th
6
+ - en
7
+ library_name: transformers
8
+ pipeline_tag: text-generation
9
+ tags:
10
+ - openthaigpt
11
+ - qwen
12
+ ---
13
+
14
+ # 🇹🇭 OpenThaiGPT 7b 1.5 Instruct
15
+ ![OpenThaiGPT](https://1173516064-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvvbWvIIe82Iv1yHaDBC5%2Fuploads%2Fb8eiMDaqiEQL6ahbAY0h%2Fimage.png?alt=media&token=6fce78fd-2cca-4c0a-9648-bd5518e644ce)
16
+ [More Info](https://openthaigpt.aieat.or.th/)
17
+
18
+ 🇹🇭 **OpenThaiGPT 7b Version 1.5** is an advanced 7-billion-parameter Thai language chat model based on Qwen v2.5 released on September 30, 2024. It has been specifically fine-tuned on over 2,000,000 Thai instruction pairs and is capable of answering Thai-specific domain questions.
19
+
20
+ ## Online Demo:
21
+ https://demo72b.aieat.or.th/
22
+
23
+ ## Example code for API Calling
24
+ https://github.com/OpenThaiGPT/openthaigpt1.5_api_examples
25
+
26
+ ## Highlights
27
+ - **State-of-the-art Thai language LLM**, achieving the highest average scores across various Thai language exams compared to other open-source Thai LLMs.
28
+ - **Multi-turn conversation support** for extended dialogues.
29
+ - **Retrieval Augmented Generation (RAG) compatibility** for enhanced response generation.
30
+ - **Impressive context handling**: Processes up to 131,072 tokens of input and generates up to 8,192 tokens, enabling detailed and complex interactions.
31
+ - **Tool calling support**: Enables users to efficiently call various functions through intelligent responses.
32
+
33
+ ## Benchmark on [OpenThaiGPT Eval](https://huggingface.co/datasets/openthaigpt/openthaigpt_eval)
34
+ ** Please take a look at ``openthaigpt/openthaigpt1.5-7b-instruct`` for this model's evaluation result.
35
+ | **Exam names** | **scb10x/llama-3-typhoon-v1.5x-8b-instruct** | **meta-llama/Llama-3.1-7B-Instruct** | **Qwen/Qwen2.5-7B-Instruct_stat** | **openthaigpt/openthaigpt1.5-7b** |
36
+ |:------------------------------:|:--------------------------------------------:|:------------------------------------:|:---------------------------------:|:---------------------------------:|
37
+ | **01_a_level** | 46.67% | 47.50% | 58.33% | 60.00% |
38
+ | **02_tgat** | 32.00% | 36.00% | 32.00% | 36.00% |
39
+ | **03_tpat1** | 52.50% | 55.00% | 57.50% | 57.50% |
40
+ | **04_investment_consult** | 56.00% | 48.00% | 68.00% | 76.00% |
41
+ | **05_facebook_beleble_th_200** | 78.00% | 73.00% | 79.00% | 81.00% |
42
+ | **06_xcopa_th_200** | 79.50% | 69.00% | 80.50% | 81.00% |
43
+ | **07_xnli2.0_th_200** | 56.50% | 55.00% | 53.00% | 54.50% |
44
+ | **08_onet_m3_thai** | 48.00% | 32.00% | 72.00% | 64.00% |
45
+ | **09_onet_m3_social** | 75.00% | 50.00% | 90.00% | 80.00% |
46
+ | **10_onet_m3_math** | 25.00% | 18.75% | 31.25% | 31.25% |
47
+ | **11_onet_m3_science** | 46.15% | 42.31% | 46.15% | 46.15% |
48
+ | **12_onet_m3_english** | 70.00% | 76.67% | 86.67% | 83.33% |
49
+ | **13_onet_m6_thai** | 47.69% | 29.23% | 46.15% | 53.85% |
50
+ | **14_onet_m6_math** | 29.41% | 17.65% | 29.41% | 29.41% |
51
+ | **15_onet_m6_social** | 50.91% | 43.64% | 56.36% | 58.18% |
52
+ | **16_onet_m6_science** | 42.86% | 32.14% | 57.14% | 57.14% |
53
+ | **17_onet_m6_english** | 65.38% | 71.15% | 78.85% | 80.77% |
54
+ | **Micro Average** | 60.65% | 55.60% | 64.41% | <b style="color:blue">65.78%</b> |
55
+
56
+
57
+ Thai language multiple choice exams, Test on unseen test set, Zero-shot learning. Benchmark source code and exams information: https://github.com/OpenThaiGPT/openthaigpt_eval
58
+
59
+ (Updated on: 30 September 2024)
60
+
61
+ ## Benchmark on [scb10x/thai_exam](https://huggingface.co/datasets/scb10x/thai_exam)
62
+
63
+ | Models | **Thai Exam (Acc)** |
64
+ |:----------------------------------------------------------:|:-------------------:|
65
+ | **api/claude-3-5-sonnet-20240620** | 69.2 |
66
+ | <b style="color:blue">**openthaigpt/openthaigpt1.5-72b-instruct***</b> | <b style="color:blue">64.07</b> |
67
+ | **api/gpt-4o-2024-05-13** | 63.89 |
68
+ | **hugging-quants/Meta-Llama-3.1-405B-Instruct-AWQ-INT4** | 63.54 |
69
+ | **Qwen/Qwen2-72B-Instruct** | 58.23 |
70
+ | **meta-llama/Meta-Llama-3.1-70B-Instruct** | 58.23 |
71
+ | **scb10x/llama-3-typhoon-v1.5x-70b-instruct** | 58.76 |
72
+ | **Qwen/Qwen2.5-14B-Instruct** | 57.35 |
73
+ | **api/gpt-4o-mini-2024-07-18** | 54.51 |
74
+ | <b style="color:blue">**openthaigpt/openthaigpt1.5-7b-instruct***</b> | <b style="color:blue">52.04</b> |
75
+ | **SeaLLMs/SeaLLMs-v3-7B-Chat** | 51.33 |
76
+ | **openthaigpt/openthaigpt-1.0.0-70b-chat** | 50.09 |
77
+
78
+ <b style="color:blue">*</b> Evaluated by OpenThaiGPT team using [scb10x/thai_exam](https://huggingface.co/datasets/scb10x/thai_exam).
79
+
80
+ ## Licenses
81
+ * Built with Qwen
82
+ * Qwen License: Allow **Research** and
83
+ **Commercial uses** but if your user base exceeds 100 million monthly active users, you need to negotiate a separate commercial license. Please see LICENSE file for more information.<br>
84
+
85
+ ## Sponsors
86
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/5fcd9c426d942eaf4d1ebd30/3kjN6kuTzXDXQ6o1RFvHX.png" width="600px">
87
+
88
+ ## Supports
89
+ - Official website: https://openthaigpt.aieat.or.th
90
+ - Facebook page: https://web.facebook.com/groups/openthaigpt
91
+ - A Discord server for discussion and support [here](https://discord.gg/rUTp6dfVUF)
92
+ - E-mail: kobkrit@aieat.or.th
93
+
94
+ ## Prompt Format
95
+ Prompt format is based on ChatML.
96
+ ```
97
+ <|im_start|>system\n{sytem_prompt}<|im_end|>\n<|im_start|>user\n{prompt}<|im_end|>\n<|im_start|>assistant\n
98
+ ```
99
+
100
+ ### System prompt:
101
+ ```
102
+ คุณคือผู้ช่วยตอบคำถามที่ฉลาดและซื่อสัตย์
103
+ ```
104
+
105
+ ### Examples
106
+
107
+ #### Single Turn Conversation Example
108
+ ```
109
+ <|im_start|>system\nคุณคือผู้ช่วยตอบคำถามที่ฉลาดและซื่อสัตย์<|im_end|>\n<|im_start|>user\nสวัสดีครับ<|im_end|>\n<|im_start|>assistant\n
110
+ ```
111
+
112
+ #### Single Turn Conversation with Context (RAG) Example
113
+ ```
114
+ <|im_start|>system\nคุณคือผู้ช่วยตอบคำถามที่ฉลาดและซื่อสัตย์<|im_end|>\n<|im_start|>user\nกรุงเทพมหานคร เป็นเมืองหลวง นครและมหานครที่มีประชากรมากที่สุดของประเทศไทย กรุงเทพมหานครมีพื้นที่ทั้งหมด 1,568.737 ตร.กม. มีประชากรตามทะเบียนราษฎรกว่า 8 ล้านคน\nกรุงเทพมหานครมีพื้นที่เท่าไร่<|im_end|>\n<|im_start|>assistant\n
115
+ ```
116
+
117
+ #### Multi Turn Conversation Example
118
+
119
+ ##### First turn
120
+ ```
121
+ <|im_start|>system\nคุณคือผู้ช่วยตอบคำถามที่ฉลาดและซื่อสัตย์<|im_end|>\n<|im_start|>user\nสวัสดีครับ<|im_end|>\n<|im_start|>assistant\n
122
+ ```
123
+
124
+ ##### Second turn
125
+ ```
126
+ <|im_start|>system\nคุณคือผู้ช่วยตอบคำถามที่ฉลาดและซื่อสัตย์<|im_end|>\n<|im_start|>user\nสวัสดีครับ<|im_end|>\n<|im_start|>assistant\nสวัสดีครับ ยินดีต้อนรับครับ คุณต้องการให้ฉันช่วยอะไรครับ?<|im_end|>\n<|im_start|>user\nกรุงเทพมหานคร ชื่อเต็มยาวๆคืออะไร<|im_end|>\n<|im_start|>assistant\n
127
+ ```
128
+
129
+ ##### Result
130
+ ```
131
+ <|im_start|>system\nคุณคือผู้ช่วยตอบคำถามที่ฉลาดและซื่อสัตย์<|im_end|>\n<|im_start|>user\nสวัสดีครับ<|im_end|>\n<|im_start|>assistant\nสวัสดีครับ ยินดีต้อนรับครับ คุณต้องการให้ฉันช่วยอะไรครับ?<|im_end|>\n<|im_start|>user\nกรุงเทพมหานคร ชื่อเต็มยาวๆคืออะไร<|im_end|>\n<|im_start|>assistant\nชื่อเต็มของกรุงเทพมหานครคือ \"กรุงเทพมหานคร อมรรัตนโกสินทร์ มหินทรายุธยา มหาดิลกภพ นพรัตนราชธานีบูรีรมย์ อุดมราชนิเวศน์มหาสถาน อมรพิมานอวตารสถิต สักกะทัตติยวิษณุกรรมประสิทธิ์\"
132
+ ```
133
+
134
+ ## How to use
135
+
136
+ ### Free API Service (hosted by Siam.Ai and Float16.cloud)
137
+
138
+ #### Siam.AI
139
+ ```bash
140
+ curl https://api.aieat.or.th/v1/completions \
141
+ -H "Content-Type: application/json" \
142
+ -H "Authorization: Bearer dummy" \
143
+ -d '{
144
+ "model": ".",
145
+ "prompt": "<|im_start|>system\nคุณคือผู้ช่วยตอบคำถามที่ฉลาดและซื่อสัตย์<|im_end|>\n<|im_start|>user\nกรุงเทพมหานครคืออะไร<|im_end|>\n<|im_start|>assistant\n",
146
+ "max_tokens": 512,
147
+ "temperature": 0.7,
148
+ "top_p": 0.8,
149
+ "top_k": 40,
150
+ "stop": ["<|im_end|>"]
151
+ }'
152
+ ```
153
+
154
+ #### Float16
155
+ ```bash
156
+ curl -X POST https://api.float16.cloud/dedicate/78y8fJLuzE/v1/chat/completions \
157
+ -H "Content-Type: application/json" \
158
+ -H "Authorization: Bearer float16-AG0F8yNce5s1DiXm1ujcNrTaZquEdaikLwhZBRhyZQNeS7Dv0X" \
159
+ -d '{
160
+ "model": "openthaigpt/openthaigpt1.5-7b-instruct",
161
+ "messages": [
162
+ {
163
+ "role": "system",
164
+ "content": "คุณคือผู้ช่วยตอบคำถามที่ฉลาดและซื่อสัตย์"
165
+ },
166
+ {
167
+ "role": "user",
168
+ "content": "สวัสดี"
169
+ }
170
+ ]
171
+ }'
172
+ ```
173
+
174
+ ### OpenAI Client Library (Hosted by VLLM, please see below.)
175
+ ```python
176
+ import openai
177
+
178
+ # Configure OpenAI client to use vLLM server
179
+ openai.api_base = "http://127.0.0.1:8000/v1"
180
+ openai.api_key = "dummy" # vLLM doesn't require a real API key
181
+
182
+ prompt = "<|im_start|>system\nคุณคือผู้ช่วยตอบคำถามที่ฉลาดและซื่อสัตย์<|im_end|>\n<|im_start|>user\nกรุงเทพมหานครคืออะไร<|im_end|>\n<|im_start|>assistant\n"
183
+
184
+ try:
185
+ response = openai.Completion.create(
186
+ model=".", # Specify the model you're using with vLLM
187
+ prompt=prompt,
188
+ max_tokens=512,
189
+ temperature=0.7,
190
+ top_p=0.8,
191
+ top_k=40,
192
+ stop=["<|im_end|>"]
193
+ )
194
+ print("Generated Text:", response.choices[0].text)
195
+ except Exception as e:
196
+ print("Error:", str(e))
197
+ ```
198
+
199
+
200
+ ### Huggingface
201
+ ```python
202
+ from transformers import AutoModelForCausalLM, AutoTokenizer
203
+
204
+ model_name = "openthaigpt/openthaigpt1.5-72b-instruct"
205
+
206
+ model = AutoModelForCausalLM.from_pretrained(
207
+ model_name,
208
+ torch_dtype="auto",
209
+ device_map="auto"
210
+ )
211
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
212
+
213
+ prompt = "ประเทศไทยคืออะไร"
214
+ messages = [
215
+ {"role": "system", "content": "คุณคือผู้ช่วยตอบคำถามที่ฉลาดและซื่อสัตย์"},
216
+ {"role": "user", "content": prompt}
217
+ ]
218
+ text = tokenizer.apply_chat_template(
219
+ messages,
220
+ tokenize=False,
221
+ add_generation_prompt=True
222
+ )
223
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
224
+
225
+ generated_ids = model.generate(
226
+ **model_inputs,
227
+ max_new_tokens=512
228
+ )
229
+ generated_ids = [
230
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
231
+ ]
232
+
233
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
234
+ ```
235
+
236
+ ### vLLM
237
+
238
+ 1. Install VLLM (https://github.com/vllm-project/vllm)
239
+
240
+ 2. Run server
241
+ ```bash
242
+ vllm serve openthaigpt/openthaigpt1.5-72b-instruct --tensor-parallel-size 4
243
+ ```
244
+ * Note, change ``--tensor-parallel-size 4`` to the amount of available GPU cards.
245
+
246
+ 3. Run inference (CURL example)
247
+ ```bash
248
+ curl -X POST 'http://127.0.0.1:8000/v1/completions' \
249
+ -H 'Content-Type: application/json' \
250
+ -d '{
251
+ "model": ".",
252
+ "prompt": "<|im_start|>system\nคุณคือผู้ช่วยตอบคำถามที่ฉลาดและซื่อสัตย์<|im_end|>\n<|im_start|>user\nสวัสดีครับ<|im_end|>\n<|im_start|>assistant\n",
253
+ "max_tokens": 512,
254
+ "temperature": 0.7,
255
+ "top_p": 0.8,
256
+ "top_k": 40,
257
+ "stop": ["<|im_end|>"]
258
+ }'
259
+ ```
260
+
261
+ ### Processing Long Texts
262
+ The current `config.json` is set for context length up to 32,768 tokens.
263
+ To handle extensive inputs exceeding 32,768 tokens, we utilize [YaRN](https://arxiv.org/abs/2309.00071), a technique for enhancing model length extrapolation, ensuring optimal performance on lengthy texts.
264
+
265
+ For supported frameworks, you could add the following to `config.json` to enable YaRN:
266
+ ```json
267
+ {
268
+ ...
269
+ "rope_scaling": {
270
+ "factor": 4.0,
271
+ "original_max_position_embeddings": 32768,
272
+ "type": "yarn"
273
+ }
274
+ }
275
+ ```
276
+
277
+
278
+ ### Tool Calling
279
+ The Tool Calling feature in OpenThaiGPT 1.5 enables users to efficiently call various functions through intelligent responses. This includes making external API calls to retrieve real-time data, such as current temperature information, or predicting future data simply by submitting a query.
280
+ For example, a user can ask OpenThaiGPT, “What is the current temperature in San Francisco?” and the AI will execute a pre-defined function to provide an immediate response without the need for additional coding.
281
+ This feature also allows for broader applications with external data sources, including the ability to call APIs for services such as weather updates, stock market information, or data from within the user’s own system.
282
+
283
+ #### Example:
284
+ ```python
285
+ import openai
286
+
287
+ def get_temperature(location, date=None, unit="celsius"):
288
+ """Get temperature for a location (current or specific date)."""
289
+ if date:
290
+ return {"temperature": 25.9, "location": location, "date": date, "unit": unit}
291
+ return {"temperature": 26.1, "location": location, "unit": unit}
292
+
293
+ tools = [
294
+ {
295
+ "name": "get_temperature",
296
+ "description": "Get temperature for a location (current or by date).",
297
+ "parameters": {
298
+ "location": "string", "date": "string (optional)", "unit": "enum [celsius, fahrenheit]"
299
+ },
300
+ }
301
+ ]
302
+
303
+ messages = [{"role": "user", "content": "อุณหภูมิที่ San Francisco วันนี้ีและพรุ้่งนี้คือเท่าไร่?"}]
304
+
305
+ # Simulated response flow using OpenThaiGPT Tool Calling
306
+ response = openai.ChatCompletion.create(
307
+ model=".", messages=messages, tools=tools, temperature=0.7, max_tokens=512
308
+ )
309
+
310
+ print(response)
311
+ ```
312
+ **Full example**: https://github.com/OpenThaiGPT/openthaigpt1.5_api_examples/blob/main/api_tool_calling_powered_by_siamai.py
313
+
314
+ ### GPU Memory Requirements
315
+ | **Number of Parameters** | **FP 16 bits** | **8 bits (Quantized)** | **4 bits (Quantized)** | **Example Graphic Card for 4 bits** |
316
+ |------------------|----------------|------------------------|------------------------|---------------------------------------------|
317
+ | **7b** | 24 GB | 12 GB | 6 GB | Nvidia RTX 4060 8GB |
318
+ | **13b** | 48 GB | 24 GB | 12 GB | Nvidia RTX 4070 16GB |
319
+ | **72b** | 192 GB | 96 GB | 48 GB | Nvidia RTX 4090 24GB x 2 cards |
320
+
321
+ ### Authors
322
+ * Sumeth Yuenyong (sumeth.yue@mahidol.edu)
323
+ * Kobkrit Viriyayudhakorn (kobkrit@aieat.or.th)
324
+ * Apivadee Piyatumrong (apivadee.piy@nectec.or.th)
325
+ * Jillaphat Jaroenkantasima (autsadang41@gmail.com)
326
+ * Thaweewat Rugsujarit (thaweewr@scg.com)
327
+ * Norapat Buppodom (new@norapat.com)
328
+ * Koravich Sangkaew (kwankoravich@gmail.com)
329
+ * Peerawat Rojratchadakorn (peerawat.roj@gmail.com)
330
+ * Surapon Nonesung (nonesungsurapon@gmail.com)
331
+ * Chanon Utupon (chanon.utupon@gmail.com)
332
+ * Sadhis Wongprayoon (sadhis.tae@gmail.com)
333
+ * Nucharee Thongthungwong (nuchhub@hotmail.com)
334
+ * Chawakorn Phiantham (mondcha1507@gmail.com)
335
+ * Patteera Triamamornwooth (patt.patteera@gmail.com)
336
+ * Nattarika Juntarapaoraya (natt.juntara@gmail.com)
337
+ * Kriangkrai Saetan (kraitan.ss21@gmail.com)
338
+ * Pitikorn Khlaisamniang (pitikorn32@gmail.com)
339
+
340
+ <i>Disclaimer: Provided responses are not guaranteed.</i>
openthaigpt1.5-7b-instruct.Q4_0.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:37b631a8888fdd47c7a122afd3bfb4fccfd24036d2e05ac81c0f25b734a2b59e
3
+ size 4431390848