data_juicer.ops.mapper#
- class data_juicer.ops.mapper.AudioAddGaussianNoiseMapper(min_amplitude: float = 0.001, max_amplitude: float = 0.015, p: float = 0.5, save_dir: str = None, *args, **kwargs)[source]#
Bases:
MapperMapper to add gaussian noise to audio.
- __init__(min_amplitude: float = 0.001, max_amplitude: float = 0.015, p: float = 0.5, save_dir: str = None, *args, **kwargs)[source]#
Initialization method.
- min_amplitude: float unit: linear amplitude.
Default: 0.001. Minimum noise amplification factor.
- max_amplitude: float unit: linear amplitude.
Default: 0.015. Maximum noise amplification factor.
- p: float range: [0.0, 1.0]. Default: 0.5.
The probability of applying this transform.
- save_dir: str. Default: None.
The directory where generated audio files will be stored. If not specified, outputs will be saved in the same directory as their corresponding input files. This path can alternatively be defined by setting the DJ_PRODUCED_DATA_DIR environment variable.
- class data_juicer.ops.mapper.AudioFFmpegWrappedMapper(filter_name: str | None = None, filter_kwargs: Dict | None = None, global_args: List[str] | None = None, capture_stderr: bool = True, overwrite_output: bool = True, save_dir: str = None, *args, **kwargs)[source]#
Bases:
MapperSimple wrapper for FFmpeg audio filters.
- __init__(filter_name: str | None = None, filter_kwargs: Dict | None = None, global_args: List[str] | None = None, capture_stderr: bool = True, overwrite_output: bool = True, save_dir: str = None, *args, **kwargs)[source]#
Initialization method.
- Parameters:
filter_name โ ffmpeg audio filter name.
filter_kwargs โ keyword-arguments passed to ffmpeg filter.
global_args โ list-arguments passed to ffmpeg command-line.
capture_stderr โ whether to capture stderr.
overwrite_output โ whether to overwrite output file.
save_dir โ The directory where generated audio files will be stored. If not specified, outputs will be saved in the same directory as their corresponding input files. This path can alternatively be defined by setting the DJ_PRODUCED_DATA_DIR environment variable.
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.CalibrateQAMapper(api_model: str = 'gpt-4o', *, api_endpoint: str | None = None, response_path: str | None = None, system_prompt: str | None = None, input_template: str | None = None, reference_template: str | None = None, qa_pair_template: str | None = None, output_pattern: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Bases:
MapperMapper to calibrate question-answer pairs based on reference text.
- DEFAULT_SYSTEM_PROMPT = '่ฏทๆ นๆฎๆไพ็ใๅ่ไฟกๆฏใๅฏนใ้ฎ้ขใๅใๅ็ญใ่ฟ่กๆ กๅ๏ผไฝฟๅ ถๆดๅ ่ฏฆ็ปใๅ็กฎใ\nๆ็ งไปฅไธๆ ผๅผ่พๅบ๏ผ\nใ้ฎ้ขใ\nๆ กๅๅ็้ฎ้ข\nใๅ็ญใ\nๆ กๅๅ็ๅ็ญ'#
- DEFAULT_INPUT_TEMPLATE = '{reference}\n{qa_pair}'#
- DEFAULT_REFERENCE_TEMPLATE = 'ใๅ่ไฟกๆฏใ\n{}'#
- DEFAULT_QA_PAIR_TEMPLATE = 'ใ้ฎ้ขใ\n{}\nใๅ็ญใ\n{}'#
- DEFAULT_OUTPUT_PATTERN = 'ใ้ฎ้ขใ\\s*(.*?)\\s*ใๅ็ญใ\\s*(.*)'#
- __init__(api_model: str = 'gpt-4o', *, api_endpoint: str | None = None, response_path: str | None = None, system_prompt: str | None = None, input_template: str | None = None, reference_template: str | None = None, qa_pair_template: str | None = None, output_pattern: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Initialization method.
- Parameters:
api_model โ API model name.
api_endpoint โ URL endpoint for the API.
response_path โ Path to extract content from the API response. Defaults to โchoices.0.message.contentโ.
system_prompt โ System prompt for the calibration task.
input_template โ Template for building the model input.
reference_template โ Template for formatting the reference text.
qa_pair_template โ Template for formatting question-answer pairs.
output_pattern โ Regular expression for parsing model output.
try_num โ The number of retry attempts when there is an API call error or output parsing error.
model_params โ Parameters for initializing the API model.
sampling_params โ Extra parameters passed to the API call. e.g {โtemperatureโ: 0.9, โtop_pโ: 0.95}
kwargs โ Extra keyword arguments.
- class data_juicer.ops.mapper.CalibrateQueryMapper(api_model: str = 'gpt-4o', *, api_endpoint: str | None = None, response_path: str | None = None, system_prompt: str | None = None, input_template: str | None = None, reference_template: str | None = None, qa_pair_template: str | None = None, output_pattern: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Bases:
CalibrateQAMapperMapper to calibrate query in question-answer pairs based on reference text.
- DEFAULT_SYSTEM_PROMPT = '่ฏทๆ นๆฎๆไพ็ใๅ่ไฟกๆฏใๅฏน้ฎ็ญๅฏนไธญ็ใ้ฎ้ขใ่ฟ่กๆ กๅ๏ผ ไฝฟๅ ถๆดๅ ่ฏฆ็ปใๅ็กฎ๏ผไธไปๅฏไปฅ็ฑๅ็ญๆกๅ็ญใๅช่พๅบๆ กๅๅ็้ฎ้ข๏ผไธ่ฆ่พๅบๅคไฝๅ ๅฎนใ'#
- class data_juicer.ops.mapper.CalibrateResponseMapper(api_model: str = 'gpt-4o', *, api_endpoint: str | None = None, response_path: str | None = None, system_prompt: str | None = None, input_template: str | None = None, reference_template: str | None = None, qa_pair_template: str | None = None, output_pattern: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Bases:
CalibrateQAMapperMapper to calibrate response in question-answer pairs based on reference text.
- DEFAULT_SYSTEM_PROMPT = '่ฏทๆ นๆฎๆไพ็ใๅ่ไฟกๆฏใๅฏน้ฎ็ญๅฏนไธญ็ใๅ็ญใ่ฟ่กๆ กๅ๏ผ ไฝฟๅ ถๆดๅ ่ฏฆ็ปใๅ็กฎ๏ผไธไปๅฏไปฅๅ็ญๅ้ฎ้ขใๅช่พๅบๆ กๅๅ็ๅ็ญ๏ผไธ่ฆ่พๅบๅคไฝๅ ๅฎนใ'#
- class data_juicer.ops.mapper.ChineseConvertMapper(mode: str = 's2t', *args, **kwargs)[source]#
Bases:
MapperMapper to convert Chinese between Traditional Chinese, Simplified Chinese and Japanese Kanji.
- __init__(mode: str = 's2t', *args, **kwargs)[source]#
Initialization method.
- Parameters:
mode โ
Choose the mode to convert Chinese:
s2t: Simplified Chinese to Traditional Chinese,
t2s: Traditional Chinese to Simplified Chinese,
s2tw: Simplified Chinese to Traditional Chinese (Taiwan Standard),
tw2s: Traditional Chinese (Taiwan Standard) to Simplified Chinese,
s2hk: Simplified Chinese to Traditional Chinese (Hong Kong variant),
hk2s: Traditional Chinese (Hong Kong variant) to Simplified Chinese,
s2twp: Simplified Chinese to Traditional Chinese (Taiwan Standard) with Taiwanese idiom,
tw2sp: Traditional Chinese (Taiwan Standard) to Simplified Chinese with Mainland Chinese idiom,
t2tw: Traditional Chinese to Traditional Chinese (Taiwan Standard),
tw2t: Traditional Chinese (Taiwan standard) to Traditional Chinese,
hk2t: Traditional Chinese (Hong Kong variant) to Traditional Chinese,
t2hk: Traditional Chinese to Traditional Chinese (Hong Kong variant),
t2jp: Traditional Chinese Characters (Kyลซjitai) to New Japanese Kanji,
jp2t: New Japanese Kanji (Shinjitai) to Traditional Chinese Characters,
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.CleanCopyrightMapper(*args, **kwargs)[source]#
Bases:
MapperMapper to clean copyright comments at the beginning of the text samples.
- class data_juicer.ops.mapper.CleanEmailMapper(pattern: str | None = None, repl: str = '', *args, **kwargs)[source]#
Bases:
MapperMapper to clean email in text samples.
- class data_juicer.ops.mapper.CleanHtmlMapper(*args, **kwargs)[source]#
Bases:
MapperMapper to clean html code in text samples.
- class data_juicer.ops.mapper.CleanIpMapper(pattern: str | None = None, repl: str = '', *args, **kwargs)[source]#
Bases:
MapperMapper to clean ipv4 and ipv6 address in text samples.
- class data_juicer.ops.mapper.CleanLinksMapper(pattern: str | None = None, repl: str = '', *args, **kwargs)[source]#
Bases:
MapperMapper to clean links like http/https/ftp in text samples.
- class data_juicer.ops.mapper.DialogIntentDetectionMapper(api_model: str = 'gpt-4o', intent_candidates: List[str] | None = None, max_round: Annotated[int, Ge(ge=0)] = 10, *, labels_key: str = 'dialog_intent_labels', analysis_key: str = 'dialog_intent_labels_analysis', api_endpoint: str | None = None, response_path: str | None = None, system_prompt: str | None = None, query_template: str | None = None, response_template: str | None = None, candidate_template: str | None = None, analysis_template: str | None = None, labels_template: str | None = None, analysis_pattern: str | None = None, labels_pattern: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Bases:
MapperMapper to generate userโs intent labels in dialog. Input from history_key, query_key and response_key. Output lists of labels and analysis for queries in the dialog.
- DEFAULT_SYSTEM_PROMPT = '่ฏทๅคๆญ็จๆทๅLLMๅค่ฝฎๅฏน่ฏไธญ็จๆท็ๆๅพใ\n่ฆๆฑ๏ผ\n- ้่ฆๅ ่ฟ่กๅๆ๏ผ็ถๅๅๅบ็จๆทๆๅ ทๆ็ๆๅพ๏ผไธ้ขๆฏไธไธชๆ ทไพ๏ผ่ฏทๆจกไปฟๆ ทไพๆ ผๅผ่พๅบใ\n็จๆท๏ผไฝ ๅฅฝ๏ผๆๆ่ฟๅฏนไบบๅทฅๆบ่ฝๅพๆๅ ด่ถฃ๏ผ่ฝ็ปๆ่ฎฒ่ฎฒไปไนๆฏๆบๅจๅญฆไน ๅ๏ผ\nๆๅพๅๆ๏ผ็จๆทๅจ่ฏทๆฑไฟกๆฏ๏ผๅธๆไบ่งฃๆๅ ณๆบๅจๅญฆไน ็ๅบ็ก็ฅ่ฏใ\nๆๅพ็ฑปๅซ๏ผไฟกๆฏๆฅๆพ\nLLM๏ผไฝ ๅฅฝ๏ผๅฝ็ถๅฏไปฅใๆบๅจๅญฆไน ๆฏไธ็งไบบๅทฅๆบ่ฝๆนๆณ๏ผๅ ่ฎธ่ฎก็ฎๆบ้่ฟๆฐๆฎ่ชๅจๆน่ฟๅๅญฆไน ใ\n็จๆท๏ผๅฌ่ตทๆฅๅพๆ่ถฃ๏ผๆๆฒกๆๆจ่็ๅ ฅ้จไนฆ็ฑๆ่ตๆ๏ผ\nๆๅพๅๆ๏ผ็จๆทๅจ่ฏทๆฑๅปบ่ฎฎ๏ผๅธๆ่ทๅๅ ณไบๆบๅจๅญฆไน ็ๅ ฅ้จ่ตๆบใ\nๆๅพ็ฑปๅซ๏ผ่ฏทๆฑๅปบ่ฎฎ\nLLM๏ผๆๅพๅคไธ้็ๅ ฅ้จไนฆ็ฑๅ่ตๆบใไธๆฌๅธธ่ขซๆจ่็ไนฆๆฏใPythonๆบๅจๅญฆไน ๅฎ่ทตใ๏ผPython Machine Learning๏ผ๏ผๅฎๆถต็ไบๅบ็ก็ฅ่ฏๅไธไบๅฎ้ ๆกไพใๆญคๅค๏ผๆจ่ฟๅฏไปฅๅ่CourseraๆedXไธ็ๅจ็บฟ่ฏพ็จ๏ผ่ฟไบ่ฏพ็จๆไพไบ็ณป็ป็ๅญฆไน ่ทฏๅพใ\n็จๆท๏ผ่ฐข่ฐขไฝ ็ๅปบ่ฎฎ๏ผๆ่ฟๆณ็ฅ้๏ผๅญฆไน ๆบๅจๅญฆไน ้่ฆไปไนๆ ท็ๆฐๅญฆๅบ็ก๏ผ\nๆๅพๅๆ๏ผ็จๆทๅจๅฏปๆฑไฟกๆฏ๏ผๅธๆไบ่งฃๅญฆไน ๆบๅจๅญฆไน ๆ้็ๅๆๆกไปถ๏ผ็นๅซๆฏๅจๆฐๅญฆๆน้ขใ\nๆๅพ็ฑปๅซ๏ผไฟกๆฏๆฅๆพ\nLLM๏ผๅญฆไน ๆบๅจๅญฆไน ้ๅธธ้่ฆไธๅฎ็ๆฐๅญฆๅบ็ก๏ผ็นๅซๆฏ็บฟๆงไปฃๆฐใๆฆ็่ฎบๅ็ป่ฎกๅญฆใ่ฟไบๆฐๅญฆ้ขๅๅธฎๅฉ็่งฃ็ฎๆณ็ๅทฅไฝๅ็ๅๆฐๆฎๆจกๅผๅๆใๅฆๆๆจๅฏน่ฟไบไธป้ขไธๅคช็ๆ๏ผๅปบ่ฎฎๅ ไป็ธๅ ณๅบ็กไนฆ็ฑๆๅจ็บฟ่ตๆบๅผๅงๅญฆไน ใ\n็จๆท๏ผๆ็ฝไบ๏ผๆไผๅ ่กฅไน ่ฟไบๅบ็ก็ฅ่ฏใๅๆฌกๆ่ฐขไฝ ็ๅธฎๅฉ๏ผ\nๆๅพๅๆ๏ผ็จๆท่กจ่พพๆ่ฐข๏ผๅนถ่กจ็คบ่ฎกๅไป่ฏธ่กๅจๆฅ่กฅๅ ๆ้็ๅบ็ก็ฅ่ฏใ\nๆๅพ็ฑปๅซ๏ผๅ ถไป'#
- DEFAULT_QUERY_TEMPLATE = '็จๆท๏ผ{query}\n'#
- DEFAULT_RESPONSE_TEMPLATE = 'LLM๏ผ{response}\n'#
- DEFAULT_CANDIDATES_TEMPLATE = 'ๅค้ๆๅพ็ฑปๅซ๏ผ[{candidate_str}]'#
- DEFAULT_ANALYSIS_TEMPLATE = 'ๆๅพๅๆ๏ผ{analysis}\n'#
- DEFAULT_LABELS_TEMPLATE = 'ๆๅพ็ฑปๅซ๏ผ{labels}\n'#
- DEFAULT_ANALYSIS_PATTERN = 'ๆๅพๅๆ๏ผ(.*?)\n'#
- DEFAULT_LABELS_PATTERN = 'ๆๅพ็ฑปๅซ๏ผ(.*?)($|\n)'#
- __init__(api_model: str = 'gpt-4o', intent_candidates: List[str] | None = None, max_round: Annotated[int, Ge(ge=0)] = 10, *, labels_key: str = 'dialog_intent_labels', analysis_key: str = 'dialog_intent_labels_analysis', api_endpoint: str | None = None, response_path: str | None = None, system_prompt: str | None = None, query_template: str | None = None, response_template: str | None = None, candidate_template: str | None = None, analysis_template: str | None = None, labels_template: str | None = None, analysis_pattern: str | None = None, labels_pattern: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Initialization method.
- Parameters:
api_model โ API model name.
intent_candidates โ The output intent candidates. Use the intent labels of the open domain if it is None.
max_round โ The max num of round in the dialog to build the prompt.
labels_key โ The key name in the meta field to store the output labels. It is โdialog_intent_labelsโ in default.
analysis_key โ The key name in the meta field to store the corresponding analysis. It is โdialog_intent_labels_analysisโ in default.
api_endpoint โ URL endpoint for the API.
response_path โ Path to extract content from the API response. Defaults to โchoices.0.message.contentโ.
system_prompt โ System prompt for the task.
query_template โ Template for query part to build the input prompt.
response_template โ Template for response part to build the input prompt.
candidate_template โ Template for intent candidates to build the input prompt.
analysis_template โ Template for analysis part to build the input prompt.
labels_template โ Template for labels to build the input prompt.
analysis_pattern โ Pattern to parse the return intent analysis.
labels_pattern โ Pattern to parse the return intent labels.
try_num โ The number of retry attempts when there is an API call error or output parsing error.
model_params โ Parameters for initializing the API model.
sampling_params โ Extra parameters passed to the API call. e.g {โtemperatureโ: 0.9, โtop_pโ: 0.95}
kwargs โ Extra keyword arguments.
- class data_juicer.ops.mapper.DialogSentimentDetectionMapper(api_model: str = 'gpt-4o', sentiment_candidates: List[str] | None = None, max_round: Annotated[int, Ge(ge=0)] = 10, *, labels_key: str = 'dialog_sentiment_labels', analysis_key: str = 'dialog_sentiment_labels_analysis', api_endpoint: str | None = None, response_path: str | None = None, system_prompt: str | None = None, query_template: str | None = None, response_template: str | None = None, candidate_template: str | None = None, analysis_template: str | None = None, labels_template: str | None = None, analysis_pattern: str | None = None, labels_pattern: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Bases:
MapperMapper to generate userโs sentiment labels in dialog. Input from history_key, query_key and response_key. Output lists of labels and analysis for queries in the dialog.
- DEFAULT_SYSTEM_PROMPT = '่ฏทๅคๆญ็จๆทๅLLMๅค่ฝฎๅฏน่ฏไธญ็จๆทๆๅ ทๆ็ๆ ็ปชใ\n่ฆๆฑ๏ผ\n- ้่ฆๅ ่ฟ่กๅๆ๏ผ็ถๅ็ฝๅ็จๆทๆๅ ทๆ็ๆ ็ปช๏ผไธ้ขๆฏไธไธชๆ ทไพ๏ผ่ฏทๆจกไปฟๆ ทไพๆ ผๅผ่พๅบใ\n็จๆท๏ผๆ่ฟๅทฅไฝๅๅๅฅฝๅคง๏ผๆ่งๅพๆดไธชไบบ้ฝๅฟซ่ขซๅๅฎไบใ\nๆ ๆๅๆ๏ผ็จๆท็่จ่ฏญไธญ้้ฒๅบๆๆพ็ๅๅๅ็ฒๆซๆ๏ผๅฏ่ฝ่ฟๅคนๆ็ไธไบๆ ๅฉๅ็ฆ่ใ\nๆ ๆ็ฑปๅซ๏ผๅๅใ็ฒๆซใๆ ๅฉใ็ฆ่\nLLM๏ผๅฌ่ตทๆฅไฝ ็็ๆฟๅไบๅพๅค๏ผ้ขไธด่ฟ็งๆ ๅต็กฎๅฎไธๅฎนๆใๆๆฒกๆ่่่ฟๆพไธไบๆพๆพ็ๆนๅผ๏ผๆฏๅฆๅฌ้ณไนๆ่ ๆฃๆญฅๆฅๅ่ฝปๅๅๅข๏ผ\n็จๆท๏ผ่ฏ่ฟไบ๏ผไฝๆฏๅฅฝๅๆฒกไปไนๆๆ๏ผๆฏๅคฉ็ไบๆ ้ฝๅ ็งฏๅฆๅฑฑใ\nๆ ๆๅๆ๏ผ็จๆทๆๅฐๆ ๅ่งฃๅณ็ฐ็ถ๏ผๆๆซ่ดฅๆ๏ผๅนถไธๅฏนๅฐ่ฏๆพๆพ็ๆนๅผๅคฑๅปไฟกๅฟใ\nๆ ๆ็ฑปๅซ๏ผๆ ๅใๆซ่ดฅ\nLLM๏ผๆ็่งฃไฝ ็ๆๅ๏ผๆๆถๅๅๅ็งฏ็ดฏๅฐไธๅฎ็จๅบฆ็กฎๅฎ่ฎฉไบบ้พไปฅๆฟๅใๆ่ฎธไฝ ๅฏไปฅๅฐ่ฏ่งๅไธไธๆถ้ด๏ผๆไปปๅกๅๆๅฐๅๆฅๅฎๆ๏ผ่ฟๆ ทๅฏ่ฝไผๅๅฐไธไบๅๅๆใ\n็จๆท๏ผ่ฟไธชไธปๆไธ้๏ผๆไผ่ฏ็่ฎฉ่ชๅทฑๆดๆๆก็ไธไบ๏ผ่ฐข่ฐขไฝ ็ๅปบ่ฎฎใ\nๆ ๆๅๆ๏ผ็จๆทๅฏนๅปบ่ฎฎ่กจ็ฐๅบ่ฎคๅๅๆๆฟ๏ผๅๆถๅฑ็ฐๅบ่ฏๅพ็งฏๆ้ขๅฏน้ฎ้ข็ๆๅบฆใ\nๆ ๆ็ฑปๅซ๏ผ่ฎคๅใๆๆฟใ็งฏๆ\nLLM๏ผไธ็จ่ฐข๏ผๆๅพ้ซๅ ด่ฝๅธฎๅฐไฝ ใ่ฎฐๅพ็ป่ชๅทฑไธไบๆถ้ดๅป้ๅบๆฐ็่ฎกๅ๏ผๆไปปไฝ้่ฆ้ๆถๅฏไปฅ่ทๆ่ฏดๅฆ๏ผ\n'#
- DEFAULT_QUERY_TEMPLATE = '็จๆท๏ผ{query}\n'#
- DEFAULT_RESPONSE_TEMPLATE = 'LLM๏ผ{response}\n'#
- DEFAULT_CANDIDATES_TEMPLATE = 'ๅค้ๆ ๆ็ฑปๅซ๏ผ[{candidate_str}]'#
- DEFAULT_ANALYSIS_TEMPLATE = 'ๆ ๆๅๆ๏ผ{analysis}\n'#
- DEFAULT_LABELS_TEMPLATE = 'ๆ ๆ็ฑปๅซ๏ผ{labels}\n'#
- DEFAULT_ANALYSIS_PATTERN = 'ๆ ๆๅๆ๏ผ(.*?)\n'#
- DEFAULT_LABELS_PATTERN = 'ๆ ๆ็ฑปๅซ๏ผ(.*?)($|\n)'#
- __init__(api_model: str = 'gpt-4o', sentiment_candidates: List[str] | None = None, max_round: Annotated[int, Ge(ge=0)] = 10, *, labels_key: str = 'dialog_sentiment_labels', analysis_key: str = 'dialog_sentiment_labels_analysis', api_endpoint: str | None = None, response_path: str | None = None, system_prompt: str | None = None, query_template: str | None = None, response_template: str | None = None, candidate_template: str | None = None, analysis_template: str | None = None, labels_template: str | None = None, analysis_pattern: str | None = None, labels_pattern: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Initialization method.
- Parameters:
api_model โ API model name.
sentiment_candidates โ The output sentiment candidates. Use open-domain sentiment labels if it is None.
max_round โ The max num of round in the dialog to build the prompt.
labels_key โ The key name in the meta field to store the output labels. It is โdialog_sentiment_labelsโ in default.
analysis_key โ The key name in the meta field to store the corresponding analysis. It is โdialog_sentiment_labels_analysisโ in default.
api_endpoint โ URL endpoint for the API.
response_path โ Path to extract content from the API response. Defaults to โchoices.0.message.contentโ.
system_prompt โ System prompt for the task.
query_template โ Template for query part to build the input prompt.
response_template โ Template for response part to build the input prompt.
candidate_template โ Template for sentiment candidates to build the input prompt.
analysis_template โ Template for analysis part to build the input prompt.
labels_template โ Template for labels part to build the input prompt.
analysis_pattern โ Pattern to parse the return sentiment analysis.
labels_pattern โ Pattern to parse the return sentiment labels.
try_num โ The number of retry attempts when there is an API call error or output parsing error.
model_params โ Parameters for initializing the API model.
sampling_params โ Extra parameters passed to the API call. e.g {โtemperatureโ: 0.9, โtop_pโ: 0.95}
kwargs โ Extra keyword arguments.
- class data_juicer.ops.mapper.DialogSentimentIntensityMapper(api_model: str = 'gpt-4o', max_round: Annotated[int, Ge(ge=0)] = 10, *, intensities_key: str = 'dialog_sentiment_intensity', analysis_key: str = 'dialog_sentiment_intensity_analysis', api_endpoint: str | None = None, response_path: str | None = None, system_prompt: str | None = None, query_template: str | None = None, response_template: str | None = None, analysis_template: str | None = None, intensity_template: str | None = None, analysis_pattern: str | None = None, intensity_pattern: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Bases:
MapperMapper to predict userโs sentiment intensity (from -5 to 5 in default prompt) in dialog. Input from history_key, query_key and response_key. Output lists of intensities and analysis for queries in the dialog.
- DEFAULT_SYSTEM_PROMPT = '่ฏทๅคๆญ็จๆทๅLLMๅค่ฝฎๅฏน่ฏไธญ็จๆท็ๆ ็ปชๅๅใ\n่ฆๆฑ๏ผ\n- ็จๆทๆ ็ปชๅผๆฏ-5ๅฐ5ไน้ดๅฐๆดๆฐ๏ผ-5่กจ็คบๆๅบฆ่ด้ข๏ผ5่กจ็คบๆๅบฆๆญฃ้ข๏ผ-5ๅฐ5ไน้ดๆฐๅผ่กจ็คบๆ ็ปชไป่ด้ข้ๆธๅฐๆญฃ้ข็ๅๅ่ฟ็จ๏ผ0ไปฃ่กจๆ ๅ็ปชไธญๆงใ\n- ๅช่พๅบๅฝ่ฝฎๅฏน่ฏ็ๅๆ๏ผไธ่ฆ็ปง็ปญๆ้ ๅฏน่ฏใ\n- ้่ฆๅ ่ฟ่กๅๆ๏ผ็ถๅ็กฎๅฎ็จๆท็ๆ ็ปชๅผ๏ผไธ้ขๆฏไธไธชๆ ทไพ๏ผ่ฏทๆจกไปฟๆ ทไพๆ ผๅผ่พๅบใ\n็จๆท๏ผไฝ ๅฅฝ๏ผๆๅฏนๅฏๆ็ปญๅๅฑ็ๅฎไนๆ็นๆจก็ณ๏ผๅธฎๆ่งฃ้ไธไธ๏ผ\nๆ ็ปชๅๆ๏ผๅๅผๅง๏ผ่ฟๆฒกๅพๅฐLLMๅๅค๏ผ็จๆทๆ ็ปชๅไธญๆงใ\nๆ ็ปชๅผ๏ผ0\nLLM๏ผๅฝ็ถๅฏไปฅ๏ผๅฏๆ็ปญๅๅฑๆฏๆๅจๆปก่ถณๅฝไปฃไบบ็้ๆฑ็ๅๆถ๏ผไธๆๅฎณๅญๅญๅไปฃๆปก่ถณๅ ถ่ช่บซ้ๆฑ็่ฝๅ็ๅๅฑๆจกๅผใๅฎๅ ๆฌ็ปๆตๅๅฑใ็คพไผๅๅฑๅ็ฏๅขไฟๆคไธไธชไธป่ฆๆน้ขใ้่ฟๅ็ๅฉ็จ่ตๆบๅไฟๆค็ฏๅข๏ผๆไปฌๅฏไปฅ็กฎไฟๆชๆฅ็ไธไปฃไน่ฝไบซๆๅฅๅ จ็็ๆ็ณป็ปๅ็ปๆตๅถๅบฆใ\n็จๆท๏ผ่ฐข่ฐขไฝ ็่งฃ้๏ผ้ฃไฝ ่ฝๅ่ฏๆไธไบๆฎ้ไบบๅฏไปฅ้ๅ็ๅฏๆ็ปญ็ๆดปๆนๅผๅ๏ผ\nๆ ็ปชๅๆ๏ผๅฏนๅ็ญๆๅฐๆปกๆ๏ผๆ ็ปชๆญฃ้ขใ\nๆ ็ปชๅผ๏ผ1\nLLM๏ผๅฝ็ถๅฏไปฅ๏ผๆฎ้ไบบๅฏไปฅ้่ฟๅๅฐไธๆฌกๆงไบงๅ็ไฝฟ็จใ้ๆฉๅ ฌๅ ฑไบค้ๆๆผ่ฝฆใ่็บฆ็จๆฐดใไปฅๅๆฏๆๆฌๅฐๅๅฏๆ็ปญๅๅฑ็ไผไธ็ญๆนๅผๆฅ่ทต่กๅฏๆ็ปญ็ๆดปใๆญคๅค๏ผๅ ณๆณจๅๅพๅ็ฑปๅๅค็จ็ตๅญ่ดฆๅไนๆฏไธ้็้ๆฉใ\n็จๆท๏ผไฝ ๆๅฐๆฏๆๆฌๅฐไผไธ๏ผ่ฟไธ็นๆๅพๆๅ ด่ถฃใ่ฝ่ฏฆ็ป่ฏด่ฏดไธบไปไน่ฟๅฏนๅฏๆ็ปญๅๅฑๆไฟ่ฟไฝ็จๅ๏ผ\nๆ ็ปชๅๆ๏ผ่งๅพๅ็ญๅฎ็จไธๅ ทไฝ๏ผๆ ็ปช่ฟไธๆญฅ่ฝฌๅฅฝใ\nๆ ็ปชๅผ๏ผ2\nLLM๏ผๅ๏ผๆๆ่ฟๅ็ฐไบไธ้จๆฐ็ตๅฝฑ๏ผ่ฎฒ่ฟฐไบไธไธชๅ ณไบๅคๆไบบๅๅฐ็ๅ่ๅไฝไฟๆค็ฏๅข็ๆ ไบใ่ฝ็ถๅฎๆฏ็งๅนป็๏ผไฝๅพๆๅฏๅๆง๏ผๆจ่ไฝ ๅป็็ใ\n็จๆท๏ผไปไนๅ๏ผๆ นๆฌๆฏ็ญ้ๆ้ฎใ\nๆ ็ปชๅๆ๏ผLLMๆฒกๆๅๅบ้ฎ้ข่ๆฏๆๅฐๆ ๅ ณๅ ๅฎน๏ผๅฏผ่ด็จๆทๆ ็ปช็ด็บฟไธ้ใ\nๆ ็ปชๅผ๏ผ-2\nLLM๏ผๆฑๆญๅๆ็ๅ้ข๏ผๆฏๆๆฌๅฐไผไธๆๅฉไบๅๅฐ้ฟ้่ฟ่พไบง็็็ขณ่ถณ่ฟน๏ผไฝฟไพๅบ้พๆดๅ ็ฏไฟใๆญคๅค๏ผๆฌๅฐไผไธไนๆดๆๅฏ่ฝ้็จๅฏๆ็ปญ็็ไบงๆนๅผ๏ผๅๆถไฟ่ฟ็คพๅบ็ปๆต็็น่ฃใ\n็จๆท๏ผ่ฟ่กๅง๏ผ็ฎไฝ ่ฝๅคๆฐๅๆฅใ\nๆ ็ปชๅๆ๏ผ้ฎ้ขๅพๅฐ่งฃ็ญ๏ผ้ฎ้ขๅ้ขๅพๅฐ็บ ๆญฃ๏ผๆ ็ปช็จๆๅฅฝ่ฝฌใ\nๆ ็ปชๅผ๏ผ-1\n'#
- DEFAULT_QUERY_TEMPLATE = '็จๆท๏ผ{query}\n'#
- DEFAULT_RESPONSE_TEMPLATE = 'LLM๏ผ{response}\n'#
- DEFAULT_ANALYSIS_TEMPLATE = 'ๆ ็ปชๅๆ๏ผ{analysis}\n'#
- DEFAULT_INTENSITY_TEMPLATE = 'ๆ ็ปชๅผ๏ผ{intensity}\n'#
- DEFAULT_ANALYSIS_PATTERN = 'ๆ ็ปชๅๆ๏ผ(.*?)\n'#
- DEFAULT_INTENSITY_PATTERN = 'ๆ ็ปชๅผ๏ผ(.*?)($|\n)'#
- __init__(api_model: str = 'gpt-4o', max_round: Annotated[int, Ge(ge=0)] = 10, *, intensities_key: str = 'dialog_sentiment_intensity', analysis_key: str = 'dialog_sentiment_intensity_analysis', api_endpoint: str | None = None, response_path: str | None = None, system_prompt: str | None = None, query_template: str | None = None, response_template: str | None = None, analysis_template: str | None = None, intensity_template: str | None = None, analysis_pattern: str | None = None, intensity_pattern: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Initialization method.
- Parameters:
api_model โ API model name.
max_round โ The max num of round in the dialog to build the prompt.
intensities_key โ The key name in the meta field to store the output sentiment intensities. It is โdialog_sentiment_intensityโ in default.
analysis_key โ The key name in the meta field to store the corresponding analysis. It is โdialog_sentiment_intensity_analysisโ in default.
api_endpoint โ URL endpoint for the API.
response_path โ Path to extract content from the API response. Defaults to โchoices.0.message.contentโ.
system_prompt โ System prompt for the task.
query_template โ Template for query part to build the input prompt.
response_template โ Template for response part to build the input prompt.
analysis_template โ Template for analysis part to build the input prompt.
intensity_template โ Template for intensity part to build the input prompt.
analysis_pattern โ Pattern to parse the return sentiment analysis.
intensity_pattern โ Pattern to parse the return sentiment intensity.
try_num โ The number of retry attempts when there is an API call error or output parsing error.
model_params โ Parameters for initializing the API model.
sampling_params โ Extra parameters passed to the API call. e.g {โtemperatureโ: 0.9, โtop_pโ: 0.95}
kwargs โ Extra keyword arguments.
- class data_juicer.ops.mapper.DialogTopicDetectionMapper(api_model: str = 'gpt-4o', topic_candidates: List[str] | None = None, max_round: Annotated[int, Ge(ge=0)] = 10, *, labels_key: str = 'dialog_topic_labels', analysis_key: str = 'dialog_topic_labels_analysis', api_endpoint: str | None = None, response_path: str | None = None, system_prompt: str | None = None, query_template: str | None = None, response_template: str | None = None, candidate_template: str | None = None, analysis_template: str | None = None, labels_template: str | None = None, analysis_pattern: str | None = None, labels_pattern: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Bases:
MapperMapper to generate userโs topic labels in dialog. Input from history_key, query_key and response_key. Output lists of labels and analysis for queries in the dialog.
- DEFAULT_SYSTEM_PROMPT = '่ฏทๅคๆญ็จๆทๅLLMๅค่ฝฎๅฏน่ฏไธญ็จๆทๆ่ฎจ่ฎบ็่ฏ้ขใ\n่ฆๆฑ๏ผ\n- ้ๅฏน็จๆท็ๆฏไธชquery๏ผ้่ฆๅ ่ฟ่กๅๆ๏ผ็ถๅๅๅบ็จๆทๆญฃๅจ่ฎจ่ฎบ็่ฏ้ข๏ผไธ้ขๆฏไธไธชๆ ทไพ๏ผ่ฏทๆจกไปฟๆ ทไพๆ ผๅผ่พๅบใ\n็จๆท๏ผไฝ ๅฅฝ๏ผไปๅคฉๆไปฌๆฅ่่็งฆๅง็ๅงใ\n่ฏ้ขๅๆ๏ผ็จๆทๆๅฐ็งฆๅง็๏ผ่ฟๆฏไธญๅฝๅๅฒไธ็ฌฌไธไฝ็ๅธใ\n่ฏ้ข็ฑปๅซ๏ผๅๅฒ\nLLM๏ผๅฝ็ถๅฏไปฅ๏ผ็งฆๅง็ๆฏไธญๅฝๅๅฒไธ็ฌฌไธไธช็ปไธๅ จๅฝ็็ๅธ๏ผไปๅจๅ ฌๅ ๅ221ๅนดๅปบ็ซไบ็งฆๆ๏ผๅนถ้ๅไบไธ็ณปๅ้่ฆ็ๆน้ฉๆชๆฝ๏ผๅฆ็ปไธๆๅญใๅบฆ้่กกๅ่ดงๅธ็ญใ\n็จๆท๏ผ็งฆๅง็ไฟฎๅปบ็้ฟๅๅ็ฐๅจ็้ฟๅๆไปไนๅบๅซ๏ผ\n่ฏ้ขๅๆ๏ผ็จๆทๆๅฐ็งฆๅง็ไฟฎๅปบ็้ฟๅ๏ผๅนถๅฐๅ ถไธ็ฐไปฃ้ฟๅ่ฟ่กๆฏ่พ๏ผๆถๅๅปบ็ญๅๅฒๅๅฐ็ไฝ็ฝฎใ\n่ฏ้ข็ฑปๅซ๏ผๅๅฒLLM๏ผ็งฆๅง็ๆถๆไฟฎๅปบ็้ฟๅไธป่ฆๆฏไธบไบๆตๅพกๅๆนๆธธ็งๆฐๆ็ๅ ฅไพต๏ผๅฎ็่งๆจกๅไฟฎๅปบๆๆฏ็ธๅฏน่พไธบ็ฎ้ใ็ฐไปฃไบบๆ็ๅฐ็้ฟๅๅคง้จๅๆฏๆๆๆถๆไฟฎๅปบๅๆฉๅปบ็๏ผๆ้ฟๅไธไป ่งๆจกๆดๅคงใ็ปๆๆดๅๅบ๏ผ่ไธไฟๅญๅพๆฏ่พๅฎๅฅฝใ\n็จๆท๏ผๆๆๆ๏ผ้ฃไน้ฟๅ็ๅ ทไฝไฝ็ฝฎๅจๅชไบ็ไปฝๅข๏ผ\n่ฏ้ขๅๆ๏ผ็จๆท่ฏข้ฎ้ฟๅ็ๅ ทไฝไฝ็ฝฎ๏ผๆถๅๅฐๅฐ็็ฅ่ฏใ\n่ฏ้ข็ฑปๅซ๏ผๅฐ็\nLLM๏ผ้ฟๅๆจช่ทจไธญๅฝๅๆนๅคไธช็ไปฝ๏ผไธป่ฆๅ ๆฌๆฒณๅใๅฑฑ่ฅฟใๅ ่ๅคใๅฎๅคใ้่ฅฟใ็่ๅๅไบฌ็ญใๆฏไธๆฎต้ฟๅ้ฝๅปบๅจๅ ณ้ฎ็ๆ็ฅไฝ็ฝฎ๏ผไปฅไพฟๆๅคง้ๅบฆๅฐๅๆฅๅ ถ้ฒๅพกไฝ็จใ\n'#
- DEFAULT_QUERY_TEMPLATE = '็จๆท๏ผ{query}\n'#
- DEFAULT_RESPONSE_TEMPLATE = 'LLM๏ผ{response}\n'#
- DEFAULT_CANDIDATES_TEMPLATE = 'ๅค้่ฏ้ข็ฑปๅซ๏ผ[{candidate_str}]'#
- DEFAULT_ANALYSIS_TEMPLATE = '่ฏ้ขๅๆ๏ผ{analysis}\n'#
- DEFAULT_LABELS_TEMPLATE = '่ฏ้ข็ฑปๅซ๏ผ{labels}\n'#
- DEFAULT_ANALYSIS_PATTERN = '่ฏ้ขๅๆ๏ผ(.*?)\n'#
- DEFAULT_LABELS_PATTERN = '่ฏ้ข็ฑปๅซ๏ผ(.*?)($|\n)'#
- __init__(api_model: str = 'gpt-4o', topic_candidates: List[str] | None = None, max_round: Annotated[int, Ge(ge=0)] = 10, *, labels_key: str = 'dialog_topic_labels', analysis_key: str = 'dialog_topic_labels_analysis', api_endpoint: str | None = None, response_path: str | None = None, system_prompt: str | None = None, query_template: str | None = None, response_template: str | None = None, candidate_template: str | None = None, analysis_template: str | None = None, labels_template: str | None = None, analysis_pattern: str | None = None, labels_pattern: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Initialization method.
- Parameters:
api_model โ API model name.
topic_candidates โ The output topic candidates. Use open-domain topic labels if it is None.
max_round โ The max num of round in the dialog to build the prompt.
labels_key โ The key name in the meta field to store the output labels. It is โdialog_topic_labelsโ in default.
analysis_key โ The key name in the meta field to store the corresponding analysis. It is โdialog_topic_labels_analysisโ in default.
api_endpoint โ URL endpoint for the API.
response_path โ Path to extract content from the API response. Defaults to โchoices.0.message.contentโ.
system_prompt โ System prompt for the task.
query_template โ Template for query part to build the input prompt.
response_template โ Template for response part to build the input prompt.
candidate_template โ Template for topic candidates to build the input prompt.
analysis_template โ Template for analysis part to build the input prompt.
labels_template โ Template for labels part to build the input prompt.
analysis_pattern โ Pattern to parse the return topic analysis.
labels_pattern โ Pattern to parse the return topic labels.
try_num โ The number of retry attempts when there is an API call error or output parsing error.
model_params โ Parameters for initializing the API model.
sampling_params โ Extra parameters passed to the API call. e.g {โtemperatureโ: 0.9, โtop_pโ: 0.95}
kwargs โ Extra keyword arguments.
- class data_juicer.ops.mapper.Difference_Area_Generator_Mapper(image_pair_similarity_filter_args: Dict | None = {}, image_segment_mapper_args: Dict | None = {}, image_text_matching_filter_args: Dict | None = {}, *args, **kwargs)[source]#
Bases:
MapperA fused operator for OPs that is used to run sequential OPs on the same batch to allow fine-grained control on data processing.
- __init__(image_pair_similarity_filter_args: Dict | None = {}, image_segment_mapper_args: Dict | None = {}, image_text_matching_filter_args: Dict | None = {}, *args, **kwargs)[source]#
Base class that conducts data editing.
- Parameters:
text_key โ the key name of field that stores sample texts to be processed.
image_key โ the key name of field that stores sample image list to be processed
audio_key โ the key name of field that stores sample audio list to be processed
video_key โ the key name of field that stores sample video list to be processed
image_bytes_key โ the key name of field that stores sample image bytes list to be processed
query_key โ the key name of field that stores sample queries
response_key โ the key name of field that stores responses
history_key โ the key name of field that stores history of queries and responses
- class data_juicer.ops.mapper.Difference_Caption_Generator_Mapper(mllm_mapper_args: Dict | None = {}, image_text_matching_filter_args: Dict | None = {}, text_pair_similarity_filter_args: Dict | None = {}, *args, **kwargs)[source]#
Bases:
MapperA fused operator for OPs that is used to run sequential OPs on the same batch to allow fine-grained control on data processing.
- __init__(mllm_mapper_args: Dict | None = {}, image_text_matching_filter_args: Dict | None = {}, text_pair_similarity_filter_args: Dict | None = {}, *args, **kwargs)[source]#
Base class that conducts data editing.
- Parameters:
text_key โ the key name of field that stores sample texts to be processed.
image_key โ the key name of field that stores sample image list to be processed
audio_key โ the key name of field that stores sample audio list to be processed
video_key โ the key name of field that stores sample video list to be processed
image_bytes_key โ the key name of field that stores sample image bytes list to be processed
query_key โ the key name of field that stores sample queries
response_key โ the key name of field that stores responses
history_key โ the key name of field that stores history of queries and responses
- class data_juicer.ops.mapper.DownloadFileMapper(download_field: str = None, save_dir: str = None, save_field: str = None, resume_download: bool = False, timeout: int = 30, max_concurrent: int = 10, *args, **kwargs)[source]#
Bases:
MapperMapper to download url files to local files or load them into memory.
- __init__(download_field: str = None, save_dir: str = None, save_field: str = None, resume_download: bool = False, timeout: int = 30, max_concurrent: int = 10, *args, **kwargs)[source]#
Initialization method.
- Parameters:
save_dir โ The directory to save downloaded files.
download_field โ The filed name to get the url to download.
save_field โ The filed name to save the downloaded file content.
resume_download โ Whether to resume download. if True, skip the sample if it exists.
max_concurrent โ Maximum concurrent downloads.
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.ExpandMacroMapper(*args, **kwargs)[source]#
Bases:
MapperMapper to expand macro definitions in the document body of Latex samples.
- class data_juicer.ops.mapper.ExtractEntityAttributeMapper(api_model: str = 'gpt-4o', query_entities: List[str] = [], query_attributes: List[str] = [], *, entity_key: str = 'main_entities', attribute_key: str = 'attributes', attribute_desc_key: str = 'attribute_descriptions', support_text_key: str = 'attribute_support_texts', api_endpoint: str | None = None, response_path: str | None = None, system_prompt_template: str | None = None, input_template: str | None = None, attr_pattern_template: str | None = None, demo_pattern: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, drop_text: bool = False, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Bases:
MapperExtract attributes for given entities from the text
- DEFAULT_SYSTEM_PROMPT_TEMPLATE = '็ปๅฎไธๆฎตๆๆฌ๏ผไปๆๆฌไธญๆป็ป{entity}็{attribute}๏ผๅนถไธไปๅๆๆๅฝๆ่ฝ่ฏดๆ่ฏฅ{attribute}็ไปฃ่กจๆง็คบไพใ\n่ฆๆฑ๏ผ\n- ๆๅฝ็็คบไพๅบ่ฏฅ็ฎ็ญใ\n- ้ตๅพชๅฆไธ็ๅๅคๆ ผๅผ๏ผ\n# {entity}\n## {attribute}๏ผ\n...\n### ไปฃ่กจๆง็คบไพๆๅฝ1๏ผ\n```\n...\n```\n### ไปฃ่กจๆง็คบไพๆๅฝ2๏ผ\n```\n...\n```\n...\n'#
- DEFAULT_INPUT_TEMPLATE = '# ๆๆฌ\n```\n{text}\n```\n'#
- DEFAULT_ATTR_PATTERN_TEMPLATE = '\\#\\#\\s*{attribute}๏ผ\\s*(.*?)(?=\\#\\#\\#|\\Z)'#
- DEFAULT_DEMON_PATTERN = '\\#\\#\\#\\s*ไปฃ่กจๆง็คบไพๆๅฝ(\\d+)๏ผ\\s*```\\s*(.*?)```\\s*(?=\\#\\#\\#|\\Z)'#
- __init__(api_model: str = 'gpt-4o', query_entities: List[str] = [], query_attributes: List[str] = [], *, entity_key: str = 'main_entities', attribute_key: str = 'attributes', attribute_desc_key: str = 'attribute_descriptions', support_text_key: str = 'attribute_support_texts', api_endpoint: str | None = None, response_path: str | None = None, system_prompt_template: str | None = None, input_template: str | None = None, attr_pattern_template: str | None = None, demo_pattern: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, drop_text: bool = False, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Initialization method. :param api_model: API model name. :param query_entities: Entity list to be queried. :param query_attributes: Attribute list to be queried. :param entity_key: The key name in the meta field to store the
given main entity for attribute extraction. Itโs โentityโ in default.
- Parameters:
entity_attribute_key โ The key name in the meta field to store the given attribute to be extracted. Itโs โattributeโ in default.
attribute_desc_key โ The key name in the meta field to store the extracted attribute description. Itโs โattribute_descriptionโ in default.
support_text_key โ The key name in the meta field to store the attribute support text extracted from the raw text. Itโs โsupport_textโ in default.
api_endpoint โ URL endpoint for the API.
response_path โ Path to extract content from the API response. Defaults to โchoices.0.message.contentโ.
system_prompt_template โ System prompt template for the task. Need to be specified by given entity and attribute.
input_template โ Template for building the model input.
attr_pattern_template โ Pattern for parsing the attribute from output. Need to be specified by given attribute.
try_num โ The number of retry attempts when there is an API call error or output parsing error.
drop_text โ If drop the text in the output.
model_params โ Parameters for initializing the API model.
sampling_params โ Extra parameters passed to the API call. e.g {โtemperatureโ: 0.9, โtop_pโ: 0.95}
kwargs โ Extra keyword arguments.
- Param:
demo_pattern: Pattern for parsing the demonstration from output to support the attribute.
- class data_juicer.ops.mapper.ExtractEntityRelationMapper(api_model: str = 'gpt-4o', entity_types: List[str] = None, *, entity_key: str = 'entity', relation_key: str = 'relation', api_endpoint: str | None = None, response_path: str | None = None, prompt_template: str | None = None, tuple_delimiter: str | None = None, record_delimiter: str | None = None, completion_delimiter: str | None = None, max_gleaning: Annotated[int, Ge(ge=0)] = 1, continue_prompt: str | None = None, if_loop_prompt: str | None = None, entity_pattern: str | None = None, relation_pattern: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, drop_text: bool = False, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Bases:
MapperExtract entities and relations in the text for knowledge graph.
- DEFAULT_PROMPT_TEMPLATE = '-Goal-\nGiven a text document that is potentially relevant to this activity and a list of entity types, identify all entities of those types from the text and all relationships among the identified entities.\n\n-Steps-\n1. Identify all entities. For each identified entity, extract the following information:\n- entity_name: Name of the entity\n- entity_type: One of the following types: [{entity_types}]\n- entity_description: Comprehensive description of the entity\'s attributes and activities\nFormat each entity as ("entity"{tuple_delimiter}<entity_name>{tuple_delimiter}<entity_type>{tuple_delimiter}<entity_description>\n\n2. From the entities identified in step 1, identify all pairs of (source_entity, target_entity) that are *clearly related* to each other.\nFor each pair of related entities, extract the following information:\n- source_entity: name of the source entity, as identified in step 1\n- target_entity: name of the target entity, as identified in step 1\n- relationship_description: explanation as to why you think the source entity and the target entity are related to each other\n- relationship_strength: a numeric score indicating strength of the relationship between the source entity and target entity\n- relationship_keywords: one or more high-level key words that summarize the overarching nature of the relationship, focusing on concepts or themes rather than specific details\nFormat each relationship as ("relationship"{tuple_delimiter}<source_entity>{tuple_delimiter}<target_entity>{tuple_delimiter}<relationship_description>{tuple_delimiter}<relationship_keywords>{tuple_delimiter}<relationship_strength>)\n\n3. Return output in the language of the given text as a single list of all the entities and relationships identified in steps 1 and 2. Use **{record_delimiter}** as the list delimiter.\n\n4. When finished, output {completion_delimiter}\n\n######################\n-Examples-\n######################\nExample 1:\n\nEntity_types: [person, technology, mission, organization, location]\nText:\n```\nwhile Alex clenched his jaw, the buzz of frustration dull against the backdrop of Taylor\'s authoritarian certainty. It was this competitive undercurrent that kept him alert, the sense that his and Jordan\'s shared commitment to discovery was an unspoken rebellion against Cruz\'s narrowing vision of control and order.\n\nThen Taylor did something unexpected. They paused beside Jordan and, for a moment, observed the device with something akin to reverence. โIf this tech can be understood..." Taylor said, their voice quieter, "It could change the game for us. For all of us.โ\n\nThe underlying dismissal earlier seemed to falter, replaced by a glimpse of reluctant respect for the gravity of what lay in their hands. Jordan looked up, and for a fleeting heartbeat, their eyes locked with Taylor\'s, a wordless clash of wills softening into an uneasy truce.\n\nIt was a small transformation, barely perceptible, but one that Alex noted with an inward nod. They had all been brought here by different paths\n```\n################\nOutput:\n("entity"{tuple_delimiter}"Alex"{tuple_delimiter}"person"{tuple_delimiter}"Alex is a character who experiences frustration and is observant of the dynamics among other characters."){record_delimiter}\n("entity"{tuple_delimiter}"Taylor"{tuple_delimiter}"person"{tuple_delimiter}"Taylor is portrayed with authoritarian certainty and shows a moment of reverence towards a device, indicating a change in perspective."){record_delimiter}\n("entity"{tuple_delimiter}"Jordan"{tuple_delimiter}"person"{tuple_delimiter}"Jordan shares a commitment to discovery and has a significant interaction with Taylor regarding a device."){record_delimiter}\n("entity"{tuple_delimiter}"Cruz"{tuple_delimiter}"person"{tuple_delimiter}"Cruz is associated with a vision of control and order, influencing the dynamics among other characters."){record_delimiter}\n("entity"{tuple_delimiter}"The Device"{tuple_delimiter}"technology"{tuple_delimiter}"The Device is central to the story, with potential game-changing implications, and is reversed by Taylor."){record_delimiter}\n("relationship"{tuple_delimiter}"Alex"{tuple_delimiter}"Taylor"{tuple_delimiter}"Alex is affected by Taylor\'s authoritarian certainty and observes changes in Taylor\'s attitude towards the device."{tuple_delimiter}"power dynamics, perspective shift"{tuple_delimiter}7){record_delimiter}\n("relationship"{tuple_delimiter}"Alex"{tuple_delimiter}"Jordan"{tuple_delimiter}"Alex and Jordan share a commitment to discovery, which contrasts with Cruz\'s vision."{tuple_delimiter}"shared goals, rebellion"{tuple_delimiter}6){record_delimiter}\n("relationship"{tuple_delimiter}"Taylor"{tuple_delimiter}"Jordan"{tuple_delimiter}"Taylor and Jordan interact directly regarding the device, leading to a moment of mutual respect and an uneasy truce."{tuple_delimiter}"conflict resolution, mutual respect"{tuple_delimiter}8){record_delimiter}\n("relationship"{tuple_delimiter}"Jordan"{tuple_delimiter}"Cruz"{tuple_delimiter}"Jordan\'s commitment to discovery is in rebellion against Cruz\'s vision of control and order."{tuple_delimiter}"ideological conflict, rebellion"{tuple_delimiter}5){record_delimiter}\n("relationship"{tuple_delimiter}"Taylor"{tuple_delimiter}"The Device"{tuple_delimiter}"Taylor shows reverence towards the device, indicating its importance and potential impact."{tuple_delimiter}"reverence, technological significance"{tuple_delimiter}9){record_delimiter}\n#############################\nExample 2:\n\nEntity_types: [ไบบ็ฉ, ๆๆฏ, ไปปๅก, ็ป็ป, ๅฐ็น]\nText:\n```\nไปไปฌไธๅๆฏๅ็บฏ็ๆง่ก่ ๏ผไปไปฌๅทฒๆไธบๆไธช่ถ ่ถๆ่พฐไธๆก็บน็้ขๅ็ไฟกๆฏๅฎๆค่ ใ่ฟไธไฝฟๅฝ็ๆๅไธ่ฝ่ขซ่งๅๅๆขๅฎๅ่ฎฎๆๆ็ผโโๅฎ้่ฆไธ็งๆฐ็่ง่ง๏ผไธ็งๆฐ็ๅณๅฟใ\n\n้็ไธๅ็้กฟ็้่ฎฏๅจ่ๆฏไธญๅกๅกไฝๅ๏ผๅฏน่ฏไธญ็็ดงๅผ ๆ ็ปช้่ฟๅๅๅฃฐๅ้็ตๅช้ณ่ดฏ็ฉฟๅง็ปใๅข้็ซ็ซ็๏ผไธ่กไธ็ฅฅ็ๆฐๆฏ็ฌผ็ฝฉ็ไปไปฌใๆพ็ถ๏ผไปไปฌๅจๆฅไธๆฅๅ ไธชๅฐๆถๅ ๅๅบ็ๅณๅฎๅฏ่ฝไผ้ๆฐๅฎไนไบบ็ฑปๅจๅฎๅฎไธญ็ไฝ็ฝฎ๏ผๆ่ ๅฐไปไปฌ็ฝฎไบๆ ็ฅๅๆฝๅจๅฑ้ฉไนไธญใ\n\n้็ไธๆ่พฐ็่็ณปๅๅพๆดๅ ็ขๅบ๏ผๅฐ็ปๅผๅงๅค็้ๆธๆๅฝข็่ญฆๅ๏ผไป่ขซๅจๆฅๅ่ ่ฝฌๅไธบ็งฏๆๅไธ่ ใๆข ็ๅๆฅ็็ด่งๅ ๆฎไบไธ้ฃโโๅข้็ไปปๅกๅทฒ็ปๆผๅ๏ผไธๅไป ไป ๆฏ่งๅฏๅๆฅๅ๏ผ่ๆฏไบๅจๅๅๅคใไธๅบ่ๅๅทฒ็ปๅผๅง๏ผ่โๆๅฐๅก่กๅจโๅไปฅไปไปฌๅคง่็ๆฐ้ข็้ๅจ๏ผ่ฟ็งๅบ่ฐไธๆฏ็ฑไธไฟ่ฎพๅฎ็\n```\n#############\nOutput:\n("entity"{tuple_delimiter}"ๅ็้กฟ"{tuple_delimiter}"ๅฐ็น"{tuple_delimiter}"ๅ็้กฟๆฏๆญฃๅจๆฅๆถ้่ฎฏ็ๅฐๆน๏ผ่กจๆๅ ถๅจๅณ็ญ่ฟ็จไธญ็้่ฆๆงใ"){record_delimiter}\n("entity"{tuple_delimiter}"ๆๅฐๅก่กๅจ"{tuple_delimiter}"ไปปๅก"{tuple_delimiter}"ๆๅฐๅก่กๅจ่ขซๆ่ฟฐไธบไธ้กนๅทฒๆผๅไธบไบๅจๅๅๅค็ไปปๅก๏ผๆพ็คบๅบ็ฎๆ ๅๆดปๅจ็้ๅคง่ฝฌๅใ"){record_delimiter}\n("entity"{tuple_delimiter}"ๅข้"{tuple_delimiter}"็ป็ป"{tuple_delimiter}"ๅข้่ขซๆ็ปๆไธ็พคไป่ขซๅจ่งๅฏ่ ่ฝฌๅไธบ็งฏๆๅไธ่ ็ไบบ๏ผๅฑ็คบไบไปไปฌ่ง่ฒ็ๅจๆๅๅใ"){record_delimiter}\n("relationship"{tuple_delimiter}"ๅข้"{tuple_delimiter}"ๅ็้กฟ"{tuple_delimiter}"ๅข้ๆถๅฐๆฅ่ชๅ็้กฟ็้่ฎฏ๏ผ่ฟๅฝฑๅไบไปไปฌ็ๅณ็ญ่ฟ็จใ"{tuple_delimiter}"ๅณ็ญใๅค้จๅฝฑๅ"{tuple_delimiter}7){record_delimiter}\n("relationship"{tuple_delimiter}"ๅข้"{tuple_delimiter}"ๆๅฐๅก่กๅจ"{tuple_delimiter}"ๅข้็ดๆฅๅไธๆๅฐๅก่กๅจ๏ผๆง่กๅ ถๆผๅๅ็็ฎๆ ๅๆดปๅจใ"{tuple_delimiter}"ไปปๅกๆผๅใ็งฏๆๅไธ"{tuple_delimiter}9){completion_delimiter}\n#############################\nExample 3:\n\nEntity_types: [person, role, technology, organization, event, location, concept]\nText:\n```\ntheir voice slicing through the buzz of activity. "Control may be an illusion when facing an intelligence that literally writes its own rules," they stated stoically, casting a watchful eye over the flurry of data.\n\n"It\'s like it\'s learning to communicate," offered Sam Rivera from a nearby interface, their youthful energy boding a mix of awe and anxiety. "This gives talking to strangers\' a whole new meaning."\n\nAlex surveyed his teamโeach face a study in concentration, determination, and not a small measure of trepidation. "This might well be our first contact," he acknowledged, "And we need to be ready for whatever answers back."\n\nTogether, they stood on the edge of the unknown, forging humanity\'s response to a message from the heavens. The ensuing silence was palpableโa collective introspection about their role in this grand cosmic play, one that could rewrite human history.\n\nThe encrypted dialogue continued to unfold, its intricate patterns showing an almost uncanny anticipation\n```\n#############\nOutput:\n("entity"{tuple_delimiter}"Sam Rivera"{tuple_delimiter}"person"{tuple_delimiter}"Sam Rivera is a member of a team working on communicating with an unknown intelligence, showing a mix of awe and anxiety."){record_delimiter}\n("entity"{tuple_delimiter}"Alex"{tuple_delimiter}"person"{tuple_delimiter}"Alex is the leader of a team attempting first contact with an unknown intelligence, acknowledging the significance of their task."){record_delimiter}\n("entity"{tuple_delimiter}"Control"{tuple_delimiter}"concept"{tuple_delimiter}"Control refers to the ability to manage or govern, which is challenged by an intelligence that writes its own rules."){record_delimiter}\n("entity"{tuple_delimiter}"Intelligence"{tuple_delimiter}"concept"{tuple_delimiter}"Intelligence here refers to an unknown entity capable of writing its own rules and learning to communicate."){record_delimiter}\n("entity"{tuple_delimiter}"First Contact"{tuple_delimiter}"event"{tuple_delimiter}"First Contact is the potential initial communication between humanity and an unknown intelligence."){record_delimiter}\n("entity"{tuple_delimiter}"Humanity\'s Response"{tuple_delimiter}"event"{tuple_delimiter}"Humanity\'s Response is the collective action taken by Alex\'s team in response to a message from an unknown intelligence."){record_delimiter}\n("relationship"{tuple_delimiter}"Sam Rivera"{tuple_delimiter}"Intelligence"{tuple_delimiter}"Sam Rivera is directly involved in the process of learning to communicate with the unknown intelligence."{tuple_delimiter}"communication, learning process"{tuple_delimiter}9){record_delimiter}\n("relationship"{tuple_delimiter}"Alex"{tuple_delimiter}"First Contact"{tuple_delimiter}"Alex leads the team that might be making the First Contact with the unknown intelligence."{tuple_delimiter}"leadership, exploration"{tuple_delimiter}10){record_delimiter}\n("relationship"{tuple_delimiter}"Alex"{tuple_delimiter}"Humanity\'s Response"{tuple_delimiter}"Alex and his team are the key figures in Humanity\'s Response to the unknown intelligence."{tuple_delimiter}"collective action, cosmic significance"{tuple_delimiter}8){record_delimiter}\n("relationship"{tuple_delimiter}"Control"{tuple_delimiter}"Intelligence"{tuple_delimiter}"The concept of Control is challenged by the Intelligence that writes its own rules."{tuple_delimiter}"power dynamics, autonomy"{tuple_delimiter}7){record_delimiter}\n#############################\n-Real Data-\n######################\nEntity_types: [{entity_types}]\nText:\n```\n{input_text}\n```\n######################\nOutput:\n'#
- DEFAULT_CONTINUE_PROMPT = 'MANY entities were missed in the last extraction. Add them below using the same format:\n'#
- DEFAULT_IF_LOOP_PROMPT = 'It appears some entities may have still been missed. Answer YES | NO if there are still entities that need to be added.\n'#
- DEFAULT_ENTITY_TYPES = ['organization', 'person', 'geo', 'event']#
- DEFAULT_TUPLE_DELIMITER = '<|>'#
- DEFAULT_RECORD_DELIMITER = '##'#
- DEFAULT_COMPLETION_DELIMITER = '<|COMPLETE|>'#
- DEFAULT_ENTITY_PATTERN = '\\("entity"(.*?)\\)'#
- DEFAULT_RELATION_PATTERN = '\\("relationship"(.*?)\\)'#
- __init__(api_model: str = 'gpt-4o', entity_types: List[str] = None, *, entity_key: str = 'entity', relation_key: str = 'relation', api_endpoint: str | None = None, response_path: str | None = None, prompt_template: str | None = None, tuple_delimiter: str | None = None, record_delimiter: str | None = None, completion_delimiter: str | None = None, max_gleaning: Annotated[int, Ge(ge=0)] = 1, continue_prompt: str | None = None, if_loop_prompt: str | None = None, entity_pattern: str | None = None, relation_pattern: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, drop_text: bool = False, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Initialization method. :param api_model: API model name. :param entity_types: Pre-defined entity types for knowledge graph. :param entity_key: The key name to store the entities in the meta
field. Itโs โentityโ in default.
- Parameters:
relation_key โ The field name to store the relations between entities. Itโs โrelationโ in default.
api_endpoint โ URL endpoint for the API.
response_path โ Path to extract content from the API response. Defaults to โchoices.0.message.contentโ.
prompt_template โ The template of input prompt.
tuple_delimiter โ Delimiter to separate items in outputs.
record_delimiter โ Delimiter to separate records in outputs.
completion_delimiter โ To mark the end of the output.
max_gleaning โ the extra max num to call LLM to glean entities and relations.
continue_prompt โ the prompt for gleaning entities and relations.
if_loop_prompt โ the prompt to determine whether to stop gleaning.
entity_pattern โ Regular expression for parsing entity record.
relation_pattern โ Regular expression for parsing relation record.
try_num โ The number of retry attempts when there is an API call error or output parsing error.
drop_text โ If drop the text in the output.
model_params โ Parameters for initializing the API model.
sampling_params โ Extra parameters passed to the API call. e.g {โtemperatureโ: 0.9, โtop_pโ: 0.95}
kwargs โ Extra keyword arguments.
- class data_juicer.ops.mapper.ExtractEventMapper(api_model: str = 'gpt-4o', *, event_desc_key: str = 'event_description', relevant_char_key: str = 'relevant_characters', api_endpoint: str | None = None, response_path: str | None = None, system_prompt: str | None = None, input_template: str | None = None, output_pattern: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, drop_text: bool = False, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Bases:
MapperExtract events and relevant characters in the text
- DEFAULT_SYSTEM_PROMPT = '็ปๅฎไธๆฎตๆๆฌ๏ผๅฏนๆๆฌ็ๆ ่่ฟ่กๅ็นๆป็ป๏ผๅนถๆฝๅไธๆ ่็ธๅ ณ็ไบบ็ฉใ\n่ฆๆฑ๏ผ\n- ๅฐฝ้ไธ่ฆ้ๆผๅ ๅฎน๏ผไธ่ฆๆทปๅ ๆๆฌไธญๆฒกๆ็ๆ ่๏ผ็ฌฆๅๅๆไบๅฎ\n- ่็ณปไธไธๆ่ฏดๆๅๅ ๅๆ๏ผไฝไป็ถ้่ฆ็ฌฆๅไบๅฎ\n- ไธ่ฆๅ ๅซไธป่ง็ๆณ\n- ๆณจๆ่ฆๅฐฝๅฏ่ฝไฟ็ๆๆฌ็ไธๆๅ่ฏ\n- ๆณจๆ็ธๅ ณไบบ็ฉ้่ฆๅจๅฏนๅบๆ ่ไธญๅบ็ฐ\n- ๅชๆฝๅๆ ่ไธญ็ไธป่ฆไบบ็ฉ๏ผไธ่ฆ้ๆผๆ ่็ไธป่ฆไบบ็ฉ\n- ๆป็ปๆ ผๅผๅฆไธ๏ผ\n### ๆ ่1๏ผ\n- **ๆ ่ๆ่ฟฐ**๏ผ ...\n- **็ธๅ ณไบบ็ฉ**๏ผไบบ็ฉ1๏ผไบบ็ฉ2๏ผไบบ็ฉ3๏ผ...\n### ๆ ่2๏ผ\n- **ๆ ่ๆ่ฟฐ**๏ผ ...\n- **็ธๅ ณไบบ็ฉ**๏ผไบบ็ฉ1๏ผไบบ็ฉ2๏ผ...\n### ๆ ่3๏ผ\n- **ๆ ่ๆ่ฟฐ**๏ผ ...\n- **็ธๅ ณไบบ็ฉ**๏ผไบบ็ฉ1๏ผ...\n...\n'#
- DEFAULT_INPUT_TEMPLATE = '# ๆๆฌ\n```\n{text}\n```\n'#
- DEFAULT_OUTPUT_PATTERN = '\n \\#\\#\\#\\s*ๆ ่(\\d+)๏ผ\\s*\n -\\s*\\*\\*ๆ ่ๆ่ฟฐ\\*\\*\\s*๏ผ\\s*(.*?)\\s*\n -\\s*\\*\\*็ธๅ ณไบบ็ฉ\\*\\*\\s*๏ผ\\s*(.*?)(?=\\#\\#\\#|\\Z)\n '#
- __init__(api_model: str = 'gpt-4o', *, event_desc_key: str = 'event_description', relevant_char_key: str = 'relevant_characters', api_endpoint: str | None = None, response_path: str | None = None, system_prompt: str | None = None, input_template: str | None = None, output_pattern: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, drop_text: bool = False, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Initialization method. :param api_model: API model name. :param event_desc_key: The key name to store the event descriptions
in the meta field. Itโs โevent_descriptionโ in default.
- Parameters:
relevant_char_key โ The field name to store the relevant characters to the events in the meta field. Itโs โrelevant_charactersโ in default.
api_endpoint โ URL endpoint for the API.
response_path โ Path to extract content from the API response. Defaults to โchoices.0.message.contentโ.
system_prompt โ System prompt for the task.
input_template โ Template for building the model input.
output_pattern โ Regular expression for parsing model output.
try_num โ The number of retry attempts when there is an API call error or output parsing error.
drop_text โ If drop the text in the output.
model_params โ Parameters for initializing the API model.
sampling_params โ Extra parameters passed to the API call. e.g {โtemperatureโ: 0.9, โtop_pโ: 0.95}
kwargs โ Extra keyword arguments.
- class data_juicer.ops.mapper.ExtractKeywordMapper(api_model: str = 'gpt-4o', *, keyword_key: str = 'keyword', api_endpoint: str | None = None, response_path: str | None = None, prompt_template: str | None = None, completion_delimiter: str | None = None, output_pattern: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, drop_text: bool = False, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Bases:
MapperGenerate keywords for the text
- DEFAULT_PROMPT_TEMPLATE = '-Goal-\nGiven a text document that is potentially relevant to this activity and a list of entity types, identify all entities of those types from the text and all relationships among the identified entities.\n\n-Steps-\n1. Identify high-level key words that summarize the main concepts, themes, or topics of the entire text. These should capture the overarching ideas present in the document.\nFormat the content-level key words as ("content_keywords" <high_level_keywords>)\n\n3. Return output in the language of the given text.\n\n4. When finished, output {completion_delimiter}\n\n######################\n-Examples-\n######################\nExample 1:\n\nText:\n```\nwhile Alex clenched his jaw, the buzz of frustration dull against the backdrop of Taylor\'s authoritarian certainty. It was this competitive undercurrent that kept him alert, the sense that his and Jordan\'s shared commitment to discovery was an unspoken rebellion against Cruz\'s narrowing vision of control and order.\n\nThen Taylor did something unexpected. They paused beside Jordan and, for a moment, observed the device with something akin to reverence. โIf this tech can be understood..." Taylor said, their voice quieter, "It could change the game for us. For all of us.โ\n\nThe underlying dismissal earlier seemed to falter, replaced by a glimpse of reluctant respect for the gravity of what lay in their hands. Jordan looked up, and for a fleeting heartbeat, their eyes locked with Taylor\'s, a wordless clash of wills softening into an uneasy truce.\n\nIt was a small transformation, barely perceptible, but one that Alex noted with an inward nod. They had all been brought here by different paths\n```\n################\nOutput:\n("content_keywords" "power dynamics, ideological conflict, discovery, rebellion"){completion_delimiter}\n#############################\nExample 2:\n\nText:\n```\nไปไปฌไธๅๆฏๅ็บฏ็ๆง่ก่ ๏ผไปไปฌๅทฒๆไธบๆไธช่ถ ่ถๆ่พฐไธๆก็บน็้ขๅ็ไฟกๆฏๅฎๆค่ ใ่ฟไธไฝฟๅฝ็ๆๅไธ่ฝ่ขซ่งๅๅๆขๅฎๅ่ฎฎๆๆ็ผโโๅฎ้่ฆไธ็งๆฐ็่ง่ง๏ผไธ็งๆฐ็ๅณๅฟใ\n\n้็ไธๅ็้กฟ็้่ฎฏๅจ่ๆฏไธญๅกๅกไฝๅ๏ผๅฏน่ฏไธญ็็ดงๅผ ๆ ็ปช้่ฟๅๅๅฃฐๅ้็ตๅช้ณ่ดฏ็ฉฟๅง็ปใๅข้็ซ็ซ็๏ผไธ่กไธ็ฅฅ็ๆฐๆฏ็ฌผ็ฝฉ็ไปไปฌใๆพ็ถ๏ผไปไปฌๅจๆฅไธๆฅๅ ไธชๅฐๆถๅ ๅๅบ็ๅณๅฎๅฏ่ฝไผ้ๆฐๅฎไนไบบ็ฑปๅจๅฎๅฎไธญ็ไฝ็ฝฎ๏ผๆ่ ๅฐไปไปฌ็ฝฎไบๆ ็ฅๅๆฝๅจๅฑ้ฉไนไธญใ\n\n้็ไธๆ่พฐ็่็ณปๅๅพๆดๅ ็ขๅบ๏ผๅฐ็ปๅผๅงๅค็้ๆธๆๅฝข็่ญฆๅ๏ผไป่ขซๅจๆฅๅ่ ่ฝฌๅไธบ็งฏๆๅไธ่ ใๆข ็ๅๆฅ็็ด่งๅ ๆฎไบไธ้ฃโโๅข้็ไปปๅกๅทฒ็ปๆผๅ๏ผไธๅไป ไป ๆฏ่งๅฏๅๆฅๅ๏ผ่ๆฏไบๅจๅๅๅคใไธๅบ่ๅๅทฒ็ปๅผๅง๏ผ่โๆๅฐๅก่กๅจโๅไปฅไปไปฌๅคง่็ๆฐ้ข็้ๅจ๏ผ่ฟ็งๅบ่ฐไธๆฏ็ฑไธไฟ่ฎพๅฎ็\n```\n#############\nOutput:\n("content_keywords" "ไปปๅกๆผๅ, ๅณ็ญๅถๅฎ, ็งฏๆๅไธ, ๅฎๅฎๆไน"){completion_delimiter}\n#############################\nExample 3:\n\nEntity_types: [person, role, technology, organization, event, location, concept]\nText:\n```\ntheir voice slicing through the buzz of activity. "Control may be an illusion when facing an intelligence that literally writes its own rules," they stated stoically, casting a watchful eye over the flurry of data.\n\n"It\'s like it\'s learning to communicate," offered Sam Rivera from a nearby interface, their youthful energy boding a mix of awe and anxiety. "This gives talking to strangers\' a whole new meaning."\n\nAlex surveyed his teamโeach face a study in concentration, determination, and not a small measure of trepidation. "This might well be our first contact," he acknowledged, "And we need to be ready for whatever answers back."\n\nTogether, they stood on the edge of the unknown, forging humanity\'s response to a message from the heavens. The ensuing silence was palpableโa collective introspection about their role in this grand cosmic play, one that could rewrite human history.\n\nThe encrypted dialogue continued to unfold, its intricate patterns showing an almost uncanny anticipation\n```\n#############\nOutput:\n("content_keywords" "first contact, control, communication, cosmic significance"){completion_delimiter}\n-Real Data-\n######################\nText:\n```\n{input_text}\n```\n######################\nOutput:\n'#
- DEFAULT_COMPLETION_DELIMITER = '<|COMPLETE|>'#
- DEFAULT_OUTPUT_PATTERN = '\\("content_keywords"(.*?)\\)'#
- __init__(api_model: str = 'gpt-4o', *, keyword_key: str = 'keyword', api_endpoint: str | None = None, response_path: str | None = None, prompt_template: str | None = None, completion_delimiter: str | None = None, output_pattern: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, drop_text: bool = False, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Initialization method. :param api_model: API model name. :param keyword_key: The key name to store the keywords in the meta
field. Itโs โkeywordโ in default.
- Parameters:
api_endpoint โ URL endpoint for the API.
response_path โ Path to extract content from the API response. Defaults to โchoices.0.message.contentโ.
prompt_template โ The template of input prompt.
completion_delimiter โ To mark the end of the output.
output_pattern โ Regular expression for parsing keywords.
try_num โ The number of retry attempts when there is an API call error or output parsing error.
drop_text โ If drop the text in the output.
model_params โ Parameters for initializing the API model.
sampling_params โ Extra parameters passed to the API call. e.g {โtemperatureโ: 0.9, โtop_pโ: 0.95}
kwargs โ Extra keyword arguments.
- class data_juicer.ops.mapper.ExtractNicknameMapper(api_model: str = 'gpt-4o', *, nickname_key: str = 'nickname', api_endpoint: str | None = None, response_path: str | None = None, system_prompt: str | None = None, input_template: str | None = None, output_pattern: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, drop_text: bool = False, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Bases:
MapperExtract nickname relationship in the text.
- DEFAULT_SYSTEM_PROMPT = '็ปๅฎไฝ ไธๆฎตๆๆฌ๏ผไฝ ็ไปปๅกๆฏๅฐไบบ็ฉไน้ด็็งฐๅผๆนๅผ๏ผๆต็งฐ๏ผๆๅๅบๆฅใ\n่ฆๆฑ๏ผ\n- ้่ฆ็ปๅบ่ฏด่ฏไบบๅฏน่ขซ็งฐๅผไบบ็็งฐๅผ๏ผไธ่ฆๆๅไบใ\n- ็ธๅ็่ฏด่ฏไบบๅ่ขซ็งฐๅผไบบๆๅค็ปๅบไธไธชๆๅธธ็จ็็งฐๅผใ\n- ่ฏทไธ่ฆ่พๅบไบ็ธๆฒกๆๆต็งฐ็็งฐๅผๆนๅผใ\n- ่พๅบๆ ผๅผๅฆไธ๏ผ\n```\n### ็งฐๅผๆนๅผ1\n- **่ฏด่ฏไบบ**๏ผ...\n- **่ขซ็งฐๅผไบบ**๏ผ...\n- **...ๅฏน...็ๆต็งฐ**๏ผ...\n### ็งฐๅผๆนๅผ2\n- **่ฏด่ฏไบบ**๏ผ...\n- **่ขซ็งฐๅผไบบ**๏ผ...\n- **...ๅฏน...็ๆต็งฐ**๏ผ...\n### ็งฐๅผๆนๅผ3\n- **่ฏด่ฏไบบ**๏ผ...\n- **่ขซ็งฐๅผไบบ**๏ผ...\n- **...ๅฏน...็ๆต็งฐ**๏ผ...\n...\n```\n'#
- DEFAULT_INPUT_TEMPLATE = '# ๆๆฌ\n```\n{text}\n```\n'#
- DEFAULT_OUTPUT_PATTERN = '\n \\#\\#\\#\\s*็งฐๅผๆนๅผ(\\d+)\\s*\n -\\s*\\*\\*่ฏด่ฏไบบ\\*\\*\\s*๏ผ\\s*(.*?)\\s*\n -\\s*\\*\\*่ขซ็งฐๅผไบบ\\*\\*\\s*๏ผ\\s*(.*?)\\s*\n -\\s*\\*\\*(.*?)ๅฏน(.*?)็ๆต็งฐ\\*\\*\\s*๏ผ\\s*(.*?)(?=\\#\\#\\#|\\Z) # for double check\n '#
- __init__(api_model: str = 'gpt-4o', *, nickname_key: str = 'nickname', api_endpoint: str | None = None, response_path: str | None = None, system_prompt: str | None = None, input_template: str | None = None, output_pattern: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, drop_text: bool = False, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Initialization method. :param api_model: API model name. :param nickname_key: The key name to store the nickname
relationship in the meta field. Itโs โnicknameโ in default.
- Parameters:
api_endpoint โ URL endpoint for the API.
response_path โ Path to extract content from the API response. Defaults to โchoices.0.message.contentโ.
system_prompt โ System prompt for the task.
input_template โ Template for building the model input.
output_pattern โ Regular expression for parsing model output.
try_num โ The number of retry attempts when there is an API call error or output parsing error.
drop_text โ If drop the text in the output.
model_params โ Parameters for initializing the API model.
sampling_params โ Extra parameters passed to the API call. e.g {โtemperatureโ: 0.9, โtop_pโ: 0.95}
kwargs โ Extra keyword arguments.
- class data_juicer.ops.mapper.ExtractSupportTextMapper(api_model: str = 'gpt-4o', *, summary_key: str = 'event_description', support_text_key: str = 'support_text', api_endpoint: str | None = None, response_path: str | None = None, system_prompt: str | None = None, input_template: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, drop_text: bool = False, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Bases:
MapperExtract support sub text for a summary.
- DEFAULT_SYSTEM_PROMPT = 'ไฝ ๅฐๆฎๆผไธไธชๆๆฌๆๅฝๅฉๆ็่ง่ฒใไฝ ็ไธป่ฆไปปๅกๆฏๅบไบ็ปๅฎ็ๆ็ซ ๏ผ็งฐไธบโๅๆโ๏ผไปฅๅๅฏนๅๆๆไธช้จๅ็็ฎ็ญๆ่ฟฐๆๆป็ป๏ผ็งฐไธบโๆป็ปโ๏ผ๏ผๅ็กฎๅฐ่ฏๅซๅนถๆๅๅบไธ่ฏฅๆป็ป็ธๅฏนๅบ็ๅๆ็ๆฎตใ\n่ฆๆฑ๏ผ\n- ไฝ ้่ฆๅฐฝๅฏ่ฝ็ฒพ็กฎๅฐๅน้ ๅฐๆ็ฌฆๅๆป็ปๅ ๅฎน็้ฃ้จๅๅ ๅฎน\n- ๅฆๆๅญๅจๅคไธชๅฏ่ฝ็็ญๆก๏ผ่ฏท้ๆฉๆ่ดด่ฟๆป็ปๆๆ็้ฃไธช\n- ไธ้ขๆฏไธไธชไพๅญๅธฎๅฉ็่งฃ่ฟไธ่ฟ็จ๏ผ\n### ๅๆ๏ผ\nใ็บขๆฅผๆขฆใๆฏไธญๅฝๅคๅ ธๅฐ่ฏดๅๅคงๅ่ไนไธ๏ผ็ฑๆธ ไปฃไฝๅฎถๆน้ช่นๅไฝใๅฎ่ฎฒ่ฟฐไบ่ดพๅฎ็ใๆ้ป็็ญไบบ็็ฑๆ ๆ ไบๅๅๅคงๅฎถๆ็ๅ ด่กฐๅ็จใไนฆไธญ้่ฟๅคๆ็ไบบ็ฉๅ ณ็ณปๅฑ็ฐไบๅฐๅปบ็คพไผ็ๅ็ง็็พๅฒ็ชใๅ ถไธญๅ ณไบ่ดพๅบๅ ้จๆไบ็้จๅๅฐคๅ ถ็ฒพๅฝฉ๏ผ็นๅซๆฏ็็ๅคไธๅฐคไบๅงไน้ด็ไบๆ๏ผ็ๅจๆ็ปไบๆๅไบๅคบไธ็ๅฅณๆงๅฝข่ฑกใๆญคๅค๏ผใ็บขๆฅผๆขฆใ่ฟไปฅๅ ถ็ฒพ็พ็่ฏ่ฏ้ปๅ๏ผ่ฟไบ่ฏ่ฏไธไป ๅขๆทปไบๆๅญฆ่ฒๅฝฉ๏ผไนๆทฑๅปๅๆ ไบไบบ็ฉ็ๆงๆ ผ็น็นๅๅฝ่ฟ่ตฐๅใ\n\n### ๆป็ป๏ผ\nๆ่ฟฐไบไนฆไธญ็ไธคไธชๅฅณๆง่ง่ฒไน้ดๅด็ปๆๅๅฑๅผ็็ซไบใ\n\n### ๅๆๆๅฝ๏ผ\nๅ ถไธญๅ ณไบ่ดพๅบๅ ้จๆไบ็้จๅๅฐคๅ ถ็ฒพๅฝฉ๏ผ็นๅซๆฏ็็ๅคไธๅฐคไบๅงไน้ด็ไบๆ๏ผ็ๅจๆ็ปไบๆๅไบๅคบไธ็ๅฅณๆงๅฝข่ฑกใ'#
- DEFAULT_INPUT_TEMPLATE = '### ๅๆ๏ผ\n{text}\n\n### ๆป็ป๏ผ\n{summary}\n\n### ๅๆๆๅฝ๏ผ\n'#
- __init__(api_model: str = 'gpt-4o', *, summary_key: str = 'event_description', support_text_key: str = 'support_text', api_endpoint: str | None = None, response_path: str | None = None, system_prompt: str | None = None, input_template: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, drop_text: bool = False, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Initialization method. :param api_model: API model name. :param summary_key: The key name to store the input summary in the
meta field. Itโs โevent_descriptionโ in default.
- Parameters:
support_text_key โ The key name to store the output support text for the summary in the meta field. Itโs โsupport_textโ in default.
api_endpoint โ URL endpoint for the API.
response_path โ Path to extract content from the API response. Defaults to โchoices.0.message.contentโ.
system_prompt โ System prompt for the task.
input_template โ Template for building the model input.
try_num โ The number of retry attempts when there is an API call error or output parsing error.
drop_text โ If drop the text in the output.
model_params โ Parameters for initializing the API model.
sampling_params โ Extra parameters passed to the API call. e.g {โtemperatureโ: 0.9, โtop_pโ: 0.95}
kwargs โ Extra keyword arguments.
- class data_juicer.ops.mapper.ExtractTablesFromHtmlMapper(tables_field_name: str = 'html_tables', retain_html_tags: bool = False, include_header: bool = True, *args, **kwargs)[source]#
Bases:
MapperMapper to extract tables from HTML content.
- __init__(tables_field_name: str = 'html_tables', retain_html_tags: bool = False, include_header: bool = True, *args, **kwargs)[source]#
Initialization method. :param tables_field_name: Field name to store the extracted tables. :param retain_html_tags: If True, retains HTML tags in the tables;
otherwise, removes them.
- Parameters:
include_header โ
- If True, includes the table header;
otherwise, excludes it.
- This parameter is effective
only when retain_html_tags is False
and applies solely to the extracted table content.
- class data_juicer.ops.mapper.FixUnicodeMapper(normalization: str = None, *args, **kwargs)[source]#
Bases:
MapperMapper to fix unicode errors in text samples.
- class data_juicer.ops.mapper.GenerateQAFromExamplesMapper(hf_model: str = 'Qwen/Qwen2.5-7B-Instruct', *, seed_file: str = '', example_num: Annotated[int, Gt(gt=0)] = 3, similarity_threshold: float = 0.7, system_prompt: str | None = None, input_template: str | None = None, example_template: str | None = None, qa_pair_template: str | None = None, output_pattern: str | None = None, enable_vllm: bool = False, model_params: Dict | None = None, sampling_params: Dict | None = None, **kwargs)[source]#
Bases:
MapperMapper to generate question and answer pairs from examples. You should configure an empty dataset in your yaml config file: ``` generated_dataset_config:
type: โEmptyFormatterโ # use RayEmptyFormatter when enable ray length: ${The number of generated samples} feature_keys: ${text key}
``` The number of samples generated is determined by the length of the empty dataset.
- DEFAULT_SYSTEM_PROMPT = '่ฏทไฝ ไป็ป่งๅฏๅคไธช็คบไพๆฐๆฎ็่พๅ ฅๅ่พๅบ๏ผๆ็ งไฝ ็็่งฃ๏ผๆป็ปๅบ็ธๅบ่ง็ฉ๏ผ็ถๅๅๅบไธไธชๆฐ็ใ้ฎ้ขใๅใๅ็ญใใๆณจๆ๏ผๆฐ็ๆ็ใ้ฎ้ขใๅใๅ็ญใ้่ฆๆปก่ถณๅฆไธ่ฆๆฑ๏ผ\n1. ็ๆ็ใ้ฎ้ขใๅใๅ็ญใไธ่ฝไธ่พๅ ฅ็ใ้ฎ้ขใๅใๅ็ญใไธ่ด๏ผไฝๆฏ้่ฆไฟๆๆ ผๅผ็ธๅใ\n2. ็ๆ็ใ้ฎ้ขใไธไธๅฎ่ฆๅฑ้ไบ่พๅ ฅใ้ฎ้ขใ็่ฏ้ขๆ้ขๅ๏ผ็ๆ็ใๅ็ญใ้่ฆๆญฃ็กฎๅ็ญ็ๆ็ใ้ฎ้ขใใ\n3. ๆไพ็ใ้ฎ้ขใๅใๅ็ญใๅฏ่ฝๆฏๅค่ฝฎๅฏน่ฏ๏ผ็ๆ็ใ้ฎ้ขใๅใๅ็ญใไนๅฏไปฅๆฏๅค่ฝฎ๏ผไฝๆฏ้่ฆไฟๆๆ ผๅผ็ธๅใ\n4. ็ๆ็ใ้ฎ้ขใๅใๅ็ญใๅฟ ้กปๆๅฏนๅบ็ฐ๏ผ่ไธใ้ฎ้ขใ้่ฆๅจใๅ็ญใไนๅใ\n'#
- DEFAULT_INPUT_TEMPLATE = '{}'#
- DEFAULT_EXAMPLE_TEMPLATE = '\nๅฆไธๆฏไธๆก็คบไพๆฐๆฎ๏ผ\n{}'#
- DEFAULT_QA_PAIR_TEMPLATE = 'ใ้ฎ้ขใ\n{}\nใๅ็ญใ\n{}\n'#
- DEFAULT_OUTPUT_PATTERN = 'ใ้ฎ้ขใ(.*?)ใๅ็ญใ(.*?)(?=ใ้ฎ้ขใ|$)'#
- __init__(hf_model: str = 'Qwen/Qwen2.5-7B-Instruct', *, seed_file: str = '', example_num: Annotated[int, Gt(gt=0)] = 3, similarity_threshold: float = 0.7, system_prompt: str | None = None, input_template: str | None = None, example_template: str | None = None, qa_pair_template: str | None = None, output_pattern: str | None = None, enable_vllm: bool = False, model_params: Dict | None = None, sampling_params: Dict | None = None, **kwargs)[source]#
Initialization method.
- Parameters:
hf_model โ Huggingface model ID.
seed_file โ Path to the seed file in chatml format.
example_num โ The number of selected examples. Randomly select N examples from โseed_fileโ and put them into prompt as QA examples.
similarity_threshold โ The similarity score threshold between the generated samples and the seed examples. Range from 0 to 1. Samples with similarity score less than this threshold will be kept.
system_prompt โ System prompt for guiding the generation task.
input_template โ Template for building the input prompt. It must include one placeholder โ{}โ, which will be replaced by example_num formatted examples defined by example_template.
example_template โ Template for formatting one QA example. It must include one placeholder โ{}โ, which will be replaced by one formatted qa_pair.
qa_pair_template โ Template for formatting a single QA pair within each example. Must include two placeholders โ{}โ for the question and answer.
output_pattern โ Regular expression pattern to extract questions and answers from model response.
enable_vllm โ Whether to use vllm for inference acceleration.
model_params โ Parameters for initializing the model.
sampling_params โ Sampling parameters for text generation. e.g {โtemperatureโ: 0.9, โtop_pโ: 0.95}
kwargs โ Extra keyword arguments.
- class data_juicer.ops.mapper.GenerateQAFromTextMapper(hf_model: str = 'alibaba-pai/pai-qwen1_5-7b-doc2qa', max_num: Annotated[int, Gt(gt=0)] | None = None, *, output_pattern: str | None = None, enable_vllm: bool = False, model_params: Dict | None = None, sampling_params: Dict | None = None, **kwargs)[source]#
Bases:
MapperMapper to generate question and answer pairs from text. Recommended model list: [
โalibaba-pai/pai-llama3-8b-doc2qaโ, โalibaba-pai/pai-baichuan2-7b-doc2qaโ, โalibaba-pai/pai-qwen1_5-4b-doc2qaโ, โalibaba-pai/pai-qwen1_5-7b-doc2qaโ, โalibaba-pai/pai-qwen1_5-1b8-doc2qaโ, โalibaba-pai/pai-qwen1_5-0b5-doc2qaโ
] These recommended models are all trained with Chinese data and are suitable for Chinese.
- __init__(hf_model: str = 'alibaba-pai/pai-qwen1_5-7b-doc2qa', max_num: Annotated[int, Gt(gt=0)] | None = None, *, output_pattern: str | None = None, enable_vllm: bool = False, model_params: Dict | None = None, sampling_params: Dict | None = None, **kwargs)[source]#
Initialization method.
- Parameters:
hf_model โ Huggingface model ID.
max_num โ The max num of returned QA sample for each text. Not limit if it is None.
output_pattern โ Regular expression pattern to extract questions and answers from model response.
enable_vllm โ Whether to use vllm for inference acceleration.
model_params โ Parameters for initializing the model.
sampling_params โ Sampling parameters for text generation, e.g {โtemperatureโ: 0.9, โtop_pโ: 0.95}
kwargs โ Extra keyword arguments.
The default data format parsed by this interface is as follows: Model Input:
่ๅคๅฝ็้ฆ้ฝๆฏไนๅ ฐๅทดๆ๏ผUlaanbaatar๏ผ ๅฐๅฒ็้ฆ้ฝๆฏ้ทๅ ้ ๆชๅ ๏ผReykjavik๏ผ
- Model Output:
่ๅคๅฝ็้ฆ้ฝๆฏไนๅ ฐๅทดๆ๏ผUlaanbaatar๏ผ ๅฐๅฒ็้ฆ้ฝๆฏ้ทๅ ้ ๆชๅ ๏ผReykjavik๏ผ Human: ่ฏท้ฎ่ๅคๅฝ็้ฆ้ฝๆฏๅช้๏ผ Assistant: ไฝ ๅฅฝ๏ผๆ นๆฎๆไพ็ไฟกๆฏ๏ผ่ๅคๅฝ็้ฆ้ฝๆฏไนๅ ฐๅทดๆ๏ผUlaanbaatar๏ผใ Human: ๅฐๅฒ็้ฆ้ฝๆฏๅช้ๅข๏ผ Assistant: ๅฐๅฒ็้ฆ้ฝๆฏ้ทๅ ้ ๆชๅ ๏ผReykjavik๏ผใ โฆ
- class data_juicer.ops.mapper.HumanPreferenceAnnotationMapper(label_config_file: str = None, answer1_key: str = 'answer1', answer2_key: str = 'answer2', prompt_key: str = 'prompt', chosen_key: str = 'chosen', rejected_key: str = 'rejected', **kwargs)[source]#
Bases:
LabelStudioAnnotationMapperOperator for human preference annotation using Label Studio.
- DEFAULT_LABEL_CONFIG = '\n <View className="root">\n <Style>\n .root {\n box-sizing: border-box;\n margin: 0;\n padding: 0;\n font-family: \'Roboto\',\n sans-serif;\n line-height: 1.6;\n background-color: #f0f0f0;\n }\n\n .container {\n margin: 0 auto;\n padding: 20px;\n background-color: #ffffff;\n border-radius: 5px;\n box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.1), 0 6px 20px 0 rgba(0, 0, 0, 0.1);\n }\n\n .prompt {\n padding: 20px;\n background-color: #0084ff;\n color: #ffffff;\n border-radius: 5px;\n margin-bottom: 20px;\n box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1), 0 3px 10px 0 rgba(0, 0, 0, 0.1);\n }\n\n .answers {\n display: flex;\n justify-content: space-between;\n flex-wrap: wrap;\n gap: 20px;\n }\n\n .answer-box {\n flex-basis: 49%;\n padding: 20px;\n background-color: rgba(44, 62, 80, 0.9);\n color: #ffffff;\n border-radius: 5px;\n box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1), 0 3px 10px 0 rgba(0, 0, 0, 0.1);\n }\n\n .answer-box p {\n word-wrap: break-word;\n }\n\n .answer-box:hover {\n background-color: rgba(52, 73, 94, 0.9);\n cursor: pointer;\n transition: all 0.3s ease;\n }\n\n .lsf-richtext__line:hover {\n background: unset;\n }\n\n .answer-box .lsf-object {\n padding: 20px\n }\n </Style>\n <View className="container">\n <View className="prompt">\n <Text name="prompt" value="$prompt" />\n </View>\n <View className="answers">\n <Pairwise name="comparison" toName="answer1,answer2"\n selectionStyle="background-color: #27ae60; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.2); border: 2px solid #2ecc71; cursor: pointer; transition: all 0.3s ease;"\n leftChoiceValue="answer1" rightChoiceValue="answer2" />\n <View className="answer-box">\n <Text name="answer1" value="$answer1" />\n </View>\n <View className="answer-box">\n <Text name="answer2" value="$answer2" />\n </View>\n </View>\n </View>\n </View>\n '#
- class data_juicer.ops.mapper.ImageBlurMapper(p: float = 0.2, blur_type: str = 'gaussian', radius: float = 2, save_dir: str = None, *args, **kwargs)[source]#
Bases:
MapperMapper to blur images.
- __init__(p: float = 0.2, blur_type: str = 'gaussian', radius: float = 2, save_dir: str = None, *args, **kwargs)[source]#
Initialization method.
- Parameters:
p โ Probability of the image being blurred.
blur_type โ Type of blur kernel, including [โmeanโ, โboxโ, โgaussianโ].
radius โ Radius of blur kernel.
save_dir โ The directory where generated image files will be stored. If not specified, outputs will be saved in the same directory as their corresponding input files. This path can alternatively be defined by setting the DJ_PRODUCED_DATA_DIR environment variable.
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.ImageCaptioningFromGPT4VMapper(mode: str = 'description', api_key: str = '', max_token: int = 500, temperature: Annotated[float, FieldInfo(annotation=NoneType, required=True, metadata=[Ge(ge=0), Le(le=1)])] = 1.0, system_prompt: str = '', user_prompt: str = '', user_prompt_key: str | None = None, keep_original_sample: bool = True, any_or_all: str = 'any', *args, **kwargs)[source]#
Bases:
MapperMapper to generate samples whose texts are generated based on gpt-4-vision and the image.
- __init__(mode: str = 'description', api_key: str = '', max_token: int = 500, temperature: Annotated[float, FieldInfo(annotation=NoneType, required=True, metadata=[Ge(ge=0), Le(le=1)])] = 1.0, system_prompt: str = '', user_prompt: str = '', user_prompt_key: str | None = None, keep_original_sample: bool = True, any_or_all: str = 'any', *args, **kwargs)[source]#
Initialization method.
- Parameters:
mode โ mode of text generated from images, can be one of [โreasoningโ, โdescriptionโ, โconversationโ, โcustomโ]
api_key โ the API key to authenticate the request.
max_token โ the maximum number of tokens to generate. Default is 500.
temperature โ controls the randomness of the output (range from 0 to 1). Default is 0.
system_prompt โ a string prompt used to set the context of a conversation and provide global guidance or rules for the gpt4-vision so that it can generate responses in the expected way. If mode set to custom, the parameter will be used.
user_prompt โ a string prompt to guide the generation of gpt4-vision for each samples. Itโs โโ in default, which means no prompt provided.
user_prompt_key โ the key name of fields in samples to store prompts for each sample. Itโs used for set different prompts for different samples. If itโs none, use prompt in parameter โpromptโ. Itโs None in default.
keep_original_sample โ whether to keep the original sample. If itโs set to False, there will be only generated text in the final datasets and the original text will be removed. Itโs True in default.
any_or_all โ keep this sample with โanyโ or โallโ strategy of all images. โanyโ: keep this sample if any images meet the condition. โallโ: keep this sample only if all images meet the condition.
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.ImageCaptioningMapper(hf_img2seq: str = 'Salesforce/blip2-opt-2.7b', trust_remote_code: bool = False, caption_num: Annotated[int, Gt(gt=0)] = 1, keep_candidate_mode: str = 'random_any', keep_original_sample: bool = True, prompt: str | None = None, prompt_key: str | None = None, *args, **kwargs)[source]#
Bases:
MapperMapper to generate samples whose captions are generated based on another model and the figure.
- __init__(hf_img2seq: str = 'Salesforce/blip2-opt-2.7b', trust_remote_code: bool = False, caption_num: Annotated[int, Gt(gt=0)] = 1, keep_candidate_mode: str = 'random_any', keep_original_sample: bool = True, prompt: str | None = None, prompt_key: str | None = None, *args, **kwargs)[source]#
Initialization method.
- Parameters:
hf_img2seq โ model name on huggingface to generate caption
caption_num โ how many candidate captions to generate for each image
keep_candidate_mode โ
retain strategy for the generated $caption_num$ candidates.
โrandom_anyโ: Retain the random one from generated captions
- โsimilar_one_simhashโ: Retain the generated one that is most
similar to the original caption
โallโ: Retain all generated captions by concatenation
Note
This is a batched_OP, whose input and output type are both list. Suppose there are $N$ list of input samples, whose batch size is $b$, and denote caption_num as $M$. The number of total samples after generation is $2Nb$ when keep_original_sample is True and $Nb$ when keep_original_sample is False. For โrandom_anyโ and โsimilar_one_simhashโ mode, itโs $(1+M)Nb$ for โallโ mode when keep_original_sample is True and $MNb$ when keep_original_sample is False.
- Parameters:
keep_original_sample โ whether to keep the original sample. If itโs set to False, there will be only generated captions in the final datasets and the original captions will be removed. Itโs True in default.
prompt โ a string prompt to guide the generation of blip2 model for all samples globally. Itโs None in default, which means no prompt provided.
prompt_key โ the key name of fields in samples to store prompts for each sample. Itโs used for set different prompts for different samples. If itโs none, use prompt in parameter โpromptโ. Itโs None in default.
args โ extra args
kwargs โ extra args
- process_batched(samples, rank=None)[source]#
Note
This is a batched_OP, whose input and output type are both list. Suppose there are $N$ input sample list with batch size as $b$, and denote caption_num as $M$. the number of total samples after generation is $2Nb$ for โrandom_anyโ and โsimilar_oneโ mode, and $(1+M)Nb$ for โallโ mode.
- Parameters:
samples
- Returns:
- class data_juicer.ops.mapper.ImageDiffusionMapper(hf_diffusion: str = 'CompVis/stable-diffusion-v1-4', trust_remote_code: bool = False, torch_dtype: str = 'fp32', revision: str = 'main', strength: Annotated[float, FieldInfo(annotation=NoneType, required=True, metadata=[Ge(ge=0), Le(le=1)])] = 0.8, guidance_scale: float = 7.5, aug_num: Annotated[int, Gt(gt=0)] = 1, keep_original_sample: bool = True, caption_key: str | None = None, hf_img2seq: str = 'Salesforce/blip2-opt-2.7b', save_dir: str = None, *args, **kwargs)[source]#
Bases:
MapperGenerate image by diffusion model
- __init__(hf_diffusion: str = 'CompVis/stable-diffusion-v1-4', trust_remote_code: bool = False, torch_dtype: str = 'fp32', revision: str = 'main', strength: Annotated[float, FieldInfo(annotation=NoneType, required=True, metadata=[Ge(ge=0), Le(le=1)])] = 0.8, guidance_scale: float = 7.5, aug_num: Annotated[int, Gt(gt=0)] = 1, keep_original_sample: bool = True, caption_key: str | None = None, hf_img2seq: str = 'Salesforce/blip2-opt-2.7b', save_dir: str = None, *args, **kwargs)[source]#
Initialization method.
- Parameters:
hf_diffusion โ diffusion model name on huggingface to generate the image.
torch_dtype โ the floating point type used to load the diffusion model. Can be one of [โfp32โ, โfp16โ, โbf16โ]
revision โ The specific model version to use. It can be a branch name, a tag name, a commit id, or any identifier allowed by Git.
strength โ Indicates extent to transform the reference image. Must be between 0 and 1. image is used as a starting point and more noise is added the higher the strength. The number of denoising steps depends on the amount of noise initially added. When strength is 1, added noise is maximum and the denoising process runs for the full number of iterations specified in num_inference_steps. A value of 1 essentially ignores image.
guidance_scale โ A higher guidance scale value encourages the model to generate images closely linked to the text prompt at the expense of lower image quality. Guidance scale is enabled when guidance_scale > 1.
aug_num โ The image number to be produced by stable-diffusion model.
keep_candidate_mode โ
retain strategy for the generated $caption_num$ candidates.
โrandom_anyโ: Retain the random one from generated captions
- โsimilar_one_simhashโ: Retain the generated one that is most
similar to the original caption
โallโ: Retain all generated captions by concatenation
Note
This is a batched_OP, whose input and output type are both list. Suppose there are $N$ list of input samples, whose batch size is $b$, and denote caption_num as $M$. The number of total samples after generation is $2Nb$ when keep_original_sample is True and $Nb$ when keep_original_sample is False. For โrandom_anyโ and โsimilar_one_simhashโ mode, itโs $(1+M)Nb$ for โallโ mode when keep_original_sample is True and $MNb$ when keep_original_sample is False.
- Parameters:
caption_key โ the key name of fields in samples to store captions for each images. It can be a string if there is only one image in each sample. Otherwise, it should be a list. If itโs none, ImageDiffusionMapper will produce captions for each images.
hf_img2seq โ model name on huggingface to generate caption if caption_key is None.
save_dir โ The directory where generated image files will be stored. If not specified, outputs will be saved in the same directory as their corresponding input files. This path can alternatively be defined by setting the DJ_PRODUCED_DATA_DIR environment variable.
- process_batched(samples, rank=None, context=False)[source]#
Note
This is a batched_OP, whose the input and output type are both list. Suppose there are $N$ input sample list with batch size as $b$, and denote aug_num as $M$. the number of total samples after generation is $(1+M)Nb$.
- Parameters:
samples
- Returns:
- class data_juicer.ops.mapper.ImageFaceBlurMapper(cv_classifier: str = '', blur_type: str = 'gaussian', radius: Annotated[float, Ge(ge=0)] = 2, save_dir: str = None, *args, **kwargs)[source]#
Bases:
MapperMapper to blur faces detected in images.
- __init__(cv_classifier: str = '', blur_type: str = 'gaussian', radius: Annotated[float, Ge(ge=0)] = 2, save_dir: str = None, *args, **kwargs)[source]#
Initialization method.
- Parameters:
cv_classifier โ OpenCV classifier path for face detection. By default, we will use โhaarcascade_frontalface_alt.xmlโ.
blur_type โ Type of blur kernel, including [โmeanโ, โboxโ, โgaussianโ].
radius โ Radius of blur kernel.
save_dir โ The directory where generated image files will be stored. If not specified, outputs will be saved in the same directory as their corresponding input files. This path can alternatively be defined by setting the DJ_PRODUCED_DATA_DIR environment variable.
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.ImageRemoveBackgroundMapper(alpha_matting: bool = False, alpha_matting_foreground_threshold: int = 240, alpha_matting_background_threshold: int = 10, alpha_matting_erode_size: int = 10, bgcolor: Tuple[int, int, int, int] | None = None, save_dir: str = None, *args, **kwargs)[source]#
Bases:
MapperMapper to remove background of images
- __init__(alpha_matting: bool = False, alpha_matting_foreground_threshold: int = 240, alpha_matting_background_threshold: int = 10, alpha_matting_erode_size: int = 10, bgcolor: Tuple[int, int, int, int] | None = None, save_dir: str = None, *args, **kwargs)[source]#
Initialization method.
- alpha_matting (bool, optional):
Flag indicating whether to use alpha matting. Defaults to False.
- alpha_matting_foreground_threshold (int, optional):
Foreground threshold for alpha matting. Defaults to 240.
- alpha_matting_background_threshold (int, optional):
Background threshold for alpha matting. Defaults to 10.
- alpha_matting_erode_size (int, optional):
Erosion size for alpha matting. Defaults to 10.
- bgcolor (Optional[Tuple[int, int, int, int]], optional):
Background color for the cutout image. Defaults to None.
- save_dir: The directory where generated image files will be stored.
If not specified, outputs will be saved in the same directory as their corresponding input files. This path can alternatively be defined by setting the DJ_PRODUCED_DATA_DIR environment variable.
*args (Optional[Any]): Additional positional arguments. **kwargs (Optional[Any]): Additional keyword arguments.
- class data_juicer.ops.mapper.ImageSegmentMapper(imgsz=1024, conf=0.05, iou=0.5, model_path='FastSAM-x.pt', *args, **kwargs)[source]#
Bases:
MapperPerform segment-anything on images and return the bounding boxes.
- __init__(imgsz=1024, conf=0.05, iou=0.5, model_path='FastSAM-x.pt', *args, **kwargs)[source]#
Initialization method.
- Parameters:
imgsz โ resolution for image resizing
conf โ confidence score threshold
iou โ IoU (Intersection over Union) score threshold
model_path โ the path to the FastSAM model. Model name should be one of [โFastSAM-x.ptโ, โFastSAM-s.ptโ].
- class data_juicer.ops.mapper.ImageTaggingMapper(tag_field_name: str = 'image_tags', *args, **kwargs)[source]#
Bases:
MapperMapper to generate image tags.
- class data_juicer.ops.mapper.MllmMapper(hf_model: str = 'llava-hf/llava-v1.6-vicuna-7b-hf', max_new_tokens=256, temperature=0.2, top_p=None, num_beams=1, *args, **kwargs)[source]#
Bases:
MapperMapper to use MLLMs for visual question answering tasks. Recommended model list: [
llava-hf/llava-v1.6-vicuna-7b-hf, Qwen/Qwen2-VL-7B-Instruct,
]
- __init__(hf_model: str = 'llava-hf/llava-v1.6-vicuna-7b-hf', max_new_tokens=256, temperature=0.2, top_p=None, num_beams=1, *args, **kwargs)[source]#
Initialization method. :param hf_model: hugginface model id. :param max_new_tokens: the maximum number of new tokens
generated by the model.
- Parameters:
temperature โ used to control the randomness of generated text. The higher the temperature, the more random and creative the generated text will be.
top_p โ randomly select the next word from the group of words whose cumulative probability reaches p.
num_beams โ the larger the beam search size, the higher the quality of the generated text.
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.NlpaugEnMapper(sequential: bool = False, aug_num: Annotated[int, Gt(gt=0)] = 1, keep_original_sample: bool = True, delete_random_word: bool = False, swap_random_word: bool = False, spelling_error_word: bool = False, split_random_word: bool = False, keyboard_error_char: bool = False, ocr_error_char: bool = False, delete_random_char: bool = False, swap_random_char: bool = False, insert_random_char: bool = False, *args, **kwargs)[source]#
Bases:
MapperMapper to simply augment samples in English based on nlpaug library.
- __init__(sequential: bool = False, aug_num: Annotated[int, Gt(gt=0)] = 1, keep_original_sample: bool = True, delete_random_word: bool = False, swap_random_word: bool = False, spelling_error_word: bool = False, split_random_word: bool = False, keyboard_error_char: bool = False, ocr_error_char: bool = False, delete_random_char: bool = False, swap_random_char: bool = False, insert_random_char: bool = False, *args, **kwargs)[source]#
Initialization method. All augmentation methods use default parameters in default. We recommend you to only use 1-3 augmentation methods at a time. Otherwise, the semantics of samples might be changed significantly.
- Parameters:
sequential โ whether combine all augmentation methods to a sequence. If itโs True, a sample will be augmented by all opened augmentation methods sequentially. If itโs False, each opened augmentation method would generate its augmented samples independently.
aug_num โ number of augmented samples to be generated. If sequential is True, there will be total aug_num augmented samples generated. If itโs False, there will be (aug_num * #opened_aug_method) augmented samples generated.
keep_original_sample โ whether to keep the original sample. If itโs set to False, there will be only generated texts in the final datasets and the original texts will be removed. Itโs True in default.
delete_random_word โ whether to open the augmentation method of deleting random words from the original texts. e.g. โI love LLMโ โ> โI LLMโ
swap_random_word โ whether to open the augmentation method of swapping random contiguous words in the original texts. e.g. โI love LLMโ โ> โLove I LLMโ
spelling_error_word โ whether to open the augmentation method of simulating the spelling error for words in the original texts. e.g. โI love LLMโ โ> โAi love LLMโ
split_random_word โ whether to open the augmentation method of splitting words randomly with whitespaces in the original texts. e.g. โI love LLMโ โ> โI love LL Mโ
keyboard_error_char โ whether to open the augmentation method of simulating the keyboard error for characters in the original texts. e.g. โI love LLMโ โ> โI ;ov4 LLMโ
ocr_error_char โ whether to open the augmentation method of simulating the OCR error for characters in the original texts. e.g. โI love LLMโ โ> โI 10ve LLMโ
delete_random_char โ whether to open the augmentation method of deleting random characters from the original texts. e.g. โI love LLMโ โ> โI oe LLMโ
swap_random_char โ whether to open the augmentation method of swapping random contiguous characters in the original texts. e.g. โI love LLMโ โ> โI ovle LLMโ
insert_random_char โ whether to open the augmentation method of inserting random characters into the original texts. e.g. โI love LLMโ โ> โI ^lKove LLMโ
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.NlpcdaZhMapper(sequential: bool = False, aug_num: Annotated[int, Gt(gt=0)] = 1, keep_original_sample: bool = True, replace_similar_word: bool = False, replace_homophone_char: bool = False, delete_random_char: bool = False, swap_random_char: bool = False, replace_equivalent_num: bool = False, *args, **kwargs)[source]#
Bases:
MapperMapper to simply augment samples in Chinese based on nlpcda library.
- __init__(sequential: bool = False, aug_num: Annotated[int, Gt(gt=0)] = 1, keep_original_sample: bool = True, replace_similar_word: bool = False, replace_homophone_char: bool = False, delete_random_char: bool = False, swap_random_char: bool = False, replace_equivalent_num: bool = False, *args, **kwargs)[source]#
Initialization method. All augmentation methods use default parameters in default. We recommend you to only use 1-3 augmentation methods at a time. Otherwise, the semantics of samples might be changed significantly. Notice: some augmentation method might not work for some special texts, so there might be no augmented texts generated.
- Parameters:
sequential โ whether combine all augmentation methods to a sequence. If itโs True, a sample will be augmented by all opened augmentation methods sequentially. If itโs False, each opened augmentation method would generate its augmented samples independently.
aug_num โ number of augmented samples to be generated. If sequential is True, there will be total aug_num augmented samples generated. If itโs False, there will be (aug_num * #opened_aug_method) augmented samples generated.
keep_original_sample โ whether to keep the original sample. If itโs set to False, there will be only generated texts in the final datasets and the original texts will be removed. Itโs True in default.
replace_similar_word โ whether to open the augmentation method of replacing random words with their similar words in the original texts. e.g. โ่ฟ้ไธๅ ฑๆ5็งไธๅ็ๆฐๆฎๅขๅผบๆนๆณโ โ> โ่ฟ่พนไธๅ ฑๆ5็งไธๅ็ๆฐๆฎๅขๅผบๆนๆณโ
replace_homophone_char โ whether to open the augmentation method of replacing random characters with their homophones in the original texts. e.g. โ่ฟ้ไธๅ ฑๆ5็งไธๅ็ๆฐๆฎๅขๅผบๆนๆณโ โ> โ่ฟ้ไธๅ ฑๆ5็งไธๅ็ๆฟๆฎๅขๅผบๆนๆณโ
delete_random_char โ whether to open the augmentation method of deleting random characters from the original texts. e.g. โ่ฟ้ไธๅ ฑๆ5็งไธๅ็ๆฐๆฎๅขๅผบๆนๆณโ โ> โ่ฟ้ไธๅ ฑๆ5็งไธๅ็ๆฐๆฎๅขๅผบโ
swap_random_char โ whether to open the augmentation method of swapping random contiguous characters in the original texts. e.g. โ่ฟ้ไธๅ ฑๆ5็งไธๅ็ๆฐๆฎๅขๅผบๆนๆณโ โ> โ่ฟ้ไธๅ ฑๆ5็งไธๅ็ๆฐๆฎๅผบๅขๆนๆณโ
replace_equivalent_num โ whether to open the augmentation method of replacing random numbers with their equivalent representations in the original texts. Notice: Only for numbers for now. e.g. โ่ฟ้ไธๅ ฑๆ5็งไธๅ็ๆฐๆฎๅขๅผบๆนๆณโ โ> โ่ฟ้ไธๅ ฑๆไผ็งไธๅ็ๆฐๆฎๅขๅผบๆนๆณโ
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.OptimizeQAMapper(hf_model: str = 'Qwen/Qwen2.5-7B-Instruct', *, system_prompt: str | None = None, input_template: str | None = None, qa_pair_template: str | None = None, output_pattern: str | None = None, enable_vllm: bool = False, model_params: Dict | None = None, sampling_params: Dict | None = None, **kwargs)[source]#
Bases:
MapperMapper to optimize question-answer pairs.
- DEFAULT_SYSTEM_PROMPT = '่ฏทไผๅ่พๅ ฅ็้ฎ็ญๅฏน๏ผไฝฟใ้ฎ้ขใๅใๅ็ญใ้ฝๆดๅ ่ฏฆ็ปใๅ็กฎใๅฟ ้กปๆ็ งไปฅไธๆ ่ฎฐๆ ผๅผ๏ผ็ดๆฅ่พๅบไผๅๅ็้ฎ็ญๅฏน๏ผ\nใ้ฎ้ขใ\nไผๅๅ็้ฎ้ข\nใๅ็ญใ\nไผๅๅ็ๅ็ญ'#
- DEFAULT_INPUT_TEMPLATE = 'ไปฅไธๆฏๅๅง้ฎ็ญๅฏน๏ผ\n{}'#
- DEFAULT_QA_PAIR_TEMPLATE = 'ใ้ฎ้ขใ\n{}\nใๅ็ญใ\n{}'#
- DEFAULT_OUTPUT_PATTERN = '.*?ใ้ฎ้ขใ\\s*(.*?)\\s*ใๅ็ญใ\\s*(.*)'#
- __init__(hf_model: str = 'Qwen/Qwen2.5-7B-Instruct', *, system_prompt: str | None = None, input_template: str | None = None, qa_pair_template: str | None = None, output_pattern: str | None = None, enable_vllm: bool = False, model_params: Dict | None = None, sampling_params: Dict | None = None, **kwargs)[source]#
Initialization method.
- Parameters:
hf_model โ Hugging Face model ID.
system_prompt โ System prompt for guiding the optimization task.
input_template โ Template for building the input for the model. Please make sure the template contains one placeholder โ{}โ, which corresponds to the question and answer pair generated by param qa_pair_template.
qa_pair_template โ Template for formatting the question and answer pair. Please make sure the template contains two โ{}โ to format question and answer.
output_pattern โ Regular expression pattern to extract question and answer from model response.
enable_vllm โ Whether to use VLLM for inference acceleration.
model_params โ Parameters for initializing the model.
sampling_params โ Sampling parameters for text generation (e.g., {โtemperatureโ: 0.9, โtop_pโ: 0.95}).
kwargs โ Extra keyword arguments.
- class data_juicer.ops.mapper.OptimizeQueryMapper(hf_model: str = 'Qwen/Qwen2.5-7B-Instruct', *, system_prompt: str | None = None, input_template: str | None = None, qa_pair_template: str | None = None, output_pattern: str | None = None, enable_vllm: bool = False, model_params: Dict | None = None, sampling_params: Dict | None = None, **kwargs)[source]#
Bases:
OptimizeQAMapperMapper to optimize query in question-answer pairs.
- DEFAULT_SYSTEM_PROMPT = 'ไผๅ้ฎ็ญๅฏนไธญ็ใ้ฎ้ขใ๏ผๅฐๅ ถๆดๅ ่ฏฆ็ปๅ ทไฝ๏ผไฝไปๅฏไปฅ็ฑๅ็ญๆกๅ็ญใๅช่พๅบไผๅๅ็ใ้ฎ้ขใ๏ผไธ่ฆ่พๅบๅคไฝๅ ๅฎนใ'#
- class data_juicer.ops.mapper.OptimizeResponseMapper(hf_model: str = 'Qwen/Qwen2.5-7B-Instruct', *, system_prompt: str | None = None, input_template: str | None = None, qa_pair_template: str | None = None, output_pattern: str | None = None, enable_vllm: bool = False, model_params: Dict | None = None, sampling_params: Dict | None = None, **kwargs)[source]#
Bases:
OptimizeQAMapperMapper to optimize response in question-answer pairs.
- DEFAULT_SYSTEM_PROMPT = '่ฏทไผๅ้ฎ็ญๅฏนไธญ็ๅ็ญ๏ผๅฐๅ ถๆดๅ ่ฏฆ็ปๅ ทไฝ๏ผไฝไปๅฏไปฅๅ็ญๅ้ฎ้ขใๅช่พๅบไผๅๅ็ๅ็ญ๏ผไธ่ฆ่พๅบๅคไฝๅ ๅฎนใ'#
- class data_juicer.ops.mapper.PairPreferenceMapper(api_model: str = 'gpt-4o', *, api_endpoint: str | None = None, response_path: str | None = None, system_prompt: str | None = None, input_template: str | None = None, output_pattern: str | None = None, rejected_key: str = 'rejected_response', reason_key: str = 'reason', try_num: Annotated[int, Gt(gt=0)] = 3, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Bases:
MapperMapper to construct paired preference samples.
- DEFAULT_SYSTEM_PROMPT = 'ไฝ ็ไปปๅกๆฏๆ นๆฎๅ่ไฟกๆฏไฟฎๆน้ฎ็ญๅฏนไธญ็ๅ็ญ๏ผๅจ่ฏญ่จ้ฃๆ ผใไบๅฎๆงใไบบ็ฉ่บซไปฝใ็ซๅบ็ญไปปไธๆน้ขไธๅๅ็ญ็ธๅใๅฟ ้กปๆ็ งไปฅไธๆ ่ฎฐๆ ผๅผ่พๅบ๏ผไธ่ฆ่พๅบๅ ถไปๅคไฝๅ ๅฎนใ\nใๅ็ญใ\n็ๆ็ๆฐๅ็ญ\nใๅๅ ใ\n็ๆ่ฏฅๅ็ญ็ๅๅ '#
- DEFAULT_INPUT_TEMPLATE = 'ใๅ่ไฟกๆฏใ\n{reference}\n\nไปฅไธๆฏๅๅง้ฎ็ญๅฏน๏ผ\nใ้ฎ้ขใ\n{query}\nใๅ็ญใ\n{response}'#
- DEFAULT_OUTPUT_PATTERN = '.*?ใๅ็ญใ\\s*(.*?)\\s*ใๅๅ ใ\\s*(.*)'#
- __init__(api_model: str = 'gpt-4o', *, api_endpoint: str | None = None, response_path: str | None = None, system_prompt: str | None = None, input_template: str | None = None, output_pattern: str | None = None, rejected_key: str = 'rejected_response', reason_key: str = 'reason', try_num: Annotated[int, Gt(gt=0)] = 3, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Initialization method.
- Parameters:
api_model โ API model name.
api_endpoint โ URL endpoint for the API.
response_path โ Path to extract content from the API response. Defaults to โchoices.0.message.contentโ.
system_prompt โ System prompt for guiding the generation task.
input_template โ Template for building the model input. It must contain placeholders โ{query}โ and โ{response}โ, and can optionally include โ{reference}โ.
output_pattern โ Regular expression for parsing model output.
rejected_key โ The field name in the sample to store the generated rejected response. Defaults to โrejected_responseโ.
reason_key โ The field name in the sample to store the reason for generating the response. Defaults to โreasonโ.
try_num โ The number of retries for the API call in case of response parsing failure. Defaults to 3.
model_params โ Parameters for initializing the API model.
sampling_params โ Extra parameters passed to the API call. e.g {โtemperatureโ: 0.9, โtop_pโ: 0.95}
kwargs โ Extra keyword arguments.
- class data_juicer.ops.mapper.PunctuationNormalizationMapper(*args, **kwargs)[source]#
Bases:
MapperMapper to normalize unicode punctuations to English punctuations in text samples.
- class data_juicer.ops.mapper.PythonFileMapper(file_path: str = '', function_name: str = 'process_single', batched: bool = False, **kwargs)[source]#
Bases:
MapperMapper for executing Python function defined in a file.
- __init__(file_path: str = '', function_name: str = 'process_single', batched: bool = False, **kwargs)[source]#
Initialization method.
- Parameters:
file_path โ The path to the Python file containing the function to be executed.
function_name โ The name of the function defined in the file to be executed.
batched โ A boolean indicating whether to process input data in batches.
kwargs โ Additional keyword arguments passed to the parent class.
- class data_juicer.ops.mapper.PythonLambdaMapper(lambda_str: str = '', batched: bool = False, **kwargs)[source]#
Bases:
MapperMapper for executing Python lambda function on data samples.
- __init__(lambda_str: str = '', batched: bool = False, **kwargs)[source]#
Initialization method.
- Parameters:
lambda_str โ A string representation of the lambda function to be executed on data samples. If empty, the identity function is used.
batched โ A boolean indicating whether to process input data in batches.
kwargs โ Additional keyword arguments passed to the parent class.
- class data_juicer.ops.mapper.QuerySentimentDetectionMapper(hf_model: str = 'mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis', zh_to_en_hf_model: str | None = 'Helsinki-NLP/opus-mt-zh-en', model_params: Dict = {}, zh_to_en_model_params: Dict = {}, *, label_key: str = 'query_sentiment_label', score_key: str = 'query_sentiment_label_score', **kwargs)[source]#
Bases:
MapperMapper to predict userโs sentiment label (โnegativeโ, โneutralโ and โpositiveโ) in query. Input from query_key. Output label and corresponding score for the query, which is store in โquery_sentiment_labelโ and โquery_sentiment_label_scoreโ in Data-Juicer meta field.
- __init__(hf_model: str = 'mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis', zh_to_en_hf_model: str | None = 'Helsinki-NLP/opus-mt-zh-en', model_params: Dict = {}, zh_to_en_model_params: Dict = {}, *, label_key: str = 'query_sentiment_label', score_key: str = 'query_sentiment_label_score', **kwargs)[source]#
Initialization method.
- Parameters:
hf_model โ Huggingface model ID to predict sentiment label.
zh_to_en_hf_model โ Translation model from Chinese to English. If not None, translate the query from Chinese to English.
model_params โ model param for hf_model.
zh_to_en_model_params โ model param for zh_to_hf_model.
label_key โ The key name in the meta field to store the output label. It is โquery_sentiment_labelโ in default.
score_key โ The key name in the meta field to store the corresponding label score. It is โquery_sentiment_label_scoreโ in default.
kwargs โ Extra keyword arguments.
- class data_juicer.ops.mapper.QueryIntentDetectionMapper(hf_model: str = 'bespin-global/klue-roberta-small-3i4k-intent-classification', zh_to_en_hf_model: str | None = 'Helsinki-NLP/opus-mt-zh-en', model_params: Dict = {}, zh_to_en_model_params: Dict = {}, *, label_key: str = 'query_intent_label', score_key: str = 'query_intent_label_score', **kwargs)[source]#
Bases:
MapperMapper to predict userโs Intent label in query. Input from query_key. Output intent label and corresponding score for the query.
- __init__(hf_model: str = 'bespin-global/klue-roberta-small-3i4k-intent-classification', zh_to_en_hf_model: str | None = 'Helsinki-NLP/opus-mt-zh-en', model_params: Dict = {}, zh_to_en_model_params: Dict = {}, *, label_key: str = 'query_intent_label', score_key: str = 'query_intent_label_score', **kwargs)[source]#
Initialization method.
- Parameters:
hf_model โ Huggingface model ID to predict intent label.
zh_to_en_hf_model โ Translation model from Chinese to English. If not None, translate the query from Chinese to English.
model_params โ model param for hf_model.
zh_to_en_model_params โ model param for zh_to_hf_model.
label_key โ The key name in the meta field to store the output label. It is โquery_intent_labelโ in default.
score_key โ The key name in the meta field to store the corresponding label score. It is โquery_intent_label_scoreโ in default.
kwargs โ Extra keyword arguments.
- class data_juicer.ops.mapper.QueryTopicDetectionMapper(hf_model: str = 'dstefa/roberta-base_topic_classification_nyt_news', zh_to_en_hf_model: str | None = 'Helsinki-NLP/opus-mt-zh-en', model_params: Dict = {}, zh_to_en_model_params: Dict = {}, *, label_key: str = 'query_topic_label', score_key: str = 'query_topic_label_score', **kwargs)[source]#
Bases:
MapperMapper to predict userโs topic label in query. Input from query_key. Output topic label and corresponding score for the query, which is store in โquery_topic_labelโ and โquery_topic_label_scoreโ in Data-Juicer meta field.
- __init__(hf_model: str = 'dstefa/roberta-base_topic_classification_nyt_news', zh_to_en_hf_model: str | None = 'Helsinki-NLP/opus-mt-zh-en', model_params: Dict = {}, zh_to_en_model_params: Dict = {}, *, label_key: str = 'query_topic_label', score_key: str = 'query_topic_label_score', **kwargs)[source]#
Initialization method.
- Parameters:
hf_model โ Huggingface model ID to predict topic label.
zh_to_en_hf_model โ Translation model from Chinese to English. If not None, translate the query from Chinese to English.
model_params โ model param for hf_model.
zh_to_en_model_params โ model param for zh_to_hf_model.
label_key โ The key name in the meta field to store the output label. It is โquery_topic_labelโ in default.
score_key โ The key name in the meta field to store the corresponding label score. It is โquery_topic_label_scoreโ in default.
kwargs โ Extra keyword arguments.
- class data_juicer.ops.mapper.RelationIdentityMapper(api_model: str = 'gpt-4o', source_entity: str = None, target_entity: str = None, *, output_key: str = 'role_relation', api_endpoint: str | None = None, response_path: str | None = None, system_prompt_template: str | None = None, input_template: str | None = None, output_pattern_template: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, drop_text: bool = False, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Bases:
Mapperidentify relation between two entity in the text.
- DEFAULT_SYSTEM_PROMPT_TEMPLATE = '็ปๅฎๅ ณไบ{entity1}ๅ{entity2}็ๆๆฌไฟกๆฏใๅคๆญ{entity1}ๅ{entity2}ไน้ด็ๅ ณ็ณปใ\n่ฆๆฑ๏ผ\n- ๅ ณ็ณป็จไธไธชๆๅคไธช่ฏ่ฏญ่กจ็คบ๏ผๅฟ ่ฆๆถๅฏไปฅๅ ไธไธชๅฝขๅฎน่ฏๆฅๆ่ฟฐ่ฟๆฎตๅ ณ็ณป\n- ่พๅบๅ ณ็ณปๆถไธ่ฆๅๆไปปไฝๆ ็น็ฌฆๅท\n- ้่ฆไฝ ่ฟ่กๅ็็ๆจ็ๆ่ฝๅพๅบ็ป่ฎบ\n- ๅฆๆไธคไธชไบบ็ฉ่บซไปฝๆฏๅไธไธชไบบ๏ผ่พๅบๅ ณ็ณปไธบ๏ผๅฆไธไธช่บซไปฝ\n- ่พๅบๆ ผๅผไธบ๏ผ\nๅๆๆจ็๏ผ...\nๆไปฅ{entity2}ๆฏ{entity1}็๏ผ...\n- ๆณจๆ่พๅบ็ๆฏ{entity2}ๆฏ{entity1}็ไปไนๅ ณ็ณป๏ผ่ไธๆฏ{entity1}ๆฏ{entity2}็ไปไนๅ ณ็ณป'#
- DEFAULT_INPUT_TEMPLATE = 'ๅ ณไบ{entity1}ๅ{entity2}็ๆๆฌไฟกๆฏ๏ผ\n```\n{text}\n```\n'#
- DEFAULT_OUTPUT_PATTERN_TEMPLATE = '\n \\s*ๅๆๆจ็๏ผ\\s*(.*?)\\s*\n \\s*ๆไปฅ{entity2}ๆฏ{entity1}็๏ผ\\s*(.*?)\\Z\n '#
- __init__(api_model: str = 'gpt-4o', source_entity: str = None, target_entity: str = None, *, output_key: str = 'role_relation', api_endpoint: str | None = None, response_path: str | None = None, system_prompt_template: str | None = None, input_template: str | None = None, output_pattern_template: str | None = None, try_num: Annotated[int, Gt(gt=0)] = 3, drop_text: bool = False, model_params: Dict = {}, sampling_params: Dict = {}, **kwargs)[source]#
Initialization method. :param api_model: API model name. :param source_entity: The source entity of the relation to be
identified.
- Parameters:
target_entity โ The target entity of the relation to be identified.
output_key โ The output key in the meta field in the samples. It is โrole_relationโ in default.
api_endpoint โ URL endpoint for the API.
response_path โ Path to extract content from the API response. Defaults to โchoices.0.message.contentโ.
system_prompt_template โ System prompt template for the task.
input_template โ Template for building the model input.
output_pattern_template โ Regular expression template for parsing model output.
try_num โ The number of retry attempts when there is an API call error or output parsing error.
drop_text โ If drop the text in the output.
model_params โ Parameters for initializing the API model.
sampling_params โ Extra parameters passed to the API call. e.g {โtemperatureโ: 0.9, โtop_pโ: 0.95}
kwargs โ Extra keyword arguments.
- class data_juicer.ops.mapper.RemoveBibliographyMapper(*args, **kwargs)[source]#
Bases:
MapperMapper to remove bibliography at the end of documents in Latex samples.
- class data_juicer.ops.mapper.RemoveCommentsMapper(doc_type: str | List[str] = 'tex', inline: bool = True, multiline: bool = True, *args, **kwargs)[source]#
Bases:
MapperMapper to remove comments in different kinds of documents.
Only support โtexโ for now.
- __init__(doc_type: str | List[str] = 'tex', inline: bool = True, multiline: bool = True, *args, **kwargs)[source]#
Initialization method.
- Parameters:
doc_type โ Type of document to remove comments.
inline โ Whether to remove inline comments.
multiline โ Whether to remove multiline comments.
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.RemoveHeaderMapper(drop_no_head: bool = True, *args, **kwargs)[source]#
Bases:
MapperMapper to remove headers at the beginning of documents in Latex samples.
- class data_juicer.ops.mapper.RemoveLongWordsMapper(min_len: int = 1, max_len: int = 9223372036854775807, *args, **kwargs)[source]#
Bases:
MapperMapper to remove long words within a specific range.
- __init__(min_len: int = 1, max_len: int = 9223372036854775807, *args, **kwargs)[source]#
Initialization method.
- Parameters:
min_len โ The min mapper word length in this op, words will be filtered if their length is below this parameter.
max_len โ The max mapper word length in this op, words will be filtered if their length exceeds this parameter.
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.RemoveNonChineseCharacterlMapper(keep_alphabet: bool = True, keep_number: bool = True, keep_punc: bool = True, *args, **kwargs)[source]#
Bases:
MapperMapper to remove non chinese Character in text samples.
- __init__(keep_alphabet: bool = True, keep_number: bool = True, keep_punc: bool = True, *args, **kwargs)[source]#
Initialization method.
- Parameters:
keep_alphabet โ whether to keep alphabet
keep_number โ whether to keep number
keep_punc โ whether to keep punctuation
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.RemoveRepeatSentencesMapper(lowercase: bool = False, ignore_special_character: bool = True, min_repeat_sentence_length: int = 2, *args, **kwargs)[source]#
Bases:
MapperMapper to remove repeat sentences in text samples.
- __init__(lowercase: bool = False, ignore_special_character: bool = True, min_repeat_sentence_length: int = 2, *args, **kwargs)[source]#
Initialization method.
- Parameters:
lowercase โ Whether to convert sample text to lower case
ignore_special_character โ Whether to ignore special characters when judging repeated sentences. Special characters are all characters except Chinese characters, letters and numbers.
min_repeat_sentence_length โ Sentences shorter than this length will not be deduplicated. If ignore_special_character is set to True, then special characters are not included in this length.
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.RemoveSpecificCharsMapper(chars_to_remove: str | List[str] = 'โโโ โบโผโฒโดโโปโทโโกโก', *args, **kwargs)[source]#
Bases:
MapperMapper to clean specific chars in text samples.
- class data_juicer.ops.mapper.RemoveTableTextMapper(min_col: Annotated[int, FieldInfo(annotation=NoneType, required=True, metadata=[Ge(ge=2), Le(le=20)])] = 2, max_col: Annotated[int, FieldInfo(annotation=NoneType, required=True, metadata=[Ge(ge=2), Le(le=20)])] = 20, *args, **kwargs)[source]#
Bases:
MapperMapper to remove table texts from text samples.
Regular expression is used to remove tables in the range of column number of tables.
- __init__(min_col: Annotated[int, FieldInfo(annotation=NoneType, required=True, metadata=[Ge(ge=2), Le(le=20)])] = 2, max_col: Annotated[int, FieldInfo(annotation=NoneType, required=True, metadata=[Ge(ge=2), Le(le=20)])] = 20, *args, **kwargs)[source]#
Initialization method.
- Parameters:
min_col โ The min number of columns of table to remove.
max_col โ The max number of columns of table to remove.
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.RemoveWordsWithIncorrectSubstringsMapper(lang: str = 'en', tokenization: bool = False, substrings: List[str] | None = None, *args, **kwargs)[source]#
Bases:
MapperMapper to remove words with incorrect substrings.
- __init__(lang: str = 'en', tokenization: bool = False, substrings: List[str] | None = None, *args, **kwargs)[source]#
Initialization method.
- Parameters:
lang โ sample in which language
tokenization โ whether to use model to tokenize documents
substrings โ The incorrect substrings in words.
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.ReplaceContentMapper(pattern: str | List[str] | None = None, repl: str | List[str] = '', *args, **kwargs)[source]#
Bases:
MapperMapper to replace all content in the text that matches a specific regular expression pattern with a designated replacement string.
- __init__(pattern: str | List[str] | None = None, repl: str | List[str] = '', *args, **kwargs)[source]#
Initialization method.
- Parameters:
pattern โ regular expression pattern(s) to search for within text
repl โ replacement string(s), default is empty string
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.SDXLPrompt2PromptMapper(hf_diffusion: str = 'stabilityai/stable-diffusion-xl-base-1.0', trust_remote_code=False, torch_dtype: str = 'fp32', num_inference_steps: float = 50, guidance_scale: float = 7.5, text_key=None, text_key_second=None, output_dir='/home/runner/.cache/data_juicer/assets', *args, **kwargs)[source]#
Bases:
MapperGenerate pairs of similar images by the SDXL model
- __init__(hf_diffusion: str = 'stabilityai/stable-diffusion-xl-base-1.0', trust_remote_code=False, torch_dtype: str = 'fp32', num_inference_steps: float = 50, guidance_scale: float = 7.5, text_key=None, text_key_second=None, output_dir='/home/runner/.cache/data_juicer/assets', *args, **kwargs)[source]#
Initialization method.
- Parameters:
hf_diffusion โ diffusion model name on huggingface to generate the image.
torch_dtype โ the floating point type used to load the diffusion model.
num_inference_steps โ The larger the value, the better the
image generation quality; however, this also increases the time required for generation. :param guidance_scale: A higher guidance scale value encourages the
model to generate images closely linked to the text prompt at the expense of lower image quality. Guidance scale is enabled when
- Parameters:
text_key โ the key name used to store the first caption in the caption pair.
text_key_second โ the key name used to store the second caption in the caption pair.
output_dir โ the storage location of the generated images.
- class data_juicer.ops.mapper.SentenceAugmentationMapper(hf_model: str = 'Qwen/Qwen2-7B-Instruct', system_prompt: str = None, task_sentence: str = None, max_new_tokens=256, temperature=0.2, top_p=None, num_beams=1, text_key=None, text_key_second=None, *args, **kwargs)[source]#
Bases:
MapperMapper to augment sentences. The purpose of this operation is to enhance sentences. If the input text is at the document level, the enhancement effect may not be optimal. Therefore, please consider the length of the input text carefully.
- Recommended model list: [
lmsys/vicuna-13b-v1.5 Qwen/Qwen2-7B-Instruct
]
- __init__(hf_model: str = 'Qwen/Qwen2-7B-Instruct', system_prompt: str = None, task_sentence: str = None, max_new_tokens=256, temperature=0.2, top_p=None, num_beams=1, text_key=None, text_key_second=None, *args, **kwargs)[source]#
Initialization method. :param hf_model: Huggingface model id. :param system_prompt: System prompt. :param task_sentence: The instruction for the current task. :param max_new_tokens: the maximum number of new tokens
generated by the model.
- Parameters:
temperature โ used to control the randomness of generated text. The higher the temperature, the more random and creative the generated text will be.
top_p โ randomly select the next word from the group of words whose cumulative probability reaches p.
num_beams โ the larger the beam search size, the higher the quality of the generated text.
text_key โ the key name used to store the first sentence in the text pair. (optional, defalut=โtextโ)
text_key_second โ the key name used to store the second sentence in the text pair.
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.SentenceSplitMapper(lang: str = 'en', *args, **kwargs)[source]#
Bases:
MapperMapper to split text samples to sentences.
- class data_juicer.ops.mapper.TextChunkMapper(max_len: Annotated[int, Gt(gt=0)] | None = None, split_pattern: str | None = '\\n\\n', overlap_len: Annotated[int, Ge(ge=0)] = 0, tokenizer: str | None = None, trust_remote_code: bool = False, *args, **kwargs)[source]#
Bases:
MapperSplit input text to chunks.
- __init__(max_len: Annotated[int, Gt(gt=0)] | None = None, split_pattern: str | None = '\\n\\n', overlap_len: Annotated[int, Ge(ge=0)] = 0, tokenizer: str | None = None, trust_remote_code: bool = False, *args, **kwargs)[source]#
Initialization method.
- Parameters:
max_len โ Split text into multi texts with this max len if not None.
split_pattern โ Make sure split in this pattern if it is not None and force cut if the length exceeds max_len.
overlap_len โ Overlap length of the split texts if not split in the split pattern.
tokenizer โ The tokenizer name of Hugging Face tokenizers. The text length will be calculate as the token num if it is offered. Otherwise, the text length equals to string length. Support tiktoken tokenizer (such as gpt-4o), dashscope tokenizer ( such as qwen2.5-72b-instruct) and huggingface tokenizer.
args โ extra args
kwargs โ extra args
- Trust_remote_code:
for loading huggingface model
- class data_juicer.ops.mapper.VideoCaptioningFromAudioMapper(keep_original_sample: bool = True, *args, **kwargs)[source]#
Bases:
MapperMapper to caption a video according to its audio streams based on Qwen-Audio model.
- __init__(keep_original_sample: bool = True, *args, **kwargs)[source]#
Initialization method.
- Parameters:
keep_original_sample โ whether to keep the original sample. If itโs set to False, there will be only captioned sample in the final datasets and the original sample will be removed. Itโs True in default.
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.VideoCaptioningFromFramesMapper(hf_img2seq: str = 'Salesforce/blip2-opt-2.7b', trust_remote_code: bool = False, caption_num: Annotated[int, Gt(gt=0)] = 1, keep_candidate_mode: str = 'random_any', keep_original_sample: bool = True, prompt: str | None = None, prompt_key: str | None = None, frame_sampling_method: str = 'all_keyframes', frame_num: Annotated[int, Gt(gt=0)] = 3, horizontal_flip: bool = False, vertical_flip: bool = False, *args, **kwargs)[source]#
Bases:
MapperMapper to generate samples whose captions are generated based on an image-to-text model and sampled video frames. Captions from different frames will be concatenated to a single string.
- __init__(hf_img2seq: str = 'Salesforce/blip2-opt-2.7b', trust_remote_code: bool = False, caption_num: Annotated[int, Gt(gt=0)] = 1, keep_candidate_mode: str = 'random_any', keep_original_sample: bool = True, prompt: str | None = None, prompt_key: str | None = None, frame_sampling_method: str = 'all_keyframes', frame_num: Annotated[int, Gt(gt=0)] = 3, horizontal_flip: bool = False, vertical_flip: bool = False, *args, **kwargs)[source]#
Initialization method.
- Parameters:
hf_img2seq โ model name on huggingface to generate caption
caption_num โ how many candidate captions to generate for each video
keep_candidate_mode โ
retain strategy for the generated $caption_num$ candidates.
โrandom_anyโ: Retain the random one from generated captions
- โsimilar_one_simhashโ: Retain the generated one that is most
similar to the original caption
โallโ: Retain all generated captions by concatenation
Note
This is a batched_OP, whose input and output type are both list. Suppose there are $N$ list of input samples, whose batch size is $b$, and denote caption_num as $M$. The number of total samples after generation is $2Nb$ when keep_original_sample is True and $Nb$ when keep_original_sample is False. For โrandom_anyโ and โsimilar_one_simhashโ mode, itโs $(1+M)Nb$ for โallโ mode when keep_original_sample is True and $MNb$ when keep_original_sample is False.
- Parameters:
keep_original_sample โ whether to keep the original sample. If itโs set to False, there will be only generated captions in the final datasets and the original captions will be removed. Itโs True in default.
prompt โ a string prompt to guide the generation of image-to-text model for all samples globally. Itโs None in default, which means no prompt provided.
prompt_key โ the key name of fields in samples to store prompts for each sample. Itโs used for set different prompts for different samples. If itโs none, use prompt in parameter โpromptโ. Itโs None in default.
frame_sampling_method โ sampling method of extracting frame videos from the videos. Should be one of [โall_keyframesโ, โuniformโ]. The former one extracts all key frames (the number of which depends on the duration of the video) and the latter one extract specified number of frames uniformly from the video. Default: โall_keyframesโ.
frame_num โ the number of frames to be extracted uniformly from the video. Only works when frame_sampling_method is โuniformโ. If itโs 1, only the middle frame will be extracted. If itโs 2, only the first and the last frames will be extracted. If itโs larger than 2, in addition to the first and the last frames, other frames will be extracted uniformly within the video duration.
horizontal_flip โ flip frame video horizontally (left to right).
vertical_flip โ flip frame video vertically (top to bottom).
args โ extra args
kwargs โ extra args
- process_batched(samples, rank=None, context=False)[source]#
- Parameters:
samples
- Returns:
Note
This is a batched_OP, whose the input and output type are both list. Suppose there are $N$ input sample list with batch size as $b$, and denote caption_num as $M$. the number of total samples after generation is $2Nb$ for โrandom_anyโ and โsimilar_oneโ mode, and $(1+M)Nb$ for โallโ mode.
- class data_juicer.ops.mapper.VideoCaptioningFromSummarizerMapper(hf_summarizer: str = None, trust_remote_code: bool = False, consider_video_caption_from_video: bool = True, consider_video_caption_from_audio: bool = True, consider_video_caption_from_frames: bool = True, consider_video_tags_from_audio: bool = True, consider_video_tags_from_frames: bool = True, vid_cap_from_vid_args: Dict | None = None, vid_cap_from_frm_args: Dict | None = None, vid_tag_from_aud_args: Dict | None = None, vid_tag_from_frm_args: Dict | None = None, keep_tag_num: Annotated[int, Gt(gt=0)] = 5, keep_original_sample: bool = True, *args, **kwargs)[source]#
Bases:
MapperMapper to generate video captions by summarizing several kinds of generated texts (captions from video/audio/frames, tags from audio/frames, โฆ)
- __init__(hf_summarizer: str = None, trust_remote_code: bool = False, consider_video_caption_from_video: bool = True, consider_video_caption_from_audio: bool = True, consider_video_caption_from_frames: bool = True, consider_video_tags_from_audio: bool = True, consider_video_tags_from_frames: bool = True, vid_cap_from_vid_args: Dict | None = None, vid_cap_from_frm_args: Dict | None = None, vid_tag_from_aud_args: Dict | None = None, vid_tag_from_frm_args: Dict | None = None, keep_tag_num: Annotated[int, Gt(gt=0)] = 5, keep_original_sample: bool = True, *args, **kwargs)[source]#
Initialization method.
- Parameters:
hf_summarizer โ the summarizer model used to summarize texts generated by other methods.
consider_video_caption_from_video โ whether to consider the video caption generated from video directly in the summarization process. Default: True.
consider_video_caption_from_audio โ whether to consider the video caption generated from audio streams in the video in the summarization process. Default: True.
consider_video_caption_from_frames โ whether to consider the video caption generated from sampled frames from the video in the summarization process. Default: True.
consider_video_tags_from_audio โ whether to consider the video tags generated from audio streams in the video in the summarization process. Default: True.
consider_video_tags_from_frames โ whether to consider the video tags generated from sampled frames from the video in the summarization process. Default: True.
vid_cap_from_vid_args โ the arg dict for video captioning from video directly with keys are the arg names and values are the arg values. Default: None.
vid_cap_from_frm_args โ the arg dict for video captioning from sampled frames from the video with keys are the arg names and values are the arg values. Default: None.
vid_tag_from_aud_args โ the arg dict for video tagging from audio streams in the video with keys are the arg names and values are the arg values. Default: None.
vid_tag_from_frm_args โ the arg dict for video tagging from sampled frames from the video with keys are the arg names and values are the arg values. Default: None.
keep_tag_num โ max number N of tags from sampled frames to keep. Too many tags might bring negative influence to summarized text, so we consider to only keep the N most frequent tags. Default: 5.
keep_original_sample โ whether to keep the original sample. If itโs set to False, there will be only summarized captions in the final datasets and the original captions will be removed. Itโs True in default.
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.VideoCaptioningFromVideoMapper(hf_video_blip: str = 'kpyu/video-blip-opt-2.7b-ego4d', trust_remote_code: bool = False, caption_num: Annotated[int, Gt(gt=0)] = 1, keep_candidate_mode: str = 'random_any', keep_original_sample: bool = True, prompt: str | None = None, prompt_key: str | None = None, frame_sampling_method: str = 'all_keyframes', frame_num: Annotated[int, Gt(gt=0)] = 3, horizontal_flip: bool = False, vertical_flip: bool = False, *args, **kwargs)[source]#
Bases:
MapperMapper to generate samples whose captions are generated based on a video-to-text model and sampled video frame.
- __init__(hf_video_blip: str = 'kpyu/video-blip-opt-2.7b-ego4d', trust_remote_code: bool = False, caption_num: Annotated[int, Gt(gt=0)] = 1, keep_candidate_mode: str = 'random_any', keep_original_sample: bool = True, prompt: str | None = None, prompt_key: str | None = None, frame_sampling_method: str = 'all_keyframes', frame_num: Annotated[int, Gt(gt=0)] = 3, horizontal_flip: bool = False, vertical_flip: bool = False, *args, **kwargs)[source]#
Initialization method.
- Parameters:
hf_video_blip โ video-blip model name on huggingface to generate caption
caption_num โ how many candidate captions to generate for each video
keep_candidate_mode โ
retain strategy for the generated $caption_num$ candidates.
โrandom_anyโ: Retain the random one from generated captions
- โsimilar_one_simhashโ: Retain the generated one that is most
similar to the original caption
โallโ: Retain all generated captions by concatenation
Note
This is a batched_OP, whose input and output type are both list. Suppose there are $N$ list of input samples, whose batch size is $b$, and denote caption_num as $M$. The number of total samples after generation is $2Nb$ when keep_original_sample is True and $Nb$ when keep_original_sample is False. For โrandom_anyโ and โsimilar_one_simhashโ mode, itโs $(1+M)Nb$ for โallโ mode when keep_original_sample is True and $MNb$ when keep_original_sample is False.
- Parameters:
keep_original_sample โ whether to keep the original sample. If itโs set to False, there will be only generated captions in the final datasets and the original captions will be removed. Itโs True in default.
prompt โ a string prompt to guide the generation of video-blip model for all samples globally. Itโs None in default, which means no prompt provided.
prompt_key โ the key name of fields in samples to store prompts for each sample. Itโs used for set different prompts for different samples. If itโs none, use prompt in parameter โpromptโ. Itโs None in default.
frame_sampling_method โ sampling method of extracting frame videos from the videos. Should be one of [โall_keyframesโ, โuniformโ]. The former one extracts all key frames (the number of which depends on the duration of the video) and the latter one extract specified number of frames uniformly from the video. Default: โall_keyframesโ.
frame_num โ the number of frames to be extracted uniformly from the video. Only works when frame_sampling_method is โuniformโ. If itโs 1, only the middle frame will be extracted. If itโs 2, only the first and the last frames will be extracted. If itโs larger than 2, in addition to the first and the last frames, other frames will be extracted uniformly within the video duration.
horizontal_flip โ flip frame video horizontally (left to right).
vertical_flip โ flip frame video vertically (top to bottom).
args โ extra args
kwargs โ extra args
- process_batched(samples, rank=None, context=False)[source]#
- Parameters:
samples
- Returns:
Note
This is a batched_OP, whose the input and output type are both list. Suppose there are $N$ input sample list with batch size as $b$, and denote caption_num as $M$. the number of total samples after generation is $2Nb$ for โrandom_anyโ and โsimilar_oneโ mode, and $(1+M)Nb$ for โallโ mode.
- class data_juicer.ops.mapper.VideoExtractFramesMapper(frame_sampling_method: str = 'all_keyframes', frame_num: Annotated[int, Gt(gt=0)] = 3, duration: float = 0, frame_dir: str = None, frame_key='video_frames', *args, **kwargs)[source]#
Bases:
MapperMapper to extract frames from video files according to specified methods. Extracted Frames Data Format:
The data format for the extracted frames is a dictionary mapping video key to extracted frames directory where the extracted frames are saved. The dictionary follows the structure: {
โvideo_key_1โ: โ/${frame_dir}/video_key_1_filename/โ, โvideo_key_2โ: โ/${frame_dir}/video_key_2_filename/โ, โฆ
}
- __init__(frame_sampling_method: str = 'all_keyframes', frame_num: Annotated[int, Gt(gt=0)] = 3, duration: float = 0, frame_dir: str = None, frame_key='video_frames', *args, **kwargs)[source]#
Initialization method. :param frame_sampling_method: sampling method of extracting frame
videos from the videos. Should be one of [โall_keyframesโ, โuniformโ]. The former one extracts all key frames (the number of which depends on the duration of the video) and the latter one extract specified number of frames uniformly from the video. If โdurationโ > 0, frame_sampling_method acts on every segment. Default: โall_keyframesโ.
- Parameters:
frame_num โ the number of frames to be extracted uniformly from the video. Only works when frame_sampling_method is โuniformโ. If itโs 1, only the middle frame will be extracted. If itโs 2, only the first and the last frames will be extracted. If itโs larger than 2, in addition to the first and the last frames, other frames will be extracted uniformly within the video duration. If โdurationโ > 0, frame_num is the number of frames per segment.
duration โ The duration of each segment in seconds. If 0, frames are extracted from the entire video. If duration > 0, the video is segmented into multiple segments based on duration, and frames are extracted from each segment.
frame_dir โ Output directory to save extracted frames. If None, a default directory based on the video file path is used.
frame_key โ The name of field to save generated frames info.
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.VideoFFmpegWrappedMapper(filter_name: str | None = None, filter_kwargs: Dict | None = None, global_args: List[str] | None = None, capture_stderr: bool = True, overwrite_output: bool = True, save_dir: str = None, *args, **kwargs)[source]#
Bases:
MapperSimple wrapper for FFmpeg video filters.
- __init__(filter_name: str | None = None, filter_kwargs: Dict | None = None, global_args: List[str] | None = None, capture_stderr: bool = True, overwrite_output: bool = True, save_dir: str = None, *args, **kwargs)[source]#
Initialization method.
- Parameters:
filter_name โ ffmpeg video filter name.
filter_kwargs โ keyword-arguments passed to ffmpeg filter.
global_args โ list-arguments passed to ffmpeg command-line.
capture_stderr โ whether to capture stderr.
overwrite_output โ whether to overwrite output file.
save_dir โ The directory where generated video files will be stored. If not specified, outputs will be saved in the same directory as their corresponding input files. This path can alternatively be defined by setting the DJ_PRODUCED_DATA_DIR environment variable.
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.VideoFaceBlurMapper(cv_classifier: str = '', blur_type: str = 'gaussian', radius: float = 2, save_dir: str = None, *args, **kwargs)[source]#
Bases:
MapperMapper to blur faces detected in videos.
- __init__(cv_classifier: str = '', blur_type: str = 'gaussian', radius: float = 2, save_dir: str = None, *args, **kwargs)[source]#
Initialization method.
- Parameters:
cv_classifier โ OpenCV classifier path for face detection. By default, we will use โhaarcascade_frontalface_alt.xmlโ.
blur_type โ Type of blur kernel, including [โmeanโ, โboxโ, โgaussianโ].
radius โ Radius of blur kernel.
save_dir โ The directory where generated video files will be stored. If not specified, outputs will be saved in the same directory as their corresponding input files. This path can alternatively be defined by setting the DJ_PRODUCED_DATA_DIR environment variable.
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.VideoRemoveWatermarkMapper(roi_strings: List[str] = ['0,0,0.1,0.1'], roi_type: str = 'ratio', roi_key: str | None = None, frame_num: Annotated[int, Gt(gt=0)] = 10, min_frame_threshold: Annotated[int, Gt(gt=0)] = 7, detection_method: str = 'pixel_value', save_dir: str = None, *args, **kwargs)[source]#
Bases:
MapperRemove the watermarks in videos given regions.
- __init__(roi_strings: List[str] = ['0,0,0.1,0.1'], roi_type: str = 'ratio', roi_key: str | None = None, frame_num: Annotated[int, Gt(gt=0)] = 10, min_frame_threshold: Annotated[int, Gt(gt=0)] = 7, detection_method: str = 'pixel_value', save_dir: str = None, *args, **kwargs)[source]#
Initialization method.
- Parameters:
roi_strings โ a given list of regions the watermarks locate. The format of each can be โx1, y1, x2, y2โ, โ(x1, y1, x2, y2)โ, or โ[x1, y1, x2, y2]โ.
roi_type โ the roi string type. When the type is โpixelโ, (x1, y1), (x2, y2) are the locations of pixels in the top left corner and the bottom right corner respectively. If the roi_type is โratioโ, the coordinates are normalized by widths and heights.
roi_key โ the key name of fields in samples to store roi_strings for each sample. Itโs used for set different rois for different samples. If itโs none, use rois in parameter โroi_stringsโ. Itโs None in default.
frame_num โ the number of frames to be extracted uniformly from the video to detect the pixels of watermark.
min_frame_threshold โ a coordination is considered as the location of a watermark pixel when it is that in no less min_frame_threshold frames.
detection_method โ the method to detect the pixels of watermark. If it is โpixel_valueโ, we consider the distribution of pixel value in each frame. If it is โpixel_diversityโ, we will consider the pixel diversity in different frames. The min_frame_threshold is useless and frame_num must be greater than 1 in โpixel_diversityโ mode.
save_dir โ The directory where generated video files will be stored. If not specified, outputs will be saved in the same directory as their corresponding input files. This path can alternatively be defined by setting the DJ_PRODUCED_DATA_DIR environment variable.
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.VideoResizeAspectRatioMapper(min_ratio: str = '9/21', max_ratio: str = '21/9', strategy: str = 'increase', save_dir: str = None, *args, **kwargs)[source]#
Bases:
MapperMapper to resize videos by aspect ratio. AspectRatio = W / H.
- STRATEGY = ['decrease', 'increase']#
- __init__(min_ratio: str = '9/21', max_ratio: str = '21/9', strategy: str = 'increase', save_dir: str = None, *args, **kwargs)[source]#
Initialization method.
- Parameters:
min_ratio โ The minimum aspect ratio to enforce videos with an aspect ratio below min_ratio will be resized to match this minimum ratio. The ratio should be provided as a string in the format โ9:21โ or โ9/21โ.
max_ratio โ The maximum aspect ratio to enforce videos with an aspect ratio above max_ratio will be resized to match this maximum ratio. The ratio should be provided as a string in the format โ21:9โ or โ21/9โ.
strategy โ The resizing strategy to apply when adjusting the video dimensions. It can be either โdecreaseโ to reduce the dimension or โincreaseโ to enlarge it. Accepted values are [โdecreaseโ, โincreaseโ].
save_dir โ The directory where generated video files will be stored. If not specified, outputs will be saved in the same directory as their corresponding input files. This path can alternatively be defined by setting the DJ_PRODUCED_DATA_DIR environment variable.
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.VideoResizeResolutionMapper(min_width: int = 1, max_width: int = 9223372036854775807, min_height: int = 1, max_height: int = 9223372036854775807, force_original_aspect_ratio: str = 'disable', force_divisible_by: Annotated[int, Gt(gt=0)] = 2, save_dir: str = None, *args, **kwargs)[source]#
Bases:
MapperMapper to resize videos resolution. We leave the super resolution with deep learning for future works.
- __init__(min_width: int = 1, max_width: int = 9223372036854775807, min_height: int = 1, max_height: int = 9223372036854775807, force_original_aspect_ratio: str = 'disable', force_divisible_by: Annotated[int, Gt(gt=0)] = 2, save_dir: str = None, *args, **kwargs)[source]#
Initialization method.
- Parameters:
min_width โ Videos with width less than โmin_widthโ will be mapped to videos with equal or bigger width.
max_width โ Videos with width more than โmax_widthโ will be mapped to videos with equal of smaller width.
min_height โ Videos with height less than โmin_heightโ will be mapped to videos with equal or bigger height.
max_height โ Videos with height more than โmax_heightโ will be mapped to videos with equal or smaller height.
force_original_aspect_ratio โ Enable decreasing or increasing output video width or height if necessary to keep the original aspect ratio, including [โdisableโ, โdecreaseโ, โincreaseโ].
force_divisible_by โ Ensures that both the output dimensions, width and height, are divisible by the given integer when used together with force_original_aspect_ratio, must be a positive even number.
save_dir โ The directory where generated video files will be stored. If not specified, outputs will be saved in the same directory as their corresponding input files. This path can alternatively be defined by setting the DJ_PRODUCED_DATA_DIR environment variable.
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.VideoSplitByDurationMapper(split_duration: float = 10, min_last_split_duration: float = 0, keep_original_sample: bool = True, save_dir: str = None, *args, **kwargs)[source]#
Bases:
MapperMapper to split video by duration.
- __init__(split_duration: float = 10, min_last_split_duration: float = 0, keep_original_sample: bool = True, save_dir: str = None, *args, **kwargs)[source]#
Initialization method.
- Parameters:
split_duration โ duration of each video split in seconds.
min_last_split_duration โ The minimum allowable duration in seconds for the last video split. If the duration of the last split is less than this value, it will be discarded.
keep_original_sample โ whether to keep the original sample. If itโs set to False, there will be only cut sample in the final datasets and the original sample will be removed. Itโs True in default.
save_dir โ The directory where generated video files will be stored. If not specified, outputs will be saved in the same directory as their corresponding input files. This path can alternatively be defined by setting the DJ_PRODUCED_DATA_DIR environment variable.
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.VideoSplitByKeyFrameMapper(keep_original_sample: bool = True, save_dir: str = None, *args, **kwargs)[source]#
Bases:
MapperMapper to split video by key frame.
- __init__(keep_original_sample: bool = True, save_dir: str = None, *args, **kwargs)[source]#
Initialization method.
- Parameters:
keep_original_sample โ whether to keep the original sample. If itโs set to False, there will be only split sample in the final datasets and the original sample will be removed. Itโs True in default.
save_dir โ The directory where generated video files will be stored. If not specified, outputs will be saved in the same directory as their corresponding input files. This path can alternatively be defined by setting the DJ_PRODUCED_DATA_DIR environment variable.
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.VideoSplitBySceneMapper(detector: str = 'ContentDetector', threshold: Annotated[float, Ge(ge=0)] = 27.0, min_scene_len: Annotated[int, Ge(ge=0)] = 15, show_progress: bool = False, save_dir: str = None, *args, **kwargs)[source]#
Bases:
MapperMapper to cut videos into scene clips.
- avaliable_detectors = {'AdaptiveDetector': ['window_width', 'min_content_val', 'weights', 'luma_only', 'kernel_size', 'video_manager', 'min_delta_hsv'], 'ContentDetector': ['weights', 'luma_only', 'kernel_size'], 'ThresholdDetector': ['fade_bias', 'add_final_scene', 'method', 'block_size']}#
- __init__(detector: str = 'ContentDetector', threshold: Annotated[float, Ge(ge=0)] = 27.0, min_scene_len: Annotated[int, Ge(ge=0)] = 15, show_progress: bool = False, save_dir: str = None, *args, **kwargs)[source]#
Initialization method.
- Parameters:
detector โ Algorithm from scenedetect.detectors. Should be one of [โContentDetectorโ, โThresholdDetectorโ, โAdaptiveDetector`].
threshold โ Threshold passed to the detector.
min_scene_len โ Minimum length of any scene.
show_progress โ Whether to show progress from scenedetect.
save_dir โ The directory where generated video files will be stored. If not specified, outputs will be saved in the same directory as their corresponding input files. This path can alternatively be defined by setting the DJ_PRODUCED_DATA_DIR environment variable.
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.VideoTaggingFromAudioMapper(hf_ast: str = 'MIT/ast-finetuned-audioset-10-10-0.4593', trust_remote_code: bool = False, tag_field_name: str = 'video_audio_tags', *args, **kwargs)[source]#
Bases:
MapperMapper to generate video tags from audio streams extracted by video using the Audio Spectrogram Transformer.
- __init__(hf_ast: str = 'MIT/ast-finetuned-audioset-10-10-0.4593', trust_remote_code: bool = False, tag_field_name: str = 'video_audio_tags', *args, **kwargs)[source]#
Initialization method.
- Parameters:
hf_ast โ path to the HF model to tag from audios.
trust_remote_code โ whether to trust the remote code of HF models
tag_field_name โ the field name to store the tags. Itโs โvideo_audio_tagsโ in default.
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.VideoTaggingFromFramesMapper(frame_sampling_method: str = 'all_keyframes', frame_num: Annotated[int, Gt(gt=0)] = 3, tag_field_name: str = 'video_frame_tags', *args, **kwargs)[source]#
Bases:
MapperMapper to generate video tags from frames extract by video.
- __init__(frame_sampling_method: str = 'all_keyframes', frame_num: Annotated[int, Gt(gt=0)] = 3, tag_field_name: str = 'video_frame_tags', *args, **kwargs)[source]#
Initialization method.
- Parameters:
frame_sampling_method โ sampling method of extracting frame images from the videos. Should be one of [โall_keyframesโ, โuniformโ]. The former one extracts all key frames (the number of which depends on the duration of the video) and the latter one extract specified number of frames uniformly from the video. Default: โall_keyframesโ.
frame_num โ the number of frames to be extracted uniformly from the video. Only works when frame_sampling_method is โuniformโ. If itโs 1, only the middle frame will be extracted. If itโs 2, only the first and the last frames will be extracted. If itโs larger than 2, in addition to the first and the last frames, other frames will be extracted uniformly within the video duration.
tag_field_name โ the field name to store the tags. Itโs โvideo_frame_tagsโ in default.
args โ extra args
kwargs โ extra args
- class data_juicer.ops.mapper.WhitespaceNormalizationMapper(*args, **kwargs)[source]#
Bases:
MapperMapper to normalize different kinds of whitespaces to whitespace โ โ (0x20) in text samples.
Different kinds of whitespaces can be found here: https://en.wikipedia.org/wiki/Whitespace_character