nxphi47 commited on
Commit
dbfd674
1 Parent(s): 5d4c0d0

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +288 -1
README.md CHANGED
@@ -16,4 +16,291 @@ language:
16
  tags:
17
  - multilingual
18
  - sea
19
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  tags:
17
  - multilingual
18
  - sea
19
+ ---
20
+
21
+ <p align="center">
22
+ <img src="seal_logo.png" width="200" />
23
+ </p>
24
+
25
+ # *SeaLLM-7B-v2* - Large Language Models for Southeast Asia
26
+
27
+ <p align="center">
28
+ <a href="https://huggingface.co/SeaLLMs/SeaLLM-7B-v2.5" target="_blank" rel="noopener"> 🤗 Tech Memo</a>
29
+ &nbsp;&nbsp;
30
+ <a href="https://huggingface.co/spaces/SeaLLMs/SeaLLM-7B" target="_blank" rel="noopener"> 🤗 DEMO</a>
31
+ &nbsp;&nbsp;
32
+ <a href="https://github.com/DAMO-NLP-SG/SeaLLMs" target="_blank" rel="noopener">Github</a>
33
+ &nbsp;&nbsp;
34
+ <a href="https://arxiv.org/pdf/2312.00738.pdf" target="_blank" rel="noopener">Technical Report</a>
35
+ </p>
36
+
37
+ We introduce [SeaLLM-7B-v2.5](https://huggingface.co/SeaLLMs/SeaLLM-7B-v2.5), the state-of-the-art multilingual LLM for Southeast Asian (SEA) languages 🇬🇧 🇨🇳 🇻🇳 🇮🇩 🇹🇭 🇲🇾 🇰🇭 🇱🇦 🇲🇲 🇵🇭. It is the most significant upgrade since [SeaLLM-13B](https://huggingface.co/SeaLLMs/SeaLLM-13B-Chat), with half the size, outperforming performance across diverse multilingual tasks, from world knowledge, math reasoning, instruction following, etc.
38
+
39
+ ### Highlights
40
+ * [SeaLLM-7B-v2.5](https://huggingface.co/SeaLLMs/SeaLLM-7B-v2.5) outperforms GPT-3.5 on most knowledge benchmarks....
41
+ * It achieves 79.0 and 34.9 on GSM8K and MATH.
42
+
43
+ ### Release and DEMO
44
+
45
+ - DEMO: [SeaLLMs/SeaLLM-7B](https://huggingface.co/spaces/SeaLLMs/SeaLLM-7B).
46
+ - Technical report: [Arxiv: SeaLLMs - Large Language Models for Southeast Asia](https://arxiv.org/pdf/2312.00738.pdf).
47
+ - Model weights:
48
+ - [SeaLLM-7B-v2](https://huggingface.co/SeaLLMs/SeaLLM-7B-v2).
49
+ - [SeaLLM-7B-v2-gguf](https://huggingface.co/SeaLLMs/SeaLLM-7B-v2-gguf).
50
+ - [SeaLLM-7B-v2-GGUF (thanks Lonestriker)](https://huggingface.co/LoneStriker/SeaLLM-7B-v2-GGUF). NOTE: use [seallm.preset.json](https://huggingface.co/SeaLLMs/SeaLLM-7B-v2-gguf/blob/main/seallm.preset.json) to work properly.
51
+ - Run locally:
52
+ - [LM-studio](https://lmstudio.ai/):
53
+ - [SeaLLM-7B-v2-q4_0](https://huggingface.co/SeaLLMs/SeaLLM-7B-v2-gguf/blob/main/SeaLLM-7B-v2.q4_0.gguf) and [SeaLLM-7B-v2-q8_0](https://huggingface.co/SeaLLMs/SeaLLM-7B-v2-gguf/blob/main/SeaLLM-7B-v2.q8_0.gguf).
54
+ - LM-studio requires this [seallm.preset.json](https://huggingface.co/SeaLLMs/SeaLLM-7B-v2-gguf/blob/main/seallm.preset.json) to set chat template properly.
55
+ - [ollama](https://ollama.ai/) `ollama run nxphi47/seallm-7b-v2:q4_0`
56
+ - [MLX for Apple Silicon](https://github.com/ml-explore/mlx): [mlx-community/SeaLLM-7B-v2-4bit-mlx](https://huggingface.co/mlx-community/SeaLLM-7B-v2-4bit-mlx)
57
+
58
+ <blockquote style="color:red">
59
+ <p><strong style="color: red">Terms of Use and License</strong>:
60
+ By using our released weights, codes, and demos, you agree to and comply with the terms and conditions specified in our <a href="https://huggingface.co/SeaLLMs/SeaLLM-Chat-13b/edit/main/LICENSE" target="_blank" rel="noopener">SeaLLMs Terms Of Use</a>.
61
+ </blockquote>
62
+
63
+ > **Disclaimer**:
64
+ > We must note that even though the weights, codes, and demos are released in an open manner, similar to other pre-trained language models, and despite our best efforts in red teaming and safety fine-tuning and enforcement, our models come with potential risks, including but not limited to inaccurate, misleading or potentially harmful generation.
65
+ > Developers and stakeholders should perform their own red teaming and provide related security measures before deployment, and they must abide by and comply with local governance and regulations.
66
+ > In no event shall the authors be held liable for any claim, damages, or other liability arising from the use of the released weights, codes, or demos.
67
+
68
+ > The logo was generated by DALL-E 3.
69
+
70
+
71
+ ### What's new since SeaLLM-7B-v2?
72
+
73
+ * SeaLLM-7B-v2.5 was built on top of Gemma-7b, and underwent large scale SFT and carefully designed alignment.
74
+
75
+
76
+ ## Evaluation
77
+
78
+
79
+ ### Multilingual World Knowledge
80
+
81
+
82
+ We evaluate models on 3 benchmarks following the recommended default setups: 5-shot MMLU for En, 3-shot [M3Exam](https://arxiv.org/pdf/2306.05179.pdf) (M3e) for En, Zh, Vi, Id, Th, and zero-shot [VMLU](https://vmlu.ai/) for Vi.
83
+
84
+ | Model | Langs | En<br>MMLU | En<br>M3e | Zh<br>M3e | Vi<br>M3e | Vi<br>VMLU | Id<br>M3e | Th<br>M3e
85
+ |-----| ----- | --- | -- | ----- | ---- | --- | --- | --- |
86
+ | GPT-3.5 | Multi | 68.90 | 75.46 | 60.20 | 58.64 | 46.32 | 49.27 | 37.41
87
+ | Vistral-7B-chat | Mono | 56.86 | 67.00 | 44.56 | 54.33 | 50.03 | 36.49 | 25.27
88
+ | Qwen1.5-7B-chat | Multi | 61.00 | 52.07 | 81.96 | 43.38 | 45.02 | 24.29 | 20.25
89
+ | SailorLM | Multi | 52.72 | 59.76 | 67.74 | 50.14 | --- | 39.53 | 37.73
90
+ | SeaLLM-7B-v2 | Multi | 61.89 | 70.91 | 55.43 | 51.15 | 45.74 | 42.25 | 35.52
91
+ | SeaLLM-7B-v2.5 | Multi | 64.05 | 76.87 | 62.54 | 63.11 | 53.30 | 48.64 | 46.86
92
+
93
+
94
+ ### MT-Bench
95
+
96
+ **SeaLLM-7B-v2.5 only score 7.40 on MT-bench, better preference tuning is needed**
97
+ On the English [MT-bench](https://arxiv.org/abs/2306.05685) metric, SeaLLM-7B-v2 achieves **7.54** score on the MT-bench (3rd place on the leaderboard for 7B category), outperforms many 70B models and is arguably the only one that handles 10 SEA languages.
98
+
99
+ Refer to [mt_bench/seallm_7b_v2.jsonl](https://huggingface.co/SeaLLMs/SeaLLM-7B-v2/blob/main/evaluation/mt_bench/seallm_7b_v2.jsonl) for the MT-bench predictions of SeaLLM-7B-v2, and [here](https://github.com/lm-sys/FastChat/issues/3013#issue-2118685341) to reproduce it.
100
+
101
+ | Model | Access | Langs | MT-Bench
102
+ | --- | --- | --- | --- |
103
+ | GPT-4-turbo | closed | multi | 9.32
104
+ | GPT-4-0613 | closed | multi | 9.18
105
+ | Mixtral-8x7b (46B) | open | multi | 8.3
106
+ | Starling-LM-7B-alpha | open | mono (en) | 8.0
107
+ | OpenChat-3.5-7B | open | mono (en) | 7.81
108
+ | **SeaLLM-7B-v2** | **open** | **multi (10+)** | **7.54**
109
+ | **SeaLLM-7B-v2.5** | **open** | **multi (10+)** | **7.40**
110
+ | [Qwen-14B](https://huggingface.co/Qwen/Qwen-14B-Chat) | open | multi | 6.96
111
+ | [Llama-2-70B](https://huggingface.co/meta-llama/Llama-2-70b-chat-hf) | open | mono (en) | 6.86
112
+ | Mistral-7B-instuct | open | mono (en) | 6.84
113
+
114
+
115
+ ### Sea-Bench
116
+
117
+ Not ready
118
+
119
+
120
+
121
+ ### Usage
122
+
123
+ #### Instruction format
124
+
125
+ ```python
126
+ prompt = """<|im_start|>system
127
+ You are a helpful assistant.<eos>
128
+ <|im_start|>user
129
+ Hello world<eos>
130
+ <|im_start|>assistant
131
+ Hi there, how can I help?<eos>"""
132
+
133
+ # NOTE: previous commit has \n between </s> and <|im_start|>, that was incorrect!
134
+ # <|im_start|> is not a special token.
135
+ # Transformers chat_template should be consistent with vLLM format below.
136
+
137
+ # ! ENSURE 1 and only 1 bos `<s>` at the beginning of sequence
138
+ print(tokenizer.convert_ids_to_tokens(tokenizer.encode(prompt)))
139
+
140
+ """
141
+ ```
142
+
143
+ #### Using transformers's chat_template
144
+ ```python
145
+
146
+ from transformers import AutoModelForCausalLM, AutoTokenizer
147
+
148
+ device = "cuda" # the device to load the model onto
149
+
150
+ # use bfloat16 to ensure the best performance.
151
+ model = AutoModelForCausalLM.from_pretrained("SeaLLMs/SeaLLM-7B-v2", torch_dtype=torch.bfloat16, device_map=device)
152
+ tokenizer = AutoTokenizer.from_pretrained("SeaLLMs/SeaLLM-7B-v2")
153
+
154
+ messages = [
155
+ {"role": "system", "content": "You are a helpful assistant."},
156
+ {"role": "user", "content": "Hello world"},
157
+ {"role": "assistant", "content": "Hi there, how can I help you today?"},
158
+ {"role": "user", "content": "Explain general relativity in details."}
159
+ ]
160
+
161
+ encodeds = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True)
162
+ print(tokenizer.convert_ids_to_tokens(encodeds[0]))
163
+ # ['<s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'system', '<0x0A>', 'You', '▁are', '▁a', '▁helpful', '▁assistant', '.', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'user', '<0x0A>', 'Hello', '▁world', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'ass', 'istant', '<0x0A>', 'Hi', '▁there', ',', '▁how', '▁can', '▁I', '▁help', '▁you', '▁today', '?', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'user', '<0x0A>', 'Ex', 'plain', '▁general', '▁rel', 'ativity', '▁in', '▁details', '.', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'ass', 'istant', '<0x0A>']
164
+
165
+ model_inputs = encodeds.to(device)
166
+ model.to(device)
167
+
168
+ generated_ids = model.generate(model_inputs, max_new_tokens=1000, do_sample=True, pad_token_id=tokenizer.pad_token_id)
169
+ decoded = tokenizer.batch_decode(generated_ids)
170
+ print(decoded[0])
171
+
172
+ ```
173
+
174
+ #### Using vLLM
175
+
176
+ ```python
177
+ from vllm import LLM, SamplingParams
178
+ TURN_TEMPLATE = "<|im_start|>{role}\n{content}</s>"
179
+ TURN_PREFIX = "<|im_start|>{role}\n"
180
+
181
+ # There is no \n between </s> and <|im_start|>.
182
+
183
+ def seallm_chat_convo_format(conversations, add_assistant_prefix: bool, system_prompt=None):
184
+ # conversations: list of dict with key `role` and `content` (openai format)
185
+ if conversations[0]['role'] != 'system' and system_prompt is not None:
186
+ conversations = [{"role": "system", "content": system_prompt}] + conversations
187
+ text = ''
188
+ for turn_id, turn in enumerate(conversations):
189
+ prompt = TURN_TEMPLATE.format(role=turn['role'], content=turn['content'])
190
+ text += prompt
191
+ if add_assistant_prefix:
192
+ prompt = TURN_PREFIX.format(role='assistant')
193
+ text += prompt
194
+ return text
195
+
196
+ sparams = SamplingParams(temperature=0.1, max_tokens=1024, stop=['</s>', '<|im_start|>'])
197
+ llm = LLM("SeaLLMs/SeaLLM-7B-v2", dtype="bfloat16")
198
+
199
+ message = "Explain general relativity in details."
200
+ prompt = seallm_chat_convo_format(message, True)
201
+ gen = llm.generate(prompt, sampling_params)
202
+
203
+ print(gen[0].outputs[0].text)
204
+ ```
205
+
206
+ #### Fine-tuning SeaLLM-7B-v2
207
+
208
+ Should follow the chat format and accurately mask out source tokens. Here is an example.
209
+
210
+ ```python
211
+ conversations = [
212
+ {"role": "system", "content": "You are helful assistant."},
213
+ {"role": "user", "content": "Hello world."},
214
+ {"role": "assistant", "content": "Hi there, how can I help?"},
215
+ {"role": "user", "content": "Tell me a joke."},
216
+ {"role": "assistant", "content": "Why don't scientists trust atoms? Because they make up everything."},
217
+ ]
218
+ def seallm_7b_v2_tokenize_multi_turns(tokenizer, conversations, add_assistant_prefix=False):
219
+ """
220
+ Inputs:
221
+ conversations: list of dict following openai format, eg
222
+ conversations = [
223
+ {"role": "system", "content": "You are helful assistant."},
224
+ {"role": "user", "content": "Hello world."},
225
+ {"role": "assistant", "content": "Hi there, how can I help?"},
226
+ {"role": "user", "content": "Tell me a joke."},
227
+ {"role": "assistant", "content": "Why don't scientists trust atoms? Because they make up everything."},
228
+ ]
229
+ add_assistant_prefix: whether to add assistant_prefix, only for inference decoding
230
+ Outputs:
231
+ tokenize_output_sample, {
232
+ "input_ids": ...
233
+ "token_type_ids": 1 if train and 0 if masked out (not train)
234
+ }
235
+ During training, need to create a labels, with masked-out tokens = -100 to avoid loss computations.
236
+ labels = sample['input_ids'].clone()
237
+ labels[sample['token_type_ids'] == 0] = -100
238
+ """
239
+ TURN_TEMPLATE = "<|im_start|>{role}\n{content}</s>"
240
+ TURN_PREFIX = "<|im_start|>{role}\n"
241
+ sample = None
242
+ assistant_prefix_len = None
243
+ for turn_id, turn in enumerate(conversations):
244
+ prompt = TURN_TEMPLATE.format(role=turn['role'], content=turn['content'])
245
+ turn_sample = tokenizer(
246
+ prompt, padding=False, truncation=False, verbose=False, add_special_tokens=False,
247
+ return_token_type_ids=True,
248
+ )
249
+ if turn['role'] == 'assistant':
250
+ if assistant_prefix_len is None:
251
+ assistant_prefix_len = len(tokenizer.encode(TURN_PREFIX.format(role=turn['role']), add_special_tokens=False))
252
+ turn_sample['token_type_ids'][assistant_prefix_len:] = [1] * (len(turn_sample['input_ids']) - assistant_prefix_len)
253
+ if sample is None:
254
+ sample = turn_sample
255
+ else:
256
+ for k in turn_sample.keys():
257
+ sample[k].extend(turn_sample[k])
258
+ if add_assistant_prefix:
259
+ assistant_prefix_sample = tokenizer(
260
+ TURN_PREFIX.format(role="assistant"), padding=False, truncation=False, verbose=False, add_special_tokens=False,
261
+ return_token_type_ids=True,
262
+ )
263
+ for k in sample.keys():
264
+ sample[k].extend(assistant_prefix_sample[k])
265
+ if tokenizer.add_bos_token:
266
+ sample['input_ids'] = [tokenizer.bos_token_id] + sample['input_ids']
267
+ sample['attention_mask'] = [1] + sample['attention_mask']
268
+ sample['token_type_ids'] = [sample['token_type_ids'][0]] + sample['token_type_ids']
269
+ return sample
270
+
271
+ # ! testing
272
+ sample = seallm_7b_v2_tokenize_multi_turns(tokenizer, conversations)
273
+ print(tokenizer.convert_ids_to_tokens(sample['input_ids']))
274
+ print(sample['token_type_ids'])
275
+ # ['<s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'system', '<0x0A>', 'You', '▁are', '▁hel', 'ful', '▁assistant', '.', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'user', '<0x0A>', 'Hello', '▁world', '.', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'ass', 'istant', '<0x0A>', 'Hi', '▁there', ',', '▁how', '▁can', '▁I', '▁help', '?', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'user', '<0x0A>', 'Tell', '▁me', '▁a', '▁joke', '.', '</s>', '▁<', '|', 'im', '_', 'start', '|', '>', 'ass', 'istant', '<0x0A>', 'Why', '▁don', "'", 't', '▁scientists', '▁trust', '▁atoms', '?', '▁Because', '▁they', '▁make', '▁up', '▁everything', '.', '</s>']
276
+ # [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
277
+
278
+
279
+
280
+ ```
281
+
282
+
283
+ ## Acknowledgement to Our Linguists
284
+
285
+ We would like to express our special thanks to our professional and native linguists, Tantong Champaiboon, Nguyen Ngoc Yen Nhi and Tara Devina Putri, who helped build, evaluate, and fact-check our sampled pretraining and SFT dataset as well as evaluating our models across different aspects, especially safety.
286
+
287
+ ## Citation
288
+
289
+ If you find our project useful, we hope you would kindly star our repo and cite our work as follows: Corresponding Author: [l.bing@alibaba-inc.com](mailto:l.bing@alibaba-inc.com)
290
+
291
+ **Author list and order will change!**
292
+
293
+ * `*` and `^` are equal contributions.
294
+
295
+ ```
296
+ @article{damonlpsg2023seallm,
297
+ author = {Xuan-Phi Nguyen*, Wenxuan Zhang*, Xin Li*, Mahani Aljunied*,
298
+ Zhiqiang Hu, Chenhui Shen^, Yew Ken Chia^, Xingxuan Li, Jianyu Wang,
299
+ Qingyu Tan, Liying Cheng, Guanzheng Chen, Yue Deng, Sen Yang,
300
+ Chaoqun Liu, Hang Zhang, Lidong Bing},
301
+ title = {SeaLLMs - Large Language Models for Southeast Asia},
302
+ year = 2023,
303
+ Eprint = {arXiv:2312.00738},
304
+ }
305
+ ```
306
+