wenge-research commited on
Commit
0bc54ad
1 Parent(s): 59594bb

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +82 -0
README.md ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - zh
4
+ - en
5
+ pipeline_tag: text-generation
6
+ tags:
7
+ - yayi
8
+ ---
9
+ # 雅意大模型
10
+
11
+ ## 介绍
12
+
13
+ [雅意大模型](https://www.wenge.com/yayi/index.html)在百万级人工构造的高质量领域数据上进行指令微调得到,训练数据覆盖媒体宣传、舆情分析、公共安全、金融风控、城市治理等五大领域,上百种自然语言指令任务。雅意大模型从预训练初始化权重到领域模型的迭代过程中,我们逐步增强了它的中文基础能力和领域分析能力,并增加了多轮对话和部分插件能力。同时,经过数百名用户内测过程中持续不断的人工反馈优化,我们进一步提升了模型性能和安全性。
14
+
15
+ 通过雅意大模型的开源为促进中文预训练大模型开源社区的发展,贡献自己的一份力量,通过开源,与每一位合作伙伴共建雅意大模型生态。
16
+
17
+ *News: 🔥 雅意大模型已开源基于 LLaMA 2 的中文优化模型版本,探索适用于中文多领域任务的最新实践。*
18
+
19
+
20
+ ## 模型地址
21
+
22
+ | 模型名称 | 🤗HF模型标识 | 下载地址 |
23
+ | --------- | --------- | --------- |
24
+ | YaYi-7B | wenge-research/yayi-7b | [模型下载](https://huggingface.co/wenge-research/yayi-7b) |
25
+ | YaYi-7B-Llama2 | wenge-research/yayi-7b-llama2 | [模型下载](https://huggingface.co/wenge-research/yayi-7b-llama2) |
26
+ | YaYi-13B-Llama2 | wenge-research/yayi-13b-llama2 | [模型下载](https://huggingface.co/wenge-research/yayi-13b-llama2) |
27
+
28
+ 详情请参考我们的 [💻Github Repo](https://github.com/wenge-research/YaYi)。
29
+
30
+
31
+ ## 运行方式
32
+
33
+ ```python
34
+ import torch
35
+ from transformers import LlamaForCausalLM, LlamaTokenizer, GenerationConfig
36
+ from transformers import StoppingCriteria, StoppingCriteriaList
37
+
38
+ pretrained_model_name_or_path = "wenge-research/yayi-13b-llama2"
39
+ tokenizer = LlamaTokenizer.from_pretrained(pretrained_model_name_or_path)
40
+ model = LlamaForCausalLM.from_pretrained(pretrained_model_name_or_path, device_map="auto", torch_dtype=torch.bfloat16, trust_remote_code=False)
41
+
42
+ # Define the stopping criteria
43
+ class KeywordsStoppingCriteria(StoppingCriteria):
44
+ def __init__(self, keywords_ids:list):
45
+ self.keywords = keywords_ids
46
+
47
+ def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs) -> bool:
48
+ if input_ids[0][-1] in self.keywords:
49
+ return True
50
+ return False
51
+
52
+ stop_words = ["<|End|>", "<|YaYi|>", "<|Human|>", "</s>"]
53
+ stop_ids = [tokenizer.encode(w)[-1] for w in stop_words]
54
+ stop_criteria = KeywordsStoppingCriteria(stop_ids)
55
+
56
+ # inference
57
+ prompt = "你是谁?"
58
+ formatted_prompt = f"""<|System|>:
59
+ You are a helpful, respectful and honest assistant named YaYi developed by Beijing Wenge Technology Co.,Ltd. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature.\n\nIf a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.
60
+
61
+ <|Human|>:
62
+ {prompt}
63
+
64
+ <|YaYi|>:
65
+ """
66
+
67
+ inputs = tokenizer(formatted_prompt, return_tensors="pt").to(model.device)
68
+ eos_token_id = tokenizer("<|End|>").input_ids[0]
69
+ generation_config = GenerationConfig(
70
+ eos_token_id=eos_token_id,
71
+ pad_token_id=eos_token_id,
72
+ do_sample=True,
73
+ max_new_tokens=256,
74
+ temperature=0.3,
75
+ repetition_penalty=1.1,
76
+ no_repeat_ngram_size=0
77
+ )
78
+ response = model.generate(**inputs, generation_config=generation_config, stopping_criteria=StoppingCriteriaList([stop_criteria]))
79
+ response = [response[0][len(inputs.input_ids[0]):]]
80
+ response_str = tokenizer.batch_decode(response, skip_special_tokens=False, clean_up_tokenization_spaces=False)[0]
81
+ print(response_str)
82
+ ```