Views
No views yet
Qwen/Qwen3-4B-Instruct-2507 designed to generate satirical news headlines in the style of The Onion.transformers. Ensure you have the latest versions of transformers and peft installed.1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3
4base_model_name = "Qwen/Qwen3-4B-Instruct-2507"
5model_name = "joshuachin/Qwen3-4B-Instruct-2507-satirical-headlines-CoT"
6
7# Load the tokenizer and model
8tokenizer = AutoTokenizer.from_pretrained(model_name)
9model = AutoModelForCausalLM.from_pretrained(
10 base_model_name,
11 torch_dtype="auto",
12 device_map="auto"
13)
14model = PeftModel.from_pretrained(model, model_name)
15model.eval()
16
17# prepare the model input
18prompt = "Give me a satirical headline."
19messages = [
20 {"role": "user", "content": prompt}
21]
22text = tokenizer.apply_chat_template(
23 messages,
24 tokenize=False,
25 add_generation_prompt=True,
26)
27model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
28
29# conduct text completion
30generated_ids = model.generate(
31 **model_inputs,
32 max_new_tokens=1024
33)
34output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
35
36content = tokenizer.decode(output_ids, skip_special_tokens=True)
37
38print("headline: ", content)Qwen/Qwen3-4B-Instruct-2507Subject + Satirical Angle) generated by gemini-2.5-flash. The model was trained to generate the final headline after seeing the CoT analysis, teaching it to mimic the reasoning process.