wenge-research commited on
Commit
34e122b
1 Parent(s): 9fc1bc4

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +77 -0
README.md CHANGED
@@ -80,3 +80,80 @@ 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
+ ## Run
109
+
110
+ ```python
111
+ import torch
112
+ from transformers import LlamaForCausalLM, LlamaTokenizer, GenerationConfig
113
+ from transformers import StoppingCriteria, StoppingCriteriaList
114
+
115
+ pretrained_model_name_or_path = "wenge-research/yayi-13b-llama2"
116
+ tokenizer = LlamaTokenizer.from_pretrained(pretrained_model_name_or_path)
117
+ model = LlamaForCausalLM.from_pretrained(pretrained_model_name_or_path, device_map="auto", torch_dtype=torch.bfloat16, trust_remote_code=False)
118
+
119
+ # Define the stopping criteria
120
+ class KeywordsStoppingCriteria(StoppingCriteria):
121
+ def __init__(self, keywords_ids:list):
122
+ self.keywords = keywords_ids
123
+
124
+ def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs) -> bool:
125
+ if input_ids[0][-1] in self.keywords:
126
+ return True
127
+ return False
128
+
129
+ stop_words = ["<|End|>", "<|YaYi|>", "<|Human|>", "</s>"]
130
+ stop_ids = [tokenizer.encode(w)[-1] for w in stop_words]
131
+ stop_criteria = KeywordsStoppingCriteria(stop_ids)
132
+
133
+ # inference
134
+ prompt = "你是谁?"
135
+ formatted_prompt = f"""<|System|>:
136
+ 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.
137
+
138
+ <|Human|>:
139
+ {prompt}
140
+
141
+ <|YaYi|>:
142
+ """
143
+
144
+ inputs = tokenizer(formatted_prompt, return_tensors="pt").to(model.device)
145
+ eos_token_id = tokenizer("<|End|>").input_ids[0]
146
+ generation_config = GenerationConfig(
147
+ eos_token_id=eos_token_id,
148
+ pad_token_id=eos_token_id,
149
+ do_sample=True,
150
+ max_new_tokens=256,
151
+ temperature=0.3,
152
+ repetition_penalty=1.1,
153
+ no_repeat_ngram_size=0
154
+ )
155
+ response = model.generate(**inputs, generation_config=generation_config, stopping_criteria=StoppingCriteriaList([stop_criteria]))
156
+ response = [response[0][len(inputs.input_ids[0]):]]
157
+ response_str = tokenizer.batch_decode(response, skip_special_tokens=False, clean_up_tokenization_spaces=False)[0]
158
+ print(response_str)
159
+ ```