Update README.md
Browse files
README.md
CHANGED
|
@@ -14,6 +14,66 @@ model-index:
|
|
| 14 |
<!-- This model card has been generated automatically according to the information the Trainer had access to. You
|
| 15 |
should probably proofread and complete it, then remove this comment. -->
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
# train_2024-05-15-20-33-30
|
| 18 |
|
| 19 |
This model is a fine-tuned version of [alpindale/Mistral-7B-v0.2-hf](https://huggingface.co/alpindale/Mistral-7B-v0.2-hf) on the emoji_add_instruction_zh dataset.
|
|
|
|
| 14 |
<!-- This model card has been generated automatically according to the information the Trainer had access to. You
|
| 15 |
should probably proofread and complete it, then remove this comment. -->
|
| 16 |
|
| 17 |
+
# Install
|
| 18 |
+
```bash
|
| 19 |
+
pip install peft transformers bitsandbytes
|
| 20 |
+
```
|
| 21 |
+
# Run by transformers
|
| 22 |
+
```python
|
| 23 |
+
from transformers import TextStreamer, AutoTokenizer, AutoModelForCausalLM
|
| 24 |
+
from peft import PeftModel
|
| 25 |
+
tokenizer = AutoTokenizer.from_pretrained("alpindale/Mistral-7B-v0.2-hf",)
|
| 26 |
+
mis_model = AutoModelForCausalLM.from_pretrained("alpindale/Mistral-7B-v0.2-hf", load_in_4bit = True)
|
| 27 |
+
mis_model = PeftModel.from_pretrained(mis_model, "svjack/emoji_Mistral7B_v2_lora")
|
| 28 |
+
mis_model = mis_model.eval()
|
| 29 |
+
|
| 30 |
+
streamer = TextStreamer(tokenizer)
|
| 31 |
+
|
| 32 |
+
def mistral_hf_predict(prompt, mis_model = mis_model,
|
| 33 |
+
tokenizer = tokenizer, streamer = streamer,
|
| 34 |
+
do_sample = True,
|
| 35 |
+
top_p = 0.95,
|
| 36 |
+
top_k = 40,
|
| 37 |
+
max_new_tokens = 512,
|
| 38 |
+
max_input_length = 3500,
|
| 39 |
+
temperature = 0.9,
|
| 40 |
+
repetition_penalty = 1.0,
|
| 41 |
+
device = "cuda"):
|
| 42 |
+
messages = [
|
| 43 |
+
{"role": "user", "content": prompt[:max_input_length]}
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
+
encodeds = tokenizer.apply_chat_template(messages, return_tensors="pt")
|
| 47 |
+
model_inputs = encodeds.to(device)
|
| 48 |
+
|
| 49 |
+
generated_ids = mis_model.generate(model_inputs, max_new_tokens=max_new_tokens,
|
| 50 |
+
do_sample=do_sample,
|
| 51 |
+
streamer = streamer,
|
| 52 |
+
top_p = top_p,
|
| 53 |
+
top_k = top_k,
|
| 54 |
+
temperature = temperature,
|
| 55 |
+
repetition_penalty = repetition_penalty,
|
| 56 |
+
)
|
| 57 |
+
out = tokenizer.batch_decode(generated_ids)[0].split("[/INST]")[-1].replace("</s>", "").strip()
|
| 58 |
+
return out
|
| 59 |
+
|
| 60 |
+
out = mistral_hf_predict('''
|
| 61 |
+
对下面的内容添加emoji
|
| 62 |
+
走在公园的大道上,可以发现许多树的叶子,已染上了秋的色彩,到处可以看到黄灿灿的树叶。
|
| 63 |
+
其中最引人注目的是那金黄金黄的银杏树,远远望去,犹如金色的海洋.
|
| 64 |
+
微风吹过,银杏树叶纷纷飘落,就像一只只美丽的蝴蝶,展开双翅在空中飞舞。
|
| 65 |
+
''',
|
| 66 |
+
repetition_penalty = 1.1)
|
| 67 |
+
print(out)
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
# Output
|
| 71 |
+
```txt
|
| 72 |
+
🍃🎊🍂🌞走在公园的大道上,可以发现许多树的叶子,已染上了秋的色彩,到处可以看到黄灿灿的树叶 ☀️。
|
| 73 |
+
其中最引人注目的是那金黄金黄的银杏树 🌟,远远望去,犹如金色的海洋 🌊。
|
| 74 |
+
微风吹过,银杏树叶纷纷飘落,就像一只只美丽的蝴蝶 🦋,展开双翅在空中飞舞 ✈️
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
# train_2024-05-15-20-33-30
|
| 78 |
|
| 79 |
This model is a fine-tuned version of [alpindale/Mistral-7B-v0.2-hf](https://huggingface.co/alpindale/Mistral-7B-v0.2-hf) on the emoji_add_instruction_zh dataset.
|