wenge-research commited on
Commit
65ed35d
1 Parent(s): f1a9e8d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +79 -0
README.md CHANGED
@@ -80,3 +80,82 @@ 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
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  response_str = tokenizer.batch_decode(response, skip_special_tokens=False, clean_up_tokenization_spaces=False)[0]
81
  print(response_str)
82
  ```
83
+
84
+
85
+ ---
86
+ # YaYi
87
+
88
+ ## Introduction
89
+
90
+ [YaYi](https://www.wenge.com/yayi/index.html) was fine-tuned on millions of artificially constructed high-quality domain data. This training data covers five key domains: media publicity, public opinion analysis, public safety, financial risk control, and urban governance, encompassing over a hundred natural language instruction tasks. Throughout the iterative development process of the YaYi, starting from pre-training initialization weights and progressing to domain-specific model, we have steadily enhanced its foundational Chinese language capabilities and domain analysis capabilities. We've also introduced multi-turn conversation enhancements and integrated various plug-in capabilities. Furthermore, through continuous manual feedback and optimization from hundreds of users during the internal testing phase, we've meticulously refined the model's performance and security.
91
+
92
+ By open-sourcing the YaYi model, we will contribute our own efforts to the development of the Chinese pre-trained large language model open-source community. Through this open-source initiative, we seek to collaborate with every partner to build the YaYi model ecosystem together.
93
+
94
+ *News: 🔥 YaYi has open sourced the Chinese optimization model version based on LLaMA 2 to explore the latest practices suitable for Chinese multi-domain tasks.*
95
+
96
+
97
+ ## Model download
98
+
99
+ | Model | 🤗HF Model Name | Download Links |
100
+ | --------- | --------- | --------- |
101
+ | YaYi-7B | wenge-research/yayi-7b | [Download](https://huggingface.co/wenge-research/yayi-7b) |
102
+ | YaYi-7B-Llama2 | wenge-research/yayi-7b-llama2 | [Download](https://huggingface.co/wenge-research/yayi-7b-llama2) |
103
+ | YaYi-13B-Llama2 | wenge-research/yayi-13b-llama2 | [Download](https://huggingface.co/wenge-research/yayi-13b-llama2) |
104
+
105
+ For more details, please refer to our [💻Github Repo](https://github.com/wenge-research/YaYi)。
106
+
107
+
108
+
109
+ ## Run
110
+
111
+ ```python
112
+ import torch
113
+ from transformers import LlamaForCausalLM, LlamaTokenizer, GenerationConfig
114
+ from transformers import StoppingCriteria, StoppingCriteriaList
115
+
116
+ pretrained_model_name_or_path = "wenge-research/yayi-7b-llama2"
117
+ tokenizer = LlamaTokenizer.from_pretrained(pretrained_model_name_or_path)
118
+ model = LlamaForCausalLM.from_pretrained(pretrained_model_name_or_path, device_map="auto", torch_dtype=torch.bfloat16, trust_remote_code=False)
119
+
120
+ # Define the stopping criteria
121
+ class KeywordsStoppingCriteria(StoppingCriteria):
122
+ def __init__(self, keywords_ids:list):
123
+ self.keywords = keywords_ids
124
+
125
+ def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs) -> bool:
126
+ if input_ids[0][-1] in self.keywords:
127
+ return True
128
+ return False
129
+
130
+ stop_words = ["<|End|>", "<|YaYi|>", "<|Human|>", "</s>"]
131
+ stop_ids = [tokenizer.encode(w)[-1] for w in stop_words]
132
+ stop_criteria = KeywordsStoppingCriteria(stop_ids)
133
+
134
+ # inference
135
+ prompt = "你是谁?"
136
+ formatted_prompt = f"""<|System|>:
137
+ 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.
138
+
139
+ <|Human|>:
140
+ {prompt}
141
+
142
+ <|YaYi|>:
143
+ """
144
+
145
+ inputs = tokenizer(formatted_prompt, return_tensors="pt").to(model.device)
146
+ eos_token_id = tokenizer("<|End|>").input_ids[0]
147
+ generation_config = GenerationConfig(
148
+ eos_token_id=eos_token_id,
149
+ pad_token_id=eos_token_id,
150
+ do_sample=True,
151
+ max_new_tokens=256,
152
+ temperature=0.3,
153
+ repetition_penalty=1.1,
154
+ no_repeat_ngram_size=0
155
+ )
156
+ response = model.generate(**inputs, generation_config=generation_config, stopping_criteria=StoppingCriteriaList([stop_criteria]))
157
+ response = [response[0][len(inputs.input_ids[0]):]]
158
+ response_str = tokenizer.batch_decode(response, skip_special_tokens=False, clean_up_tokenization_spaces=False)[0]
159
+ print(response_str)
160
+ ```
161
+