Skip to content

Commit c08e110

Browse files
authored
Fix Auto Prompt pipeline in sandbox (#791)
* * involve answer of QAs for grader * * update reference of flagged_words_filter
1 parent 7218cf8 commit c08e110

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

configs/data_juicer_recipes/sandbox/auto_prompt_optimization/sandbox_auto_prompt_optimization.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ resume: true # allo
1010
# iteration related parameters
1111
max_iter_num: 5
1212
iter_targets:
13-
- "grader_model_prompt_optimization.grades_evaluation.min_mse <= 0.26"
13+
- "grader_model_prompt_optimization.grades_evaluation.min_mse <= 0.2"
1414
iter_updater:
1515
select_and_merge_data_pools.merge_single_prompt_data_pools.merged_top_prompt_dataset: grader_model_prompt_optimization.generate_new_prompts.dj_configs.dataset_path
1616

@@ -53,11 +53,12 @@ pipelines:
5353
type: 'api'
5454
model: 'qwen2.5-32b-instruct'
5555
max_retry_num: 5
56-
build_messages_func: 'build_messages'
56+
build_messages_func: 'build_messages_for_math_qa'
5757
parse_output_func: 'parse_output'
5858
func_kwargs:
5959
system_key: "prompt"
6060
query_key: "question"
61+
response_key: "answer"
6162
# data related
6263
dataset_path: '<replaced_by_the_input>'
6364
export_path: './outputs/auto-prompt-optimization-for-grader-model/infer_results/'

data_juicer/core/sandbox/helper_funcs.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,23 @@ def parse_output(output: str, item: dict, **kwargs):
2727
A simple implementation.
2828
"""
2929
return output
30+
31+
32+
# Math QA grader
33+
@ALL_FUNCS.register_module("build_messages_for_math_qa")
34+
def build_messages_for_math_qa(item: dict, **kwargs):
35+
"""
36+
Build message for math QA grader.
37+
"""
38+
system_key = kwargs.get("system_key", "system")
39+
query_key = kwargs.get("query_key", "query")
40+
response_key = kwargs.get("response_key", "response")
41+
42+
system_prompt = item.get(system_key, "")
43+
question = item[query_key]
44+
answer = item[response_key]
45+
messages = []
46+
if system_prompt:
47+
messages.append({"role": "system", "content": system_prompt})
48+
messages.append({"role": "user", "content": f"Question: {question}\nAnswer: {answer}"})
49+
return messages

data_juicer/ops/filter/flagged_words_filter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Some code here has been modified from:
22
# https://huggingface.co/spaces/huggingface/text-data-filtering
3+
#
4+
# The flagged words list comes from https://huggingface.co/spaces/huggingface/text-data-filtering
5+
# and https://github.com/LDNOOBW/List-of-Dirty-Naughty-Obscene-and-Otherwise-Bad-Words
36
# --------------------------------------------------------
47

58
from typing import List

0 commit comments

Comments
 (0)