Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
language:
|
4 |
+
- zh
|
5 |
+
- en
|
6 |
+
tags:
|
7 |
+
- prompt refinement
|
8 |
+
---
|
9 |
+
<img src="https://cdn-uploads.huggingface.co/production/uploads/62aba5ebab9ed4f63c36b1e2/VA_IEJWR4RA1iApoZrZcK.png" alt="image/png" style="transform: scale(0.6);">
|
10 |
+
|
11 |
+
## 📖 Introduction
|
12 |
+
|
13 |
+
**Qwen2-7B-Instruct-Refine** and **Qwen2-1.5B-Instruct-Refine** are two powerful large language models that act as proficient prompt engineers. They can optimize and refine the prompts input by users, and the generated optimized instructions can significantly enhance the LLM's ability to produce better and more informative responses for users.
|
14 |
+
|
15 |
+
## 🚀 Quick Start
|
16 |
+
|
17 |
+
Here provides a code snippet with `apply_chat_template` to show you how to load the tokenizer and model and how to generate contents.
|
18 |
+
|
19 |
+
```python
|
20 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
21 |
+
device = "cuda" # the device to load the model onto
|
22 |
+
|
23 |
+
model = AutoModelForCausalLM.from_pretrained(
|
24 |
+
"alibaba-pai/Qwen2-1.5B-Instruct-Refine",
|
25 |
+
torch_dtype="auto",
|
26 |
+
device_map="auto"
|
27 |
+
)
|
28 |
+
tokenizer = AutoTokenizer.from_pretrained("alibaba-pai/Qwen2-1.5B-Instruct-Refine")
|
29 |
+
|
30 |
+
prompt = "Give me a short introduction to large language model."
|
31 |
+
messages = [
|
32 |
+
{"role": "user", "content": prompt}
|
33 |
+
]
|
34 |
+
text = tokenizer.apply_chat_template(
|
35 |
+
messages,
|
36 |
+
tokenize=False,
|
37 |
+
add_generation_prompt=True
|
38 |
+
)
|
39 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(device)
|
40 |
+
|
41 |
+
generated_ids = model.generate(
|
42 |
+
model_inputs.input_ids,
|
43 |
+
max_new_tokens=2048,
|
44 |
+
eos_token_id=151645,
|
45 |
+
)
|
46 |
+
generated_ids = [
|
47 |
+
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
48 |
+
]
|
49 |
+
|
50 |
+
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
51 |
+
```
|
52 |
+
|
53 |
+
## 🔍 Evaluation
|
54 |
+
|
55 |
+
| Model | Detail | Truthfulness |
|
56 |
+
|------------------------------------|---------|--------------|
|
57 |
+
| Qwen2-1.5B-Instruct | 50.00% | 50.00% |
|
58 |
+
| + Qwen2-1.5B-Instruct-Refine | 75.63% | 63.75% |
|
59 |
+
| + Qwen2-7B-Instruct-Refine | 76.56% | 62.19% |
|
60 |
+
| Qwen2-7B-Instruct | 50.00% | 50.00% |
|
61 |
+
| + Qwen2-1.5B-Instruct-Refine | 70.94% | 57.19% |
|
62 |
+
| + Qwen2-7B-Instruct-Refine | 74.69% | 58.44% |
|
63 |
+
|
64 |
+
|