Edit model card

ChatGLM3-6B是一个中英双语大模型,本项目为ChatGLM3-6B加入日文能力。
通过sentencepiece在日文wiki和青空文库上训练BPE的tokenizer,词表扩充14000(64789 -> 78554),相比原生ChatGLM3的日文编码效率提升接近一倍,中文英文编码效率不变。

共有两个模型:

  • ChatGLM3-Japanese-Zero:本模型,经过扩词表和resize后的模型,保留了ChatGLM3的中英文能力,尚无日文能力,但因为编码效率高,适合在日文语料上训练。
  • ChatGLM3-Japanese:对ChatGLM3-Japanese-Zero进行日文语料增量预训练和指令微调的模型,可以日文对话。

GitHub上有全流程的代码,包含训练tokenizer和训练模型。

使用样例:

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("dummy-foo/ChatGLM3-Japanese-Zero", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("dummy-foo/ChatGLM3-Japanese-Zero", trust_remote_code=True, device_map='cuda:0', torch_dtype=torch.float16)

# test Chinese chat, 预期得到和原生模型相同效果的答案
response, _ = model.chat(tokenizer, "你是谁", history=[])
print("\nQ:你是谁,A:", response)
response, _ = model.chat(tokenizer, "你喜欢甜粽子还是咸粽子", history=[])
print("\nQ:你喜欢甜粽子还是咸粽子,A:", response)

# test Japanese chat, まったく無意味な答えが得られるでしょう
response, _ = model.chat(tokenizer, "あなたは誰ですか", history=[])
print("\nQ:あなたは誰ですか,A:", response)
response, _ = model.chat(tokenizer, "すみません、ちょっとお聞きしたいことがあるんですが", history=[])
print("\nQ:すみません、ちょっとお聞きしたいことがあるんですが,A:", response)

# test Japanese tokenizer
print("\ntokens: ", tokenizer.tokenize("恥の多い生涯を送って来ました。自分には、人間の生活というものが、見当つかないのです。"))

分词结果都是一些有意义的token:

['▁', '恥', 'の多い', '生涯', 'を送', 'って', '来ました', '。', '自分に', 'は', '、', '人間の', '生活', 'というもの', 'が', '、', '見', '当', 'つかない', 'のです', '。']

而原生ChatGLM3的分词结果,除了“生涯”和“生活”因为和中文重合而成为词组外,其他的都被单独切分。

['▁', '恥', 'の', '多', 'い', '生涯', 'を', '送', 'っ', 'て', '来', 'ま', 'し', 'た', '。', '自', '分', 'に', 'は', '、', '人', '間', 'の', '生活', 'と', 'い', 'う', 'も', 'の', 'が', '、', '見', '当', 'つ', 'か', 'な', 'い', 'の', 'で', 'す', '。']

更多分词效率对比见GitHub仓库,结论大致为:原生ChatGLM3平均对1个日文汉字或假名切分为1个token,ChatGLM3-Japanese-Zero只切分成0.54个token,编码效率接近翻倍,大大提升日文的训练和推理效率。

Downloads last month
3
Safetensors
Model size
6.35B params
Tensor type
FP16
·
Inference Examples
Input a message to start chatting with dummy-foo/ChatGLM3-Japanese-Zero.
Inference API (serverless) does not yet support model repos that contain custom code.