| | --- |
| | license: other |
| | license_name: license |
| | license_link: LICENSE |
| | --- |
| | <div align="center"> |
| | <h1> |
| | Index-1.9B-Chat |
| | </h1> |
| | </div> |
| |
|
| | ## 模型介绍 |
| |
|
| | 我们很高兴首次发布Index系列模型中的轻量版本:Index-1.9B系列 |
| | 本次开源的Index-1.9B 系列包含以下模型: |
| | - Index-1.9B base : 基座模型,具有 19亿 非词嵌入参数量,在2.8T 中英文为主的语料上预训练,多个评测基准上与同级别模型比处于领先。 |
| | - Index-1.9B pure : 基座模型的对照组,与base具有相同的参数和训练策略,不同之处在于我们严格过滤了该版本语料中所有指令相关的数据,以此来验证指令对benchmark的影响。 |
| | - **Index-1.9B chat(本仓库模型)** : 基于index-1.9B base通过SFT和DPO对齐后的对话模型,我们发现由于预训练中引入了较多定向清洗的对话类语料,聊天的趣味性明显更强。 |
| | - Index-1.9B character : 在SFT和DPO的基础上引入了RAG来实现fewshots角色扮演定制。 |
| |
|
| |
|
| | 更多细节详见我们的[GitHub](https://github.com/bilibili/Index-1.9B)和[Index-1.9B技术报告](https://github.com/bilibili/Index-1.9B/blob/main/Index-1.9B%20%E6%8A%80%E6%9C%AF%E6%8A%A5%E5%91%8A.pdf) |
| |
|
| | ### Transformers 加载方式 |
| |
|
| | 可通过以下代码加载 Index-1.9B-Chat 模型来进行对话: |
| |
|
| | ```python |
| | import torch |
| | import argparse |
| | from transformers import AutoTokenizer, AutoModelForCausalLM |
| | |
| | # 注意!目录不能含有".",可以替换成"_" |
| | parser = argparse.ArgumentParser() |
| | parser.add_argument('--model_path', default="", type=str, help="") |
| | args = parser.parse_args() |
| | |
| | tokenizer = AutoTokenizer.from_pretrained(args.model_path, trust_remote_code=True) |
| | model = AutoModelForCausalLM.from_pretrained(args.model_path, torch_dtype=torch.bfloat16, trust_remote_code=True, device_map='auto') |
| | model = model.eval() |
| | print('model loaded', args.model_path, model.device) |
| | |
| | system_message = "你是由哔哩哔哩自主研发的大语言模型,名为“Index”。你能够根据用户传入的信息,帮助用户完成指定的任务,并生成恰当的、符合要求的回复。" |
| | query = "续写 天不生我金坷垃" |
| | model_input = [] |
| | model_input.append({"role": "system", "content": system_message}) |
| | model_input.append({"role": "user", "content": query}) |
| | |
| | inputs = tokenizer.apply_chat_template(model_input, tokenize=False, add_generation_prompt=False) |
| | input_ids = tokenizer.encode(inputs, return_tensors="pt").to(model.device) |
| | history_outputs = model.generate(input_ids, max_new_tokens=300, top_k=5, top_p=0.8, temperature=0.3, repetition_penalty=1.1, do_sample=True) |
| | |
| | # 删除</s> |
| | if history_outputs[0][-1] == 2: |
| | history_outputs = history_outputs[:, :-1] |
| | |
| | outputs = history_outputs[0][len(input_ids[0]):] |
| | print('User:', query) |
| | print('\nModel:', tokenizer.decode(outputs)) |
| | ``` |
| |
|