Update README.md
Browse files
README.md
CHANGED
|
@@ -21,3 +21,64 @@ Simple, just make your comments more eye-catching, like talk show style!!!
|
|
| 21 |
|
| 22 |

|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |

|
| 23 |
|
| 24 |
+
|
| 25 |
+
## Train
|
| 26 |
+
It's a reasoning model. Train Qwen/Qwen3-14B with USLOTH's GRPO.
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
## Test
|
| 30 |
+
```
|
| 31 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 32 |
+
|
| 33 |
+
model_name = "aipgpt/Punch-Line-Master"
|
| 34 |
+
|
| 35 |
+
# load the tokenizer and the model
|
| 36 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 37 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 38 |
+
model_name,
|
| 39 |
+
torch_dtype="auto",
|
| 40 |
+
device_map="auto"
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
# prepare the model input
|
| 44 |
+
user_prompt = "请用幽默的方式修改下面这句话,建议参考脱口秀方式。改后句子长度不超过原句长度的3倍。\n\n原来我和富豪的共同点是都会失眠,区别是他们后悔几千万的决策,我后悔半夜点开外卖软件的手……"
|
| 45 |
+
system_prompt = """
|
| 46 |
+
请使用中文按以下格式回答问题:
|
| 47 |
+
<think>
|
| 48 |
+
...
|
| 49 |
+
</think>
|
| 50 |
+
|
| 51 |
+
...
|
| 52 |
+
"""
|
| 53 |
+
messages = [
|
| 54 |
+
{"role": "system", "content": system_prompt},
|
| 55 |
+
{"role": "user", "content": user_prompt}
|
| 56 |
+
]
|
| 57 |
+
text = tokenizer.apply_chat_template(
|
| 58 |
+
messages,
|
| 59 |
+
tokenize=False,
|
| 60 |
+
add_generation_prompt=True,
|
| 61 |
+
enable_thinking=True # Switches between thinking and non-thinking modes. Default is True.
|
| 62 |
+
)
|
| 63 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 64 |
+
|
| 65 |
+
# conduct text completion
|
| 66 |
+
generated_ids = model.generate(
|
| 67 |
+
**model_inputs,
|
| 68 |
+
max_new_tokens=32768
|
| 69 |
+
)
|
| 70 |
+
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
|
| 71 |
+
|
| 72 |
+
# parsing thinking content
|
| 73 |
+
try:
|
| 74 |
+
# rindex finding 151668 (</think>)
|
| 75 |
+
index = len(output_ids) - output_ids[::-1].index(151668)
|
| 76 |
+
except ValueError:
|
| 77 |
+
index = 0
|
| 78 |
+
|
| 79 |
+
thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
|
| 80 |
+
content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
|
| 81 |
+
|
| 82 |
+
print("thinking content:", thinking_content)
|
| 83 |
+
print("content:", content)
|
| 84 |
+
```
|