Views
No views yet
Qwen2.5-7B-Instruct base model and fine-tuned to enhance prompt effectiveness in low-resource LLM scenarios.transformers library:1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model = AutoModelForCausalLM.from_pretrained('zixiaozhu/MePO', device_map="auto", load_in_8bit=True)
4tokenizer = AutoTokenizer.from_pretrained('zixiaozhu/MePO', truncation_side='left', padding_side='left')
5
6# Example prompt optimization
7po_prompt_ins ='You are an expert of prompt optimization.\n\nSliver Prompt:\n\'S_P\'\n\n\nThe optional Sliver Response was generated by an AI based on the Silver Prompt. Please help modify the Silver Prompt to Golden Prompt (in English) that can obtain a more correct response, in reference to the optional Golden Response. The Golden Prompt should be strictly faithful to any factual information in the Silver Prompt. Only give me the content of Golden Prompt in English, do not contain any other information (e.g., your response of the Golden Prompt, any postfix like \'Golden Prompt\', etc.).'
8
9raw_prompt = 'who is the father of nlp?'
10prompt = po_prompt_ins.replace("S_P", raw_prompt)
11
12messages = [
13 {"role": "system", "content": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant."},
14 {"role": "user", "content": prompt}
15]
16
17text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
18model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
19
20generated_ids = model.generate(
21 **model_inputs,
22 max_new_tokens=1024,
23 do_sample=False
24)
25
26# Remove the original input to keep only the generated response
27generated_ids = [
28 output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
29]
30
31optimized_prompt = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]1@misc{zhu2025rethinkingpromptoptimizersprompt,
2 title = {Rethinking Prompt Optimizers: From Prompt Merits to Optimization},
3 author = {Zixiao Zhu and Hanzhang Zhou and Zijian Feng and Tianjiao Li and Chua Jia Jim Deryl and Mak Lee Onn and Gee Wah Ng and Kezhi Mao},
4 year = {2025},
5 eprint = {2505.09930},
6 archivePrefix = {arXiv},
7 primaryClass = {cs.CL},
8 url = {https://arxiv.org/abs/2505.09930}
9}