Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Datajuicer Data juicer OptimizeQueryMapper

From Leeroopedia
Revision as of 12:22, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Datajuicer_Data_juicer_OptimizeQueryMapper.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Data_Processing, Mapping
Last Updated 2026-02-14 16:00 GMT

Overview

Concrete tool for optimizing queries in question-answer pairs provided by Data-Juicer.

Description

OptimizeQueryMapper is a mapper operator that extends OptimizeQAMapper to optimize only the query (question) in a QA pair, making it more specific and detailed while ensuring the original answer can still address it. It uses a specialized Chinese system prompt instructing the model to optimize only the question. The parse_output method returns the stripped raw output as the optimized query and None for the answer, leaving the original answer unchanged. Inherits all model configuration, retry logic, and VLLM/HF/API support from the parent class. Requires CUDA acceleration.

Usage

Use when answer quality is already adequate but questions need to be more specific or detailed for better instruction-following training data.

Code Reference

Source Location

Signature

@OPERATORS.register_module("optimize_query_mapper")
class OptimizeQueryMapper(OptimizeQAMapper):
    def __init__(self,
                 api_or_hf_model: str = "Qwen/Qwen2.5-7B-Instruct",
                 is_hf_model: bool = True,
                 *,
                 api_endpoint: Optional[str] = None,
                 response_path: Optional[str] = None,
                 system_prompt: Optional[str] = None,
                 input_template: Optional[str] = None,
                 qa_pair_template: Optional[str] = None,
                 output_pattern: Optional[str] = None,
                 try_num: PositiveInt = 3,
                 enable_vllm: bool = False,
                 model_params: Optional[Dict] = None,
                 sampling_params: Optional[Dict] = None,
                 **kwargs):

Import

from data_juicer.ops.mapper.optimize_query_mapper import OptimizeQueryMapper

I/O Contract

Inputs

Name Type Required Description
api_or_hf_model str No API or HuggingFace model name, defaults to "Qwen/Qwen2.5-7B-Instruct"
is_hf_model bool No If True, use HuggingFace model; otherwise use API, defaults to True
api_endpoint Optional[str] No URL endpoint for the API
response_path Optional[str] No Path to extract content from API response
system_prompt Optional[str] No System prompt for guiding optimization; defaults to Chinese query optimization prompt
input_template Optional[str] No Template for building model input
qa_pair_template Optional[str] No Template for formatting question-answer pairs
output_pattern Optional[str] No Regex pattern to extract question and answer from model response
try_num PositiveInt No Number of retry attempts on error, defaults to 3
enable_vllm bool No Whether to use VLLM for inference acceleration, defaults to False
model_params Optional[Dict] No Parameters for initializing the model
sampling_params Optional[Dict] No Sampling parameters for text generation

Outputs

Name Type Description
samples Dict Transformed samples with optimized query replacing the original question

Usage Examples

process:
  - optimize_query_mapper:
      api_or_hf_model: "Qwen/Qwen2.5-7B-Instruct"
      is_hf_model: true
      try_num: 3

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment