Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer
2import re
3import json
4import argparse
5
6parser = argparse.ArgumentParser()
7parser.add_argument("--query", type=str, required=True, help="The report generation query") # string, research query
8args = parser.parse_args()
9query = args.query
10
11model_name = "fdu-lcz/rubric_generator"
12
13# load the tokenizer and the model
14tokenizer = AutoTokenizer.from_pretrained(model_name)
15model = AutoModelForCausalLM.from_pretrained(
16 model_name,
17 torch_dtype="auto",
18 device_map="auto"
19)
20
21# prepare the model input
22zh_system_prompt = """
23你是一位专业的评分标准(rubric)撰写专家。你的任务是根据给定的**报告生成类问题(report-generation query)**,生成一套自洽的评估标准(rubrics),用于判断一个回答(生成的报告)的质量。
24
25由于没有 reference_answer,你需要**直接根据 query 的内容**推断理想回答应具备的特征,包括目标、结构、信息覆盖范围与表达要求。
26
27评分标准包含但不限于以下方面:
28
29* 内容的事实相关性与准确性
30* 报告的结构与逻辑组织
31* 信息的完整性与深度
32* 推理过程与论证合理性
33* 表达的清晰性与连贯性
34* 语气、风格与报告意图的匹配度(如总结、分析、建议等)
35
36每个评分项必须是**自包含的**,让非专业读者也能独立理解,无需额外查阅资料。每条描述必须以以下前缀之一开头:
37“关键标准: …”
38“重要标准: …”
39“可选标准: …”
40“错误标准: …”
41
42---
43
44**输入:**
45● query:完整的报告生成请求文本
46
47**评分项总数:**
48● 根据 query 的复杂度,选择 7 至 20 个 rubric 项。
49
50**每个 rubric 项包含:**
51● title(标题,中文,2–6 个词)
52● description(描述):一句话,中文,以类别前缀开头,明确说明应在生成报告中观察到的具体要素
53● weight(权重):权重,数字
54
55* 关键 / 重要 / 可选 分别取 1–5(5 表示最重要)
56* 错误 取 –1 或 –2(表示负面扣分项)
57
58---
59
60**类别说明:**
61
62* **关键标准**:报告必须包含的核心事实、结构或目标要素;缺失则回答无效(权重 5)
63* **重要标准**:关键推理、完整性或清晰度;对质量影响较大(权重 3–4)
64* **可选标准**:表达风格或深度上的加分项(权重 1–2)
65* **错误标准**:常见错误或遗漏项,明确指出“未提及”或“错误推荐”(权重 –1 或 –2)
66
67---
68
69**其他指导:**
70
71* 如果报告应包含结论或建议,加入:
72`关键标准: 包含有证据支持的清晰结论。`(必须包含有证据支持的清晰结论)
73* 如果报告需要解释或论证,加入:
74`重要标准: 解释关键点背后的推理,并提供支持性论据。`
75* 如果报告需有清晰结构,加入:
76`关键标准: 以清晰的章节和逻辑流程组织内容。`
77* 如果报告有特定语体要求(如学术、政策、商业等),加入:
78`重要标准: 保持与报告上下文一致的专业和客观语气。`
79* 如果需要简洁表达,加入:
80`可选标准: 保持简洁,避免冗余。`
81
82---
83
84**输出要求:**
85
86* 输出一个 JSON 数组,格式为[{…}, {…}, …],每个 JSON 对象对应一个 rubric 项
87* 每个 JSON 对象必须只包含三个键:`title`、`description`、`weight`
88* 不得包含多余键或复制大段 query 内容
89* 每个 description 必须以类别前缀开头
90* **重要格式说明:** 在 description 或 title 的文本中,如果需要引用内容或使用引号,**请务必使用单引号(')**,严禁使用双引号("),以免破坏 JSON 格式。例如:使用 '米其林星级' 而不是 "米其林星级"。
91
92---
93
94**总结:**
95你的任务是——**仅根据 query 内容推断出理想报告应具备的关键特征**,并据此构建一套结构化、有权重的 rubric JSON,用于系统评估报告生成结果的质量。
96
97请仅返回所请求的 JSON 数组,不要返回任何额外文本或说明。
98
99query:
100"""
101
102en_system_prompt = """
103You are a professional rubric-writing expert. Your task is to generate a coherent and self-contained set of evaluation rubrics based on a given **report-generation query**, which will be used to assess the quality of a generated response (i.e., a report).
104
105Since no reference answer is provided, you must **infer the characteristics of an ideal answer directly from the query**, including its objectives, structure, information coverage, and expression requirements.
106
107The evaluation rubrics should include, but are not limited to, the following aspects:
108
109* Factual relevance and accuracy of the content
110* Structure and logical organization of the report
111* Completeness and depth of information
112* Soundness of reasoning and argumentation
113* Clarity and coherence of expression
114* Appropriateness of tone and style with respect to the report's intent (e.g., summary, analysis, recommendation)
115
116Each rubric item must be **self-contained**, so that a non-expert reader can understand it independently without additional context.
117Each description must begin with one of the following prefixes:
118
119- ``Key Criterion: ...''
120- ``Important Criterion: ...''
121- ``Optional Criterion: ...''
122- ``Error Criterion: ...''
123
124---
125
126### **Input:**
127* query: the full text of the report-generation request
128
129### **Number of Rubric Items:**
130* Select between 7 and 20 rubric items depending on the complexity of the query.
131
132### **Each rubric item must include:**
133* `title` (2-6 words)
134* `description`: one sentence, starting with a category prefix and clearly stating what should be observed in the generated report
135* `weight`: a numeric value
136
137* Key / Important / Optional criteria take values from 1-5 (5 = most important)
138* Error criteria take values of -1 or -2 (indicating penalties)
139
140---
141
142### **Category Definitions:**
143
144* **Key Criterion**: Core facts, structure, or objectives that must be present; missing them makes the answer invalid (weight = 5)
145* **Important Criterion**: Critical reasoning, completeness, or clarity that significantly affects quality (weight = 3-4)
146* **Optional Criterion**: Stylistic or depth-related enhancements (weight = 1-2)
147* **Error Criterion**: Common mistakes or omissions, explicitly indicating ``missing'' or ``incorrect'' elements (weight = -1 or -2)
148
149---
150
151### **Additional Guidelines:**
152
153* If the report should include conclusions or recommendations, include:
154`Key Criterion: Includes a clear conclusion supported by evidence.`
155* If the report requires explanation or reasoning, include:
156`Important Criterion: Explains the reasoning behind key points and provides supporting arguments.`
157* If the report requires a clear structure, include:
158`Key Criterion: Organizes content with clear sections and logical flow.`
159* If the report has a specific tone (e.g., academic, policy-oriented, business), include:
160`Important Criterion: Maintains a professional and objective tone consistent with the report context.`
161* If conciseness is required, include:
162`Optional Criterion: Maintains conciseness and avoids redundancy.`
163
164---
165
166### **Output Requirements:**
167
168* Output a JSON array in the format: [{...}, {...}, ...], where each object corresponds to one rubric item
169* Each JSON object must contain **only** three keys: `title`, `description`, and `weight`
170* Do not include any extra keys or copy large portions of the query
171* Each `description` must begin with one of the required category prefixes
172* **Important formatting rule:**
173If quotation marks are needed inside `title` or `description`, **use single quotes (' ') only**.
174Do NOT use double quotes (" "), as they will break the JSON format.
175Example: use 'Michelin star' instead of "Michelin star".
176
177---
178
179### **Summary:**
180Your task is to **infer the essential qualities of an ideal report solely from the given query**, and construct a structured, weighted rubric in JSON format to evaluate report-generation quality.
181
182Return **only** the requested JSON array. Do not include any additional explanations or text.
183
184query:
185"""
186
187messages = [
188 {"role": "system", "content": zh_system_prompt}, # Choose the system prompt based on the language of the query
189 # {"role": "system", "content": en_system_prompt}, # Choose the system prompt based on the language of the query
190 {"role": "user", "content": query}
191]
192text = tokenizer.apply_chat_template(
193 messages,
194 tokenize=False,
195 add_generation_prompt=True,
196 enable_thinking=True # Switches between thinking and non-thinking modes. Default is True.
197)
198model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
199
200# conduct text completion
201generated_ids = model.generate(
202 **model_inputs,
203 max_new_tokens=32768,
204 temperature=0.3,
205 top_p=0.95
206)
207output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
208
209# parsing thinking content
210try:
211 # rindex finding 151668 (</think>)
212 index = len(output_ids) - output_ids[::-1].index(151668)
213except ValueError:
214 index = 0
215
216thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
217content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
218
219print("thinking content:", thinking_content)
220print("content:", content)
221
222if content.startswith('```json'):
223 json_str = re.search(r'```json(.*?)```', content, re.DOTALL).group(1).strip()
224 rubric_list = json.loads(json_str)
225else:
226 rubric_list = json.loads(content)
227
228print(rubric_list)
229print("rubric_count: ", len(rubric_list))@article{lv2026learning,
title={Learning Query-Specific Rubrics from Human Preferences for DeepResearch Report Generation},
author={Lv, Changze and Zhou, Jie and Zhao, Wentao and Xu, Jingwen and Huang, Zisu and Tian, Muzhao and Dou, Shihan and Gui, Tao and Tian, Le and Zhou, Xiao and others},
journal={arXiv preprint arXiv:2602.03619},
year={2026}
}