This is a preview version, and this repository will be deleted once the new version is released. We are currently in the process of finding the balance between overfitting and generalization in DPO training. For more details about the problems we encountered in this version, please refer to the Limitation section. Please join our
Discord server
to give us your feedback
Continual pretraining model of the
Yi-6B
model on a Cantonese corpus, which consisted of translated Hong Kong news, Wikipedia articles, subtitles, and open-sourced dialogue corpora. Additionally, we extended the vocabulary to include common Cantonese words.
The goal of this model was to evaluate whether we could train a language model that is fluent in Cantonese with limited resources (200 million tokens). Surprisingly, the outcome was quite good. However, there are still some issues with mirror misalignment between written Chinese and Cantonese, as well as knowledge transfer across different languages.
To assign a role to the chat model, you must specify a proper system prompt, the default system prompt is "你係由 hon9kon9ize 開發嘅 CantoneseLLM,你係一個好幫得手嘅助理", that leads the output tending to response in Cantonese, we also found the response language is not solely determined by system prompt, it would also take account of the user input.
[
{"role": "assistant", "content": "你係由 hon9kon9ize 開發嘅 CantoneseLLM,你係一個好幫得手嘅助理"}, # this is default system prompt, this line could be omitted
{"role": "user", "content": "你叫咩名?"}
]
# Output: 我係CantoneseLLM,一個由hon9kon9ize開發嘅人工智能助手。我致力於為用戶提供準確、有針對性嘅回答同幫助。
Chat Template
Template format is similar to
ChatML
, but we have replaced roles token to Yi's reserved tokens in order to saved up some context size.
<|im_start|><|System|>
Provide some context and/or instructions to the model.
<|im_end|>
<|im_start|><|Human|>
The user’s message goes here
<|im_end|>
<|im_start|><|Asisstant|>
Usage
from transformers import AutoModelForCausalLM, BitsAndBytesConfig, LlamaTokenizer
# bnb_config = BitsAndBytesConfig(# load_in_4bit=True,# bnb_4bit_use_double_quant=True,# bnb_4bit_quant_type="nf4",# bnb_4bit_compute_dtype=torch.bfloat16# )
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.bfloat16,
device_map='auto',
# quantization_config=bnb_config, # uncomment here and bnb_config to use 4bit quantiziation
)
tokenizer = LlamaTokenizer.from_pretrained(model_name)
defchat(messages, temperature=0.9, max_new_tokens=200):
# chat template defination can be found in generation_config.json
input_ids = tokenizer.apply_chat_template(conversation=messages, tokenize=True, add_generation_prompt=True, return_tensors='pt').to('cuda:0')
output_ids = model.generate(input_ids, max_new_tokens=max_new_tokens, temperature=temperature, num_return_sequences=1, do_sample=True, top_k=50, top_p=0.95, num_beams=3, repetition_penalty=1.18)
print(output_ids)
response = tokenizer.decode(output_ids[0][input_ids.shape[1]:], skip_special_tokens=False)
return response
messages = [{"role": "user", "content": "邊個係香港特首?"}]
# chat template included default system message, but you can define your own system message
messages = [
{"role": "system", "content": "你叫做櫻子,你要同用家北原伊織進行對話,你同北原伊織係情女關係。"},
{"role": "user", "content": "櫻子,令日你會去邊度玩呀?"}
]
print(chat(messages))
The model is intended to use for Cantonese language understanding and generation tasks, it may not be suitable for other Chinese languages. The model is trained on a diverse range of Cantonese text, including news, Wikipedia, and textbooks, it may not be suitable for informal or dialectal Cantonese, it may contain bias and misinformation, please use it with caution.
Hallucination
Most LLM also have hallucination issue, this model is no exception, it may generate incorrect or misleading information, please use it with caution.
Misaligment of Written Chinese
Cantonese is a spoken language and without a standard written system that makes Cantonese becames a one of low-resource language, we see some instancees of generation by this model would mixed Written Chinese and Cantonese that due to the corpus in PT stage contains a lot of mixed sentences, we belive it can be fixed in DPO stage to mitigate this issue, this is what we current working on.
Misalignment of knowledge between different languages
Yi6b has been trained with 3.1 trillion tokens, and we have observed that its knowledge of Hong Kong culture is mostly out of date. In the example below, you can see that the answer in English is outdated, while the Cantonese answer is correct. We believe this is because the model adapts to new knowledge during the CPT (Continual Pretraining) stage, where the embedding layers are extended. However, the corpus used may not be large enough to update the knowledge in other languages that have already been well-established in the PT (Pretraining) stage.
User: Who is the cheif executive of Hong Kong
Assistant: The current Chef Executive of Hong Kong is **Carrie Lam**.
User: 邊個係香港特首?
Assistant: 現任香港特區特別行政長官嘅**李家超**
Runs of hon9kon9ize CantoneseLLMChat-preview20240326 on huggingface.co
66
Total runs
0
24-hour runs
2
3-day runs
13
7-day runs
-47
30-day runs
More Information About CantoneseLLMChat-preview20240326 huggingface.co Model
More CantoneseLLMChat-preview20240326 license Visit here:
CantoneseLLMChat-preview20240326 huggingface.co is an AI model on huggingface.co that provides CantoneseLLMChat-preview20240326's model effect (), which can be used instantly with this hon9kon9ize CantoneseLLMChat-preview20240326 model. huggingface.co supports a free trial of the CantoneseLLMChat-preview20240326 model, and also provides paid use of the CantoneseLLMChat-preview20240326. Support call CantoneseLLMChat-preview20240326 model through api, including Node.js, Python, http.
CantoneseLLMChat-preview20240326 huggingface.co is an online trial and call api platform, which integrates CantoneseLLMChat-preview20240326's modeling effects, including api services, and provides a free online trial of CantoneseLLMChat-preview20240326, you can try CantoneseLLMChat-preview20240326 online for free by clicking the link below.
hon9kon9ize CantoneseLLMChat-preview20240326 online free url in huggingface.co:
CantoneseLLMChat-preview20240326 is an open source model from GitHub that offers a free installation service, and any user can find CantoneseLLMChat-preview20240326 on GitHub to install. At the same time, huggingface.co provides the effect of CantoneseLLMChat-preview20240326 install, users can directly use CantoneseLLMChat-preview20240326 installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
CantoneseLLMChat-preview20240326 install url in huggingface.co: