Ko-Gemma-2-9B-IT是Gemma模型系列中的一款韩语对话模型,基于google/gemma-2-9b-it进行监督微调(SFT)和直接偏好优化(DPO)训练,专门针对韩语文本生成任务优化。
下载量 3,467
发布时间 : 7/11/2024
模型介绍
内容详情
替代品
模型简介
这是一个仅解码器的大型语言模型,专为韩语文本到文本任务设计,支持问答、总结和推理等多种文本生成场景。
模型特点
韩语优化
基于高质量韩语数据集进行监督微调和直接偏好优化训练,专门针对韩语文本生成任务优化。
轻量级设计
相对较小的体积使其能够在资源有限的环境中部署,如笔记本电脑、台式机或自有云基础设施。
多任务支持
支持问答、总结、推理等多种文本生成任务,适用于广泛的韩语应用场景。
模型能力
韩语文本生成
问答系统
文本总结
逻辑推理
对话系统
使用案例
旅游服务
旅游路线规划
根据用户需求生成个性化的旅游路线建议
示例:生成包含首尔著名景点的观光路线
教育辅助
学习辅导
回答学生提出的各类学科问题
许可证:gemma
库名称:transformers
流水线标签:文本生成
额外授权标题:在Hugging Face上访问Gemma
额外授权提示:要在Hugging Face上访问Gemma,您需要审阅并同意谷歌的使用许可。为此,请确保您已登录Hugging Face并点击下方。请求将立即处理。
额外授权按钮内容:确认许可
标签:
- 对话式
基础模型:
- google/gemma-2-9b
语言:
- 韩语
## 模型详情
### Ko-Gemma-2-9B-IT
**[Ko-Gemma-2-9B-IT](https://huggingface.co/rtzr/ko-gemma-2-9b-it)** 是Gemma模型系列中的一款韩语对话模型。它是一个仅解码器的大型语言模型,专为文本到文本任务设计,支持韩语。我们通过监督微调(SFT)在精心筛选的高质量数据集上对该模型进行了微调,并特别针对人类反馈使用了[直接偏好优化](https://arxiv.org/abs/2305.18290)训练。所用数据集包括:
- [Orca-Math](https://huggingface.co/datasets/kuotient/orca-math-korean-dpo-pairs)
- [dpo-mix-7k](https://huggingface.co/datasets/argilla/dpo-mix-7k)
部分数据集在训练过程中进行了翻译和使用。翻译过程中出现了大量重复内容,因此基于N-gram进行了预处理。
#### *输入与输出*
- **输入:** 文本字符串,如问题、提示或待总结的文档。
- **输出:** 生成的韩语文本,作为对输入的响应,如问题答案或文档摘要。
### Google Gemma 2
Gemma是谷歌推出的一系列轻量级、前沿的开源模型,基于与创建Gemini模型相同的研究和技术构建。它们是仅解码器的大型语言模型,支持英语,提供预训练和指令调优变体的开放权重。Gemma模型适用于多种文本生成任务,包括问答、总结和推理。其相对较小的体积使其能够在资源有限的环境中部署,如笔记本电脑、台式机或自有云基础设施,从而普及先进AI模型,促进创新。
## 基准分数
我们使用[LogicKor](https://github.com/instructkr/LogicKor)代码进行了内部评估。公开的LogicKor代码评估基于GPT-4,而我们的内部评估基于GPT-4o。公开分数将在发布后补充。以下分数仅包含零样本评估。
| 模型 | 数学 | 推理 | 写作 | 编码 | 理解 | 语法 | 单任务综合 | 多任务综合 | 总体 |
|:---------:|:-----:|:------:|:-----:|:-----:|:----:|:-----:|:-----:|:-----:|:----:|
| [rtzr/ko-gemma-2-9b-it](https://huggingface.co/rtzr/ko-gemma-2-9b-it) | 8.71 / 8.00 | 9.14 / 8.00 | 9.43 / 9.29 | 9.00 / 9.43 | 9.57 / 9.86 | 7.14 / 5.00 | 8.83 | 8.26 | 8.55 |
| [google/gemma-2-9b-it](https://huggingface.co/google/gemma-2-9b-it) | 8.57 / 7.71 | 8.86 / 7.00 | 9.29 / 9.29 | 9.29 / 9.57 | 8.57 / 8.29 | 6.86 / 3.86 | 8.57 | 7.62 | 8.10 |
| [MLP-KTLim/llama-3-Korean-Bllossom-8B](https://huggingface.co/MLP-KTLim/llama-3-Korean-Bllossom-8B) | 6.43 / 5.71 | 6.86 / 5.14 | 9.14 / 8.57 | 8.29 / 8.14 | 8.43 / 9.29 | 5.71 / 5.29 | 7.48 | 7.02 | 7.25 |
| [yanolja/EEVE-Korean-Instruct-10.8B-v1.0](https://huggingface.co/yanolja/EEVE-Korean-Instruct-10.8B-v1.0) | 5.57 / 4.29 | 8.14 / 5.14 | 8.29 / 6.29 | 6.43 / 7.86 | 9.29 / 8.57 | 6.57 / 3.71 | 7.38 | 5.98 | 6.68 |
| [allganize/Llama-3-Alpha-Ko-8B-Instruct](https://huggingface.co/allganize/Llama-3-Alpha-Ko-8B-Instruct) | 4.57 / 3.00 | 6.86 / 6.43 | 7.43 / 6.71 | 8.43 / 8.43| 7.71 / 8.71 | 6.71 / 4.43 | 6.95 | 6.29 | 6.62 |
## 使用方法
### 安装依赖
必须安装transformers >= 4.42.3以支持gemma2模型。
```bash
pip install transformers==4.42.3 accelerate
使用Pipeline的Python代码
import transformers
import torch
model_id = "rtzr/ko-gemma-2-9b-it"
pipeline = transformers.pipeline(
"text-generation",
model=model_id,
model_kwargs={"torch_dtype": torch.bfloat16},
device_map="auto",
)
pipeline.model.eval()
instruction = "서울의 유명한 관광 코스를 만들어줄래?"
messages = [
{"role": "user", "content": f"{instruction}"}
]
prompt = pipeline.tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
terminators = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<end_of_turn>")
]
outputs = pipeline(
prompt,
max_new_tokens=2048,
eos_token_id=terminators,
do_sample=True,
temperature=0.6,
top_p=0.9,
)
print(outputs[0]["generated_text"][len(prompt):])
使用AutoModel的Python代码
import os
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model_id = "rtzr/ko-gemma-2-9b-it"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="auto",
)
model.eval()
instruction = "서울의 유명한 관광 코스를 만들어줄래?"
messages = [
{"role": "user", "content": f"{instruction}"}
]
input_ids = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
return_tensors="pt"
).to(model.device)
terminators = [
tokenizer.eos_token_id,
tokenizer.convert_tokens_to_ids("<end_of_turn>")
]
outputs = model.generate(
input_ids,
max_new_tokens=2048,
eos_token_id=terminators,
do_sample=True,
temperature=0.6,
top_p=0.9,
)
print(tokenizer.decode(outputs[0][input_ids.shape[-1]:], skip_special_tokens=True))
通过bitsandbytes量化版本
- 使用8位精度
- 使用4位精度
# pip install bitsandbytes
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
model_id = "rtzr/ko-gemma-2-9b-it"
quantization_config_8bit = BitsAndBytesConfig(load_in_8bit=True)
# quantization_config_4bit = BitsAndBytesConfig(load_in_4bit=True)
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="auto",
quantization_config=quantization_config_8bit,
# quantization_config=quantization_config_4bit,
low_cpu_mem_usage=True,
)
model.eval()
instruction = "서울의 유명한 관광 코스를 만들어줄래?"
messages = [
{"role": "user", "content": f"{instruction}"}
]
input_ids = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
return_tensors="pt"
).to(model.device)
terminators = [
tokenizer.eos_token_id,
tokenizer.convert_tokens_to_ids("<end_of_turn>")
]
outputs = model.generate(
input_ids,
max_new_tokens=2048,
eos_token_id=terminators,
do_sample=True,
temperature=0.6,
top_p=0.9,
)
print(tokenizer.decode(outputs[0][input_ids.shape[-1]:], skip_special_tokens=True))
VLLM使用
使用vllm==0.5.1
时,gemma2模型尚无法加载,会出现以下问题。建议使用vllm/vllm-openai:latest
docker或vllm==0.5.0.post1
。
#!/bin/bash
VLLM_ATTENTION_BACKEND=FLASHINFER
MODEL_NAME="rtzr/ko-gemma-2-9b-it"
MODEL_PATH="YOUR_PATH/${MODEL_NAME}"
docker run --rm --gpus all \
-p 8000:8000 \
--shm-size=12gb --ulimit memlock=-1 --ulimit stack=67108864 \
-e VLLM_ATTENTION_BACKEND=${VLLM_ATTENTION_BACKEND} \
-v $MODEL_PATH:/vllm-workspace/${MODEL_NAME} \
vllm/vllm-openai:latest \
--model ${MODEL_NAME} --dtype auto \
--gpu-memory-utilization 0.8
许可证
Gemma 2许可证:https://ai.google.dev/gemma/terms
引用
@article{RTZR,
title={ko-gemma-2-9b-it},
author={Return Zero Team},
year={2024},
url={https://huggingface.co/rtzr/ko-gemma-2-9b-it}
}
@article{gemma_2024,
title={Gemma},
url={https://www.kaggle.com/m/3301},
DOI={10.34740/KAGGLE/M/3301},
publisher={Kaggle},
author={Gemma Team},
year={2024}
}
Phi 2 GGUF
其他
Phi-2是微软开发的一个小型但强大的语言模型,具有27亿参数,专注于高效推理和高质量文本生成。
大型语言模型
支持多种语言
P
TheBloke
41.5M
205
Roberta Large
MIT
基于掩码语言建模目标预训练的大型英语语言模型,采用改进的BERT训练方法
大型语言模型
英语
R
FacebookAI
19.4M
212
Distilbert Base Uncased
Apache-2.0
DistilBERT是BERT基础模型的蒸馏版本,在保持相近性能的同时更轻量高效,适用于序列分类、标记分类等自然语言处理任务。
大型语言模型
英语
D
distilbert
11.1M
669
Llama 3.1 8B Instruct GGUF
Meta Llama 3.1 8B Instruct 是一个多语言大语言模型,针对多语言对话用例进行了优化,在常见的行业基准测试中表现优异。
大型语言模型
英语
L
modularai
9.7M
4
Xlm Roberta Base
MIT
XLM-RoBERTa是基于100种语言的2.5TB过滤CommonCrawl数据预训练的多语言模型,采用掩码语言建模目标进行训练。
大型语言模型
支持多种语言
X
FacebookAI
9.6M
664
Roberta Base
MIT
基于Transformer架构的英语预训练模型,通过掩码语言建模目标在海量文本上训练,支持文本特征提取和下游任务微调
大型语言模型
英语
R
FacebookAI
9.3M
488
Opt 125m
其他
OPT是由Meta AI发布的开放预训练Transformer语言模型套件,参数量从1.25亿到1750亿,旨在对标GPT-3系列性能,同时促进大规模语言模型的开放研究。
大型语言模型
英语
O
facebook
6.3M
198
Llama 3.1 8B Instruct
Llama 3.1是Meta推出的多语言大语言模型系列,包含8B、70B和405B参数规模,支持8种语言和代码生成,优化了多语言对话场景。
大型语言模型
Transformers

支持多种语言
L
meta-llama
5.7M
3,898
T5 Base
Apache-2.0
T5基础版是由Google开发的文本到文本转换Transformer模型,参数规模2.2亿,支持多语言NLP任务。
大型语言模型
支持多种语言
T
google-t5
5.4M
702
Xlm Roberta Large
MIT
XLM-RoBERTa是基于100种语言的2.5TB过滤CommonCrawl数据预训练的多语言模型,采用掩码语言建模目标进行训练。
大型语言模型
支持多种语言
X
FacebookAI
5.3M
431
精选推荐AI模型
Llama 3 Typhoon V1.5x 8b Instruct
专为泰语设计的80亿参数指令模型,性能媲美GPT-3.5-turbo,优化了应用场景、检索增强生成、受限生成和推理任务
大型语言模型
Transformers

支持多种语言
L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一个基于SODA数据集训练的超小型对话模型,专为边缘设备推理设计,体积仅为Cosmo-3B模型的2%左右。
对话系统
Transformers

英语
C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基于RoBERTa架构的中文抽取式问答模型,适用于从给定文本中提取答案的任务。
问答系统
中文
R
uer
2,694
98
AIbase是一个专注于MCP服务的平台,为AI开发者提供高质量的模型上下文协议服务,助力AI应用开发。
简体中文