
Janus 是以 Mistral-7B-v0.2 为基础模型训练而成的。Janus 训练所使用的数据集为 Multifaceted Collection,这是一个偏好数据集,包含 196k 条独特的系统消息,用于使大型语言模型(LLMs)与多样化的人类偏好对齐。Janus 不仅擅长生成能够满足各种人类偏好的个性化响应,还能生成具有普遍偏好的、既有用又无害的回复。
Janus-7B 是通过对 Multifaceted-Collection 训练数据中的全部 196k 条条目进行有监督微调而创建的模型。
Janus 是一个针对各种系统消息进行泛化的模型,用户可以通过输入所需的系统消息来控制模型的响应。输入提示格式如下:
[INST]{system_message}\n{instruction}[/INST]此外,应用此方法的推理代码示例如下:
from openmind import AutoTokenizer, AutoModelForCausalLM, is_torch_npu_available
from openmind_hub import snapshot_download
import torch.nn.functional as F
from torch import Tensor
import openmind
import torch
import argparse
import sys
import time
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"--model_name_or_path",
type=str,
help="Path to model",
default="zhouhui/janus-7b",
)
args = parser.parse_args()
return args
def main():
args = parse_args()
model_path = args.model_name_or_path
if is_torch_npu_available():
device = "npu:0"
else:
device = "cpu"
#device = "cpu"
start_time = time.time()
model = AutoModelForCausalLM.from_pretrained(model_path).to(device)
tokenizer = AutoTokenizer.from_pretrained(model_path)
model.eval()
prompt = "Hello, who are you?"
input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(device)
outputs = model.generate(input_ids=input_ids, max_length=100)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
end_time = time.time()
print(f"硬件环境:{device},推理执行时间:{end_time - start_time}秒")
if __name__ == "__main__":
main()若要训练 Janus 并评估其生成的回复,请参考 GitHub 代码库。此外,可参考 Multifaceted Bench,该基准用于评估大型语言模型(LLM)生成个性化回复的能力。
训练过程中使用了以下超参数:
如果您觉得以下模型有帮助,请考虑引用我们的论文!
BibTeX:
@misc{lee2024aligning,
title={Aligning to Thousands of Preferences via System Message Generalization},
author={Seongyun Lee and Sue Hyun Park and Seungone Kim and Minjoon Seo},
year={2024},
eprint={2405.17977},
archivePrefix={arXiv},
primaryClass={cs.CL}
}