code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def __init__( self, cfg=None, ): """ Initialization method. :param cfg: configuration of sandbox. """ self.cfg = cfg self.watcher = SandBoxWatcher(self.cfg) self.watcher.watch_cfgs([(cfg, 'sandbox')]) # jobs to probe, refine_recipe,...
Initialization method. :param cfg: configuration of sandbox.
__init__
python
modelscope/data-juicer
data_juicer/core/sandbox/pipelines.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/core/sandbox/pipelines.py
Apache-2.0
def run(self): """ Running the sandbox pipeline at once or in HPO style. """ if self.cfg.hpo_config is not None: # execute_hpo_wandb contains running one_trail with HPO scheduler self.execute_hpo_wandb() else: self.one_trial()
Running the sandbox pipeline at once or in HPO style.
run
python
modelscope/data-juicer
data_juicer/core/sandbox/pipelines.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/core/sandbox/pipelines.py
Apache-2.0
def one_trial(self): """ Running the sandbox pipeline at once. Users can flexibly conduct some steps of the whole sandbox pipeline according to their own need and configuration. The watcher will automatically track the results in terms of data, model and specified ...
Running the sandbox pipeline at once. Users can flexibly conduct some steps of the whole sandbox pipeline according to their own need and configuration. The watcher will automatically track the results in terms of data, model and specified evaluation metrics to the watche...
one_trial
python
modelscope/data-juicer
data_juicer/core/sandbox/pipelines.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/core/sandbox/pipelines.py
Apache-2.0
def execute_hpo_wandb(self): """ Running the sandbox pipeline in HPO style. Users can flexibly conduct some steps of the whole sandbox pipeline according to their own need and configuration. The watcher will automatically track the results in terms of data, model and specifi...
Running the sandbox pipeline in HPO style. Users can flexibly conduct some steps of the whole sandbox pipeline according to their own need and configuration. The watcher will automatically track the results in terms of data, model and specified evaluation metrics to the w...
execute_hpo_wandb
python
modelscope/data-juicer
data_juicer/core/sandbox/pipelines.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/core/sandbox/pipelines.py
Apache-2.0
def _tex_proj_loader(self, file_or_dir_path): r"""function to load the tex files from a tar file or a gzip file. The function will return a tuple containing a list of tex files and the timestamp of the project. @param file_or_dir_path: path to the tar file or the gzip file @ret...
function to load the tex files from a tar file or a gzip file. The function will return a tuple containing a list of tex files and the timestamp of the project. @param file_or_dir_path: path to the tar file or the gzip file @return: tuple containing a list of tex files and the timestam...
_tex_proj_loader
python
modelscope/data-juicer
data_juicer/download/arxiv.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/download/arxiv.py
Apache-2.0
def _format_arxiv_id(self, arxiv_id): r"""this function brings the raw arxiv-id into a format compliant with the specification from arxiv. This is used to create the url to the arxiv abstract page. - Format prior to March 2007: <archive>/YYMMNNN where N is a 3-digit number ...
this function brings the raw arxiv-id into a format compliant with the specification from arxiv. This is used to create the url to the arxiv abstract page. - Format prior to March 2007: <archive>/YYMMNNN where N is a 3-digit number - Format after March 2007: <archive>/YYMM.N...
_format_arxiv_id
python
modelscope/data-juicer
data_juicer/download/arxiv.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/download/arxiv.py
Apache-2.0
def _clean_tex_file(self, file_content, arg_macros, non_arg_macros): r"""function takes a tex file as input and returns a cleaned version. The cleaned version is a concatenation of the tex files with the following modifications: - remove all comments (i.e. all lines starting with %) ...
function takes a tex file as input and returns a cleaned version. The cleaned version is a concatenation of the tex files with the following modifications: - remove all comments (i.e. all lines starting with %) - remove everything before the first section-like header - remove e...
_clean_tex_file
python
modelscope/data-juicer
data_juicer/download/arxiv.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/download/arxiv.py
Apache-2.0
def _build_non_arg_macros_dict(self, file_content): r"""function takes the content of a tex file and returns a dictionary that contains the definitions of all macros that do not use arguments. The dictionary is of the form {macro_name: macro_value}. @param file_content: the content of t...
function takes the content of a tex file and returns a dictionary that contains the definitions of all macros that do not use arguments. The dictionary is of the form {macro_name: macro_value}. @param file_content: the content of the tex file as a string. @return: dict
_build_non_arg_macros_dict
python
modelscope/data-juicer
data_juicer/download/arxiv.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/download/arxiv.py
Apache-2.0
def get_wikipedia_urls( language='en', wikidumps_index_prefix='https://dumps.wikimedia.org', dump_date: Optional[str] = None, ) -> List[str]: """ Retrieves all urls pointing to the latest Wikipedia dumps Args: language: Desired language of the Wikipedia dump. wikidumps_index_pre...
Retrieves all urls pointing to the latest Wikipedia dumps Args: language: Desired language of the Wikipedia dump. wikidumps_index_prefix: The base url for all wikipedia dumps dump_date: A string formatted as "YYYYMMDD" for the wikipedia dump to use. If None, latest dump is us...
get_wikipedia_urls
python
modelscope/data-juicer
data_juicer/download/downloader.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/download/downloader.py
Apache-2.0
def validate_snapshot_format(snapshot: Optional[str]) -> None: """ Validate snapshot format 'YYYY-WW'. Args: snapshot: Snapshot string in format 'YYYY-WW' or None Raises: ValueError: If format is invalid """ if snapshot is None: return # Check basic format with reg...
Validate snapshot format 'YYYY-WW'. Args: snapshot: Snapshot string in format 'YYYY-WW' or None Raises: ValueError: If format is invalid
validate_snapshot_format
python
modelscope/data-juicer
data_juicer/download/downloader.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/download/downloader.py
Apache-2.0
def __init__(self, dataset_path, suffixes=None, **kwargs): """ Initialization method. :param dataset_path: a dataset file or a dataset directory :param suffixes: files with specified suffixes to be processed :param kwargs: extra args """ super().__init__( ...
Initialization method. :param dataset_path: a dataset file or a dataset directory :param suffixes: files with specified suffixes to be processed :param kwargs: extra args
__init__
python
modelscope/data-juicer
data_juicer/format/csv_formatter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/format/csv_formatter.py
Apache-2.0
def __init__(self, length, feature_keys: List[str] = [], *args, **kwargs): """ Initialization method. :param length: The empty dataset length. :param feature_keys: feature key name list. """ self.length = length self.feature_keys = feature_keys if isinsta...
Initialization method. :param length: The empty dataset length. :param feature_keys: feature key name list.
__init__
python
modelscope/data-juicer
data_juicer/format/empty_formatter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/format/empty_formatter.py
Apache-2.0
def __init__( self, dataset_path: str, type: str, suffixes: Union[str, List[str], None] = None, text_keys: List[str] = None, add_suffix=False, **kwargs, ): """ Initialization method. :param dataset_path: path to a dataset file or a dat...
Initialization method. :param dataset_path: path to a dataset file or a dataset directory :param type: a packaged dataset module type (json, csv, etc.) :param suffixes: files with specified suffixes to be processed :param text_keys: key names of field that stores sa...
__init__
python
modelscope/data-juicer
data_juicer/format/formatter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/format/formatter.py
Apache-2.0
def load_dataset(self, num_proc: int = 1, global_cfg=None) -> Dataset: """ Load a dataset from dataset file or dataset directory, and unify its format. :param num_proc: number of processes when loading the dataset :param global_cfg: global cfg used in consequent processes, ...
Load a dataset from dataset file or dataset directory, and unify its format. :param num_proc: number of processes when loading the dataset :param global_cfg: global cfg used in consequent processes, :return: formatted dataset
load_dataset
python
modelscope/data-juicer
data_juicer/format/formatter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/format/formatter.py
Apache-2.0
def __init__(self, dataset_path: str, text_keys: List[str] = None, **kwargs): """ Initialization method. :param dataset_path: a dataset file or a dataset directory :param text_keys: key names of field that stores sample text...
Initialization method. :param dataset_path: a dataset file or a dataset directory :param text_keys: key names of field that stores sample text. :param kwargs: extra args
__init__
python
modelscope/data-juicer
data_juicer/format/formatter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/format/formatter.py
Apache-2.0
def load_dataset(self, num_proc: int = 1, global_cfg=None) -> Dataset: """ Load a dataset from HuggingFace, and unify its format. :param num_proc: number of processes when loading the dataset :param global_cfg: the global cfg used in consequent processes, :return: formatted data...
Load a dataset from HuggingFace, and unify its format. :param num_proc: number of processes when loading the dataset :param global_cfg: the global cfg used in consequent processes, :return: formatted dataset
load_dataset
python
modelscope/data-juicer
data_juicer/format/formatter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/format/formatter.py
Apache-2.0
def add_suffixes(datasets: DatasetDict, num_proc: int = 1) -> Dataset: """ Add suffix filed to datasets. :param datasets: a DatasetDict object :param num_proc: number of processes to add suffixes :return: datasets with suffix features. """ logger.info('Add suffix column for dataset') fr...
Add suffix filed to datasets. :param datasets: a DatasetDict object :param num_proc: number of processes to add suffixes :return: datasets with suffix features.
add_suffixes
python
modelscope/data-juicer
data_juicer/format/formatter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/format/formatter.py
Apache-2.0
def unify_format( dataset: Dataset, text_keys: Union[List[str], str] = 'text', num_proc: int = 1, global_cfg=None, ) -> Dataset: """ Get an unified internal format, conduct the following modifications. 1. check keys of dataset 2. filter out those samples with empty or None text :p...
Get an unified internal format, conduct the following modifications. 1. check keys of dataset 2. filter out those samples with empty or None text :param dataset: input dataset :param text_keys: original text key(s) of dataset. :param num_proc: number of processes for mapping :param globa...
unify_format
python
modelscope/data-juicer
data_juicer/format/formatter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/format/formatter.py
Apache-2.0
def load_formatter(dataset_path, text_keys=None, suffixes=None, add_suffix=False, **kwargs) -> BaseFormatter: """ Load the appropriate formatter for different types of data formats. :param dataset_path: Path to dataset file or data...
Load the appropriate formatter for different types of data formats. :param dataset_path: Path to dataset file or dataset directory :param text_keys: key names of field that stores sample text. Default: None :param suffixes: the suffix of files that will be read. Default: None :para...
load_formatter
python
modelscope/data-juicer
data_juicer/format/load.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/format/load.py
Apache-2.0
def extract_txt_from_docx(fn, tgt_path): """ Extract text from a docx file and save to target path. :param fn: path to input pdf file :param tgt_path: path to save text file. """ doc = Document(fn) text = [para.text for para in doc.paragraphs if para.text.strip()] base_fn = os.path.base...
Extract text from a docx file and save to target path. :param fn: path to input pdf file :param tgt_path: path to save text file.
extract_txt_from_docx
python
modelscope/data-juicer
data_juicer/format/text_formatter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/format/text_formatter.py
Apache-2.0
def extract_txt_from_pdf(fn, tgt_path): """ Extract text from a pdf file and save to target path. :param fn: path to input pdf file :param tgt_path: path to save text file. """ with pdfplumber.open(fn) as pdf: text = [] for page in pdf.pages: # remove tables from eac...
Extract text from a pdf file and save to target path. :param fn: path to input pdf file :param tgt_path: path to save text file.
extract_txt_from_pdf
python
modelscope/data-juicer
data_juicer/format/text_formatter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/format/text_formatter.py
Apache-2.0
def __init__(self, dataset_path, suffixes=None, add_suffix=False, **kwargs): """ Initialization method. :param dataset_path: a dataset file or a dataset directory :param suffixes: files with specified suffixes to be pro...
Initialization method. :param dataset_path: a dataset file or a dataset directory :param suffixes: files with specified suffixes to be processed :param add_suffix: Whether to add file suffix to dataset meta info :param kwargs: extra args
__init__
python
modelscope/data-juicer
data_juicer/format/text_formatter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/format/text_formatter.py
Apache-2.0
def load_dataset(self, num_proc: int = 1, global_cfg=None) -> Dataset: """ Load a dataset from local text-type files. :param num_proc: number of processes when loading the dataset :param global_cfg: the global cfg used in consequent processes, :return: unified_format_dataset. ...
Load a dataset from local text-type files. :param num_proc: number of processes when loading the dataset :param global_cfg: the global cfg used in consequent processes, :return: unified_format_dataset.
load_dataset
python
modelscope/data-juicer
data_juicer/format/text_formatter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/format/text_formatter.py
Apache-2.0
def catch_map_batches_exception(method, skip_op_error=False, op_name=None): """ For batched-map sample-level fault tolerance. """ if op_name is None: op_name = method.__name__ @wraps(method) @convert_arrow_to_python def wrapper(samples, *args, **kwargs): try: re...
For batched-map sample-level fault tolerance.
catch_map_batches_exception
python
modelscope/data-juicer
data_juicer/ops/base_op.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/base_op.py
Apache-2.0
def catch_map_single_exception(method, return_sample=True, skip_op_error=False, op_name=None): """ For single-map sample-level fault tolerance. The input sample is expected batch_size = 1. """ if op_name is...
For single-map sample-level fault tolerance. The input sample is expected batch_size = 1.
catch_map_single_exception
python
modelscope/data-juicer
data_juicer/ops/base_op.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/base_op.py
Apache-2.0
def __init__(self, *args, **kwargs): """ Base class of operators. :param text_key: the key name of field that stores sample texts to be processed. :param image_key: the key name of field that stores sample image list to be processed :param audio_key: the ...
Base class of operators. :param text_key: the key name of field that stores sample texts to be processed. :param image_key: the key name of field that stores sample image list to be processed :param audio_key: the key name of field that stores sample audio list ...
__init__
python
modelscope/data-juicer
data_juicer/ops/base_op.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/base_op.py
Apache-2.0
def remove_extra_parameters(self, param_dict, keys=None): """ at the beginning of the init of the mapper op, call self.remove_extra_parameters(locals()) to get the init parameter dict of the op for convenience """ if keys is None: param_dict = { ...
at the beginning of the init of the mapper op, call self.remove_extra_parameters(locals()) to get the init parameter dict of the op for convenience
remove_extra_parameters
python
modelscope/data-juicer
data_juicer/ops/base_op.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/base_op.py
Apache-2.0
def add_parameters(self, init_parameter_dict, **extra_param_dict): """ add parameters for each sample, need to keep extra_param_dict and init_parameter_dict unchanged. """ related_parameters = copy.deepcopy(init_parameter_dict) related_parameters.update(extra_para...
add parameters for each sample, need to keep extra_param_dict and init_parameter_dict unchanged.
add_parameters
python
modelscope/data-juicer
data_juicer/ops/base_op.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/base_op.py
Apache-2.0
def __init__(self, *args, **kwargs): """ Base class that conducts data editing. :param text_key: the key name of field that stores sample texts to be processed. :param image_key: the key name of field that stores sample image list to be processed :param a...
Base class that conducts data editing. :param text_key: the key name of field that stores sample texts to be processed. :param image_key: the key name of field that stores sample image list to be processed :param audio_key: the key name of field that stores samp...
__init__
python
modelscope/data-juicer
data_juicer/ops/base_op.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/base_op.py
Apache-2.0
def __init__(self, *args, **kwargs): """ Base class that removes specific info. :param text_key: the key name of field that stores sample texts to be processed :param image_key: the key name of field that stores sample image list to be processed :param au...
Base class that removes specific info. :param text_key: the key name of field that stores sample texts to be processed :param image_key: the key name of field that stores sample image list to be processed :param audio_key: the key name of field that stores sampl...
__init__
python
modelscope/data-juicer
data_juicer/ops/base_op.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/base_op.py
Apache-2.0
def __init__(self, *args, **kwargs): """ Base class that conducts deduplication. :param text_key: the key name of field that stores sample texts to be processed :param image_key: the key name of field that stores sample image list to be processed :param a...
Base class that conducts deduplication. :param text_key: the key name of field that stores sample texts to be processed :param image_key: the key name of field that stores sample image list to be processed :param audio_key: the key name of field that stores samp...
__init__
python
modelscope/data-juicer
data_juicer/ops/base_op.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/base_op.py
Apache-2.0
def __init__(self, *args, **kwargs): """ Base class that group samples. :param text_key: the key name of field that stores sample texts to be processed :param image_key: the key name of field that stores sample image list to be processed :param audio_key:...
Base class that group samples. :param text_key: the key name of field that stores sample texts to be processed :param image_key: the key name of field that stores sample image list to be processed :param audio_key: the key name of field that stores sample audio ...
__init__
python
modelscope/data-juicer
data_juicer/ops/base_op.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/base_op.py
Apache-2.0
def load_ops(process_list): """ Load op list according to the process list from config file. :param process_list: A process list. Each item is an op name and its arguments. :return: The op instance list. """ ops = [] new_process_list = [] for process in process_list: op...
Load op list according to the process list from config file. :param process_list: A process list. Each item is an op name and its arguments. :return: The op instance list.
load_ops
python
modelscope/data-juicer
data_juicer/ops/load.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/load.py
Apache-2.0
def register_event_handler(self, event_type: str, handler: Callable): """Register a handler for a specific event type. Args: event_type: Type of event to handle handler: Callback function to handle the event """ if event_type not in self.event_handlers: ...
Register a handler for a specific event type. Args: event_type: Type of event to handle handler: Callback function to handle the event
register_event_handler
python
modelscope/data-juicer
data_juicer/ops/mixins.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/mixins.py
Apache-2.0
def trigger_event(self, event_type: str, data: Dict): """Trigger an event and call all registered handlers. Args: event_type: Type of event to trigger data: Event data to pass to handlers """ if event_type in self.event_handlers: for handler in self.e...
Trigger an event and call all registered handlers. Args: event_type: Type of event to trigger data: Event data to pass to handlers
trigger_event
python
modelscope/data-juicer
data_juicer/ops/mixins.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/mixins.py
Apache-2.0
def start_polling(self, event_type: str, poll_func: Callable, interval: int = 60): """Start polling for a specific event type. Args: event_type: Type of event to poll for poll_func: Function to call for polling ...
Start polling for a specific event type. Args: event_type: Type of event to poll for poll_func: Function to call for polling interval: Polling interval in seconds
start_polling
python
modelscope/data-juicer
data_juicer/ops/mixins.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/mixins.py
Apache-2.0
def stop_polling(self, event_type: str): """Stop polling for a specific event type. Args: event_type: Type of event to stop polling for """ if event_type in self.polling_threads: self.stop_polling_flags[event_type] = True self.polling_threads[event_ty...
Stop polling for a specific event type. Args: event_type: Type of event to stop polling for
stop_polling
python
modelscope/data-juicer
data_juicer/ops/mixins.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/mixins.py
Apache-2.0
def wait_for_completion(self, condition_func: Callable[[], bool], timeout: int = 3600, poll_interval: int = 10, error_message: str = 'Operation timed out'): """Wait for a condition to be met. ...
Wait for a condition to be met. Args: condition_func: Function that returns True when condition is met timeout: Maximum time to wait in seconds poll_interval: Polling interval in seconds error_message: Error message to raise on timeout Raises: ...
wait_for_completion
python
modelscope/data-juicer
data_juicer/ops/mixins.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/mixins.py
Apache-2.0
def send_notification(self, message: str, notification_type: str = None, **kwargs): """Send a notification message. Args: message: The message to send notification_type: The type of notification to sen...
Send a notification message. Args: message: The message to send notification_type: The type of notification to send. Email, Slack, DingTalk. If None, send nothing **kwargs: Additional arguments to pass to the no...
send_notification
python
modelscope/data-juicer
data_juicer/ops/mixins.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/mixins.py
Apache-2.0
def _send_email_notification(self, message: str, **kwargs): """Send an email notification. Args: message: The message to send **kwargs: Additional parameters for email configuration (recipients, subject, etc.) Returns: bool: Whether the...
Send an email notification. Args: message: The message to send **kwargs: Additional parameters for email configuration (recipients, subject, etc.) Returns: bool: Whether the email was sent successfully
_send_email_notification
python
modelscope/data-juicer
data_juicer/ops/mixins.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/mixins.py
Apache-2.0
def _send_slack_notification(self, message: str, **kwargs): """Send a Slack notification. Args: message: The message to send **kwargs: Additional parameters for Slack configuration (webhook_url, channel, etc.) Returns: bool: Whether the...
Send a Slack notification. Args: message: The message to send **kwargs: Additional parameters for Slack configuration (webhook_url, channel, etc.) Returns: bool: Whether the notification was sent successfully
_send_slack_notification
python
modelscope/data-juicer
data_juicer/ops/mixins.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/mixins.py
Apache-2.0
def _send_dingtalk_notification(self, message: str, **kwargs): """Send a DingTalk notification. Args: message: The message to send **kwargs: Additional parameters for DingTalk configuration (access_token, secret, etc.) Returns: bool: Wh...
Send a DingTalk notification. Args: message: The message to send **kwargs: Additional parameters for DingTalk configuration (access_token, secret, etc.) Returns: bool: Whether the notification was sent successfully
_send_dingtalk_notification
python
modelscope/data-juicer
data_juicer/ops/mixins.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/mixins.py
Apache-2.0
def fuse_operators(ops, probe_res=None): """ Fuse the input ops list and return the fused ops list. :param ops: the corresponding list of op objects. :param probe_res: the probed speed for each OP from Monitor. :return: a list of fused op objects. """ if probe_res is None: probe_res...
Fuse the input ops list and return the fused ops list. :param ops: the corresponding list of op objects. :param probe_res: the probed speed for each OP from Monitor. :return: a list of fused op objects.
fuse_operators
python
modelscope/data-juicer
data_juicer/ops/op_fusion.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/op_fusion.py
Apache-2.0
def fuse_filter_group(original_filter_group): """ Fuse single filter group and return the fused filter group. :param original_filter_group: the original filter group, including op definitions and objects. :return: the fused definitions and objects of the input filter group. """ fused_gr...
Fuse single filter group and return the fused filter group. :param original_filter_group: the original filter group, including op definitions and objects. :return: the fused definitions and objects of the input filter group.
fuse_filter_group
python
modelscope/data-juicer
data_juicer/ops/op_fusion.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/op_fusion.py
Apache-2.0
def __init__(self, name: str, fused_filters: List): """ Initialization method. :param fused_filters: a list of filters to be fused. """ self._name = name super().__init__() self.fused_filters = fused_filters # set accelerator to 'cuda' if there exists any...
Initialization method. :param fused_filters: a list of filters to be fused.
__init__
python
modelscope/data-juicer
data_juicer/ops/op_fusion.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/op_fusion.py
Apache-2.0
def __init__(self, api_model: str = 'gpt-4o', meta_tag_key: str = MetaKeys.dialog_sentiment_labels, target_tags: Optional[List[str]] = None, *, api_endpoint: Optional[str] = None, response_path: Optional[str] = None, ...
Initialization method. :param api_model: API model name. :param meta_tag_key: The key of the meta tag to be mapped. :param target_tags: The tags that is supposed to be mapped to. :param api_endpoint: URL endpoint for the API. :param response_path: Path to extract content...
__init__
python
modelscope/data-juicer
data_juicer/ops/aggregator/meta_tags_aggregator.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/aggregator/meta_tags_aggregator.py
Apache-2.0
def strip(document, strip_characters): """ Way faster than document.strip(strip_characters) since strip_characters is now a set instead of a str, and it contains a lot of elements (all the emojis). :param document: document to be processed :param strip_characters: characters used for stripping ...
Way faster than document.strip(strip_characters) since strip_characters is now a set instead of a str, and it contains a lot of elements (all the emojis). :param document: document to be processed :param strip_characters: characters used for stripping document :return: stripped document
strip
python
modelscope/data-juicer
data_juicer/ops/common/helper_func.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/common/helper_func.py
Apache-2.0
def split_on_whitespace(document, new_line=False, tab=False): """ This method also removes concatenated spaces. :param document: document to be split :param new_line: whether to split document with '\\\\n' :param tag: whether to split document with '\\\\t' :return: word list obtained after spli...
This method also removes concatenated spaces. :param document: document to be split :param new_line: whether to split document with '\\n' :param tag: whether to split document with '\\t' :return: word list obtained after splitting document
split_on_whitespace
python
modelscope/data-juicer
data_juicer/ops/common/helper_func.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/common/helper_func.py
Apache-2.0
def split_on_newline_tab_whitespace(document): """ This method is used to split the document into different levels of sub- sentences. First split on "\\\\n", then on "\\\\t", then on " ". :param document: document to be split :return: sentence list obtained after splitting document """ ...
This method is used to split the document into different levels of sub- sentences. First split on "\\n", then on "\\t", then on " ". :param document: document to be split :return: sentence list obtained after splitting document
split_on_newline_tab_whitespace
python
modelscope/data-juicer
data_juicer/ops/common/helper_func.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/common/helper_func.py
Apache-2.0
def merge_on_whitespace_tab_newline(sentences): """ This method is used to merge different levels of sub-sentences into one document. Invert the method split_on_newline_tab_whitespace. Removes concatenated separators. :param sentences: sentence list to be merged :return: document obtained after...
This method is used to merge different levels of sub-sentences into one document. Invert the method split_on_newline_tab_whitespace. Removes concatenated separators. :param sentences: sentence list to be merged :return: document obtained after merging sub-sentences
merge_on_whitespace_tab_newline
python
modelscope/data-juicer
data_juicer/ops/common/helper_func.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/common/helper_func.py
Apache-2.0
def words_augmentation(words, group_size, join_char): """ Augment words, especially for Chinese (without a space between words) and Vietnamese (with a space between syllables). :param word: word list to be augmented :param group_size: the size of word groups that need to be merged :param join_c...
Augment words, especially for Chinese (without a space between words) and Vietnamese (with a space between syllables). :param word: word list to be augmented :param group_size: the size of word groups that need to be merged :param join_char: characters to be added between word group :return: w...
words_augmentation
python
modelscope/data-juicer
data_juicer/ops/common/helper_func.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/common/helper_func.py
Apache-2.0
def get_words_from_document( document, token_func=None, new_line=True, tab=True, ): """ Get words from a document. Useful to compute ratios, like the stopwords ratio. :param document: document that need to split words. :param token_func: function of tokenizer, if specified, the func...
Get words from a document. Useful to compute ratios, like the stopwords ratio. :param document: document that need to split words. :param token_func: function of tokenizer, if specified, the function will be used for split document into different tokens. :param new_line: whether to use '\\n' ...
get_words_from_document
python
modelscope/data-juicer
data_juicer/ops/common/helper_func.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/common/helper_func.py
Apache-2.0
def words_refinement(words, lower_case=False, strip_chars=None, use_words_aug=False, words_aug_group_sizes=[2], words_aug_join_char=''): """ Refine split words. Non reversible since the document is split on ...
Refine split words. Non reversible since the document is split on multiple characters, words are stripped of special characters and characters are converted to lower case. :param words: the word list to be augmented :param lower_case: whether to convert word to lowercase :param strip_chars: ch...
words_refinement
python
modelscope/data-juicer
data_juicer/ops/common/helper_func.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/common/helper_func.py
Apache-2.0
def get_sentences_from_document(document, model_func=None): """ Get sentences from a document. :param document: document that need to split sentences :param model_func: function of sentence model, if specified, the function will be used for splitting document into different sentences. ...
Get sentences from a document. :param document: document that need to split sentences :param model_func: function of sentence model, if specified, the function will be used for splitting document into different sentences. :return: document with the sentences separated by '\\n'
get_sentences_from_document
python
modelscope/data-juicer
data_juicer/ops/common/helper_func.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/common/helper_func.py
Apache-2.0
def split_text_by_punctuation(text): """ Split text by any zh and en punctuation :param text: text to be split. :return: sub texts split by any zh and en punctuation """ # any zh and en punctuation punctuation_pattern = r'[\u3000-\u303f\uff00-\uffef]|[!"#$%&\'()*+,-./:;<=>?@[\\\]^_`{|}~]' ...
Split text by any zh and en punctuation :param text: text to be split. :return: sub texts split by any zh and en punctuation
split_text_by_punctuation
python
modelscope/data-juicer
data_juicer/ops/common/helper_func.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/common/helper_func.py
Apache-2.0
def rescale_noise_cfg(noise_cfg, noise_pred_text, guidance_rescale=0.0): """ Rescale `noise_cfg` according to `guidance_rescale`. Based on findings of [Common Diffusion Noise Schedules and Sample Steps are Flawed](https://arxiv.org/pdf/2305.08891.pdf). See Section 3.4 """ std_text = noise_p...
Rescale `noise_cfg` according to `guidance_rescale`. Based on findings of [Common Diffusion Noise Schedules and Sample Steps are Flawed](https://arxiv.org/pdf/2305.08891.pdf). See Section 3.4
rescale_noise_cfg
python
modelscope/data-juicer
data_juicer/ops/common/prompt2prompt_pipeline.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/common/prompt2prompt_pipeline.py
Apache-2.0
def __init__(self, lowercase: bool = False, ignore_non_character: bool = False, *args, **kwargs): """ Initialization method. :param lowercase: Whether to convert sample text to lower case :param ignore_non_character: Wh...
Initialization method. :param lowercase: Whether to convert sample text to lower case :param ignore_non_character: Whether to ignore non-alphabet characters, including whitespaces, digits, and punctuations :param args: extra args :param kwargs: extra args.
__init__
python
modelscope/data-juicer
data_juicer/ops/deduplicator/document_deduplicator.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/deduplicator/document_deduplicator.py
Apache-2.0
def compute_hash(self, sample): """ Compute md5 hash values for the sample. :param sample: input sample :return: sample with md5 hash value. """ # check if it's computed already if HashKeys.hash in sample: return sample text = sample[self.tex...
Compute md5 hash values for the sample. :param sample: input sample :return: sample with md5 hash value.
compute_hash
python
modelscope/data-juicer
data_juicer/ops/deduplicator/document_deduplicator.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/deduplicator/document_deduplicator.py
Apache-2.0
def process(self, dataset, show_num=0): """ For doc-level, dataset --> dataset. :param dataset: input dataset :param show_num: number of traced samples used when tracer is open. :return: deduplicated dataset and the sampled duplicate pairs. """ # no n...
For doc-level, dataset --> dataset. :param dataset: input dataset :param show_num: number of traced samples used when tracer is open. :return: deduplicated dataset and the sampled duplicate pairs.
process
python
modelscope/data-juicer
data_juicer/ops/deduplicator/document_deduplicator.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/deduplicator/document_deduplicator.py
Apache-2.0
def optimal_param( threshold: float, num_perm: int, false_positive_weight: float = 0.5, false_negative_weight: float = 0.5, ): """ Compute the optimal `MinHashLSH` parameter that minimizes the weighted sum of probabilities of false positive and false negative, taken from datasketch. ...
Compute the optimal `MinHashLSH` parameter that minimizes the weighted sum of probabilities of false positive and false negative, taken from datasketch. :param threshold: float. The threshold for similarity :param num_perm: int. The number of permutations :param false_positive_weight: float. T...
optimal_param
python
modelscope/data-juicer
data_juicer/ops/deduplicator/document_minhash_deduplicator.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/deduplicator/document_minhash_deduplicator.py
Apache-2.0
def __init__( self, tokenization: str = 'space', window_size: PositiveInt = 5, lowercase: bool = True, ignore_pattern: Optional[str] = None, num_permutations: PositiveInt = 256, jaccard_threshold: Annotated[float, Field(ge=0, le=1)] = 0.7, num_bands: Optio...
Initialization method. :param tokenization: tokenization method for sample texts. It should be one of [space, punctuation, character, sentencepiece]. For English-like languages, we recommend to use 'space', for Chinese-like languages, we recommend to use...
__init__
python
modelscope/data-juicer
data_juicer/ops/deduplicator/document_minhash_deduplicator.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/deduplicator/document_minhash_deduplicator.py
Apache-2.0
def compute_hash(self, sample): """ Compute minhash values for the sample. :param sample: input sample :return: sample with minhash value. """ # check if it's computed already if HashKeys.minhash in sample: return sample text = sample[self.te...
Compute minhash values for the sample. :param sample: input sample :return: sample with minhash value.
compute_hash
python
modelscope/data-juicer
data_juicer/ops/deduplicator/document_minhash_deduplicator.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/deduplicator/document_minhash_deduplicator.py
Apache-2.0
def __init__(self, tokenization: str = 'space', window_size: PositiveInt = 6, lowercase: bool = True, ignore_pattern: Optional[str] = None, num_blocks: PositiveInt = 6, hamming_distance: PositiveInt = 4, ...
Initialization method :param tokenization: tokenization method for sample texts. It should be one of [space, punctuation, character]. For English-like languages, we recommend to use 'space'. And for Chinese-like languages, we recommend to use 'character' :param window_...
__init__
python
modelscope/data-juicer
data_juicer/ops/deduplicator/document_simhash_deduplicator.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/deduplicator/document_simhash_deduplicator.py
Apache-2.0
def compute_hash(self, sample): """ Compute simhash values for the sample. :param sample: input sample :return: sample with simhash value. """ # check if it's computed already if HashKeys.simhash in sample: return sample text = sample[self.te...
Compute simhash values for the sample. :param sample: input sample :return: sample with simhash value.
compute_hash
python
modelscope/data-juicer
data_juicer/ops/deduplicator/document_simhash_deduplicator.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/deduplicator/document_simhash_deduplicator.py
Apache-2.0
def __init__(self, method: str = 'phash', consider_text: bool = False, *args, **kwargs): """ Initialization method. :param method: hash method for image :param consider_text: whether to consider text hash together with ...
Initialization method. :param method: hash method for image :param consider_text: whether to consider text hash together with image hash when applying deduplication. :param args: extra args :param kwargs: extra args
__init__
python
modelscope/data-juicer
data_juicer/ops/deduplicator/image_deduplicator.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/deduplicator/image_deduplicator.py
Apache-2.0
def __init__(self, backend: str = 'ray_actor', redis_address: str = 'redis://localhost:6379', *args, **kwargs): """ Initialization. :param backend: the backend for dedup, either 'ray_actor' or 'redis' :param redis_addres...
Initialization. :param backend: the backend for dedup, either 'ray_actor' or 'redis' :param redis_address: the address of redis server :param args: extra args :param kwargs: extra args
__init__
python
modelscope/data-juicer
data_juicer/ops/deduplicator/ray_basic_deduplicator.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/deduplicator/ray_basic_deduplicator.py
Apache-2.0
def get_remote_classes(): """Get remote versions of classes with Ray decorators applied at runtime.""" # Apply ray.method decorator to get_next_id at runtime IdGenerator.get_next_id = ray.method(num_returns=2)( IdGenerator.get_next_id) return { 'IdGenerator': ray.remote(IdGenerator), ...
Get remote versions of classes with Ray decorators applied at runtime.
get_remote_classes
python
modelscope/data-juicer
data_juicer/ops/deduplicator/ray_bts_minhash_deduplicator.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/deduplicator/ray_bts_minhash_deduplicator.py
Apache-2.0
def __init__( self, tokenization: str = 'space', window_size: PositiveInt = 5, lowercase: bool = True, ignore_pattern: Optional[str] = None, num_permutations: PositiveInt = 256, jaccard_threshold: Annotated[float, Field(ge=0, le=1)] = 0.7, num_bands: Optio...
Initialization method. :param tokenization: tokenization method for sample texts. It should be one of [space, punctuation, character, sentencepiece]. For English-like languages, we recommend to use 'space', for Chinese-like languages, we recommend to use...
__init__
python
modelscope/data-juicer
data_juicer/ops/deduplicator/ray_bts_minhash_deduplicator.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/deduplicator/ray_bts_minhash_deduplicator.py
Apache-2.0
def __init__(self, backend: str = 'ray_actor', redis_address: str = 'redis://localhost:6379', lowercase: bool = False, ignore_non_character: bool = False, *args, **kwargs): """ Initialization method. ...
Initialization method. :param backend: the backend for dedup, either 'ray_actor' or 'redis' :param redis_address: the address of redis server :param lowercase: Whether to convert sample text to lower case :param ignore_non_character: Whether to ignore non-alphabet charac...
__init__
python
modelscope/data-juicer
data_juicer/ops/deduplicator/ray_document_deduplicator.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/deduplicator/ray_document_deduplicator.py
Apache-2.0
def __init__(self, consider_text: bool = False, *args, **kwargs): """ Initialization. :param consider_text: whether to consider text hash together with video hash when applying deduplication. :param args: extra args :param kwargs: extra args """ super...
Initialization. :param consider_text: whether to consider text hash together with video hash when applying deduplication. :param args: extra args :param kwargs: extra args
__init__
python
modelscope/data-juicer
data_juicer/ops/deduplicator/video_deduplicator.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/deduplicator/video_deduplicator.py
Apache-2.0
def __init__(self, tokenization: bool = False, min_ratio: float = 0.25, max_ratio: float = sys.maxsize, *args, **kwargs): """ Initialization method. :param tokenization: Whether to count the ratio of alphanumer...
Initialization method. :param tokenization: Whether to count the ratio of alphanumeric to the total number of tokens. if tokenization=False, it will count the ratio of alphanumeric to the total number of characters. :param min_ratio: The min filter ratio in ...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/alphanumeric_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/alphanumeric_filter.py
Apache-2.0
def __init__(self, min_duration: int = 0, max_duration: int = sys.maxsize, any_or_all: str = 'any', *args, **kwargs): """ Initialization method. :param min_duration: The min audio duration to keep samples in se...
Initialization method. :param min_duration: The min audio duration to keep samples in seconds. It's 0 by default. :param max_duration: The max audio duration to keep samples in seconds. It's sys.maxsize by default. :param any_or_all: keep this sample with 'any' ...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/audio_duration_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/audio_duration_filter.py
Apache-2.0
def __init__(self, min_snr: float = 0, max_snr: float = sys.maxsize, nmf_iter_num: PositiveInt = 500, any_or_all: str = 'any', *args, **kwargs): """ Initialization method. :param min_snr: The m...
Initialization method. :param min_snr: The min audio SNR to keep samples in dB. It's 0 by default. :param max_snr: The max audio SNR to keep samples in dB. It's sys.maxsize by default. :param nmf_iter_num: The max number of iterations to run NMF. It's 500 ...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/audio_nmf_snr_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/audio_nmf_snr_filter.py
Apache-2.0
def __init__(self, min_len: int = 10, max_len: int = sys.maxsize, *args, **kwargs): """ Initialization method. :param min_len: The min filter length in this op, samples will be filtered if their average line length ...
Initialization method. :param min_len: The min filter length in this op, samples will be filtered if their average line length is below this parameter. :param max_len: The max filter length in this op, samples will be filtered if their average line length ex...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/average_line_length_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/average_line_length_filter.py
Apache-2.0
def __init__(self, rep_len: PositiveInt = 10, min_ratio: float = 0.0, max_ratio: float = 0.5, *args, **kwargs): """ Initialization method. :param rep_len: Repetition length for char-level n-gram. :param...
Initialization method. :param rep_len: Repetition length for char-level n-gram. :param min_ratio: The min filter ratio in this op, samples will be filtered if their char-level n-gram repetition ratio is below this parameter. :param max_ratio: The max filter rati...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/character_repetition_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/character_repetition_filter.py
Apache-2.0
def __init__(self, lang: str = 'en', tokenization: bool = False, max_ratio: float = 0.045, flagged_words_dir: str = ASSET_DIR, use_words_aug: bool = False, words_aug_group_sizes: List[PositiveInt] = [2], ...
Initialization method. :param lang: Consider flagged words in what language. If lang == "all", we will adopt the one merged from all the available languages :param tokenization: Whether to use model to tokenize documents :param max_ratio: The max filter ratio in...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/flagged_words_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/flagged_words_filter.py
Apache-2.0
def __init__(self, filter_condition: str = '', *args, **kwargs): """ Initialization method. :param filter_condition: The filter condition as a string. It can include logical operators (and/or) and chain comparisons. For example: "10 < num <= 30 and text != 'nothing here' ...
Initialization method. :param filter_condition: The filter condition as a string. It can include logical operators (and/or) and chain comparisons. For example: "10 < num <= 30 and text != 'nothing here' and __dj__meta__.a == 3".
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/general_field_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/general_field_filter.py
Apache-2.0
def __init__(self, hf_scorer_model: str = '', trust_remote_code: bool = False, min_score: float = 0.5, max_score: float = 1.0, any_or_all: str = 'any', *args, **kwargs): """ Initializat...
Initialization method. :param hf_scorer_model: Huggingface model name for the aesthetics predictor. By default, we will use 'shunk031/aesthetics-predictor-v2-sac-logos-ava1-l14-linearMSE', refer to pypi.org/project/simple-aesthetics-predictor :param min_scor...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/image_aesthetics_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/image_aesthetics_filter.py
Apache-2.0
def __init__(self, min_ratio: float = 0.333, max_ratio: float = 3.0, any_or_all: str = 'any', *args, **kwargs): """ Initialization method. :param min_ratio: The min aspect ratio to keep samples. :param ...
Initialization method. :param min_ratio: The min aspect ratio to keep samples. :param max_ratio: The max aspect ratio to keep samples. :param any_or_all: keep this sample with 'any' or 'all' strategy of all images. 'any': keep this sample if any images meet the ...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/image_aspect_ratio_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/image_aspect_ratio_filter.py
Apache-2.0
def __init__(self, cv_classifier: str = '', min_face_count: int = 1, max_face_count: int = 1, any_or_all: str = 'any', *args, **kwargs): """ Initialization method. :param cv_classifier: OpenCV ...
Initialization method. :param cv_classifier: OpenCV classifier path for face detection. By default, we will use 'haarcascade_frontalface_alt.xml'. :param min_face_count: Minimum number of faces required for samples. :param max_face_count: Maximum number of faces required fo...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/image_face_count_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/image_face_count_filter.py
Apache-2.0
def __init__(self, cv_classifier: str = '', min_ratio: float = 0.0, max_ratio: float = 0.4, any_or_all: str = 'any', *args, **kwargs): """ Initialization method. :param cv_classifier: OpenCV cl...
Initialization method. :param cv_classifier: OpenCV classifier path for face detection. By default, we will use 'haarcascade_frontalface_alt.xml'. :param min_ratio: Min ratio for the largest face area in an image. :param max_ratio: Max ratio for the largest face area in an ...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/image_face_ratio_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/image_face_ratio_filter.py
Apache-2.0
def __init__(self, hf_nsfw_model: str = 'Falconsai/nsfw_image_detection', trust_remote_code: bool = False, max_score: float = 0.5, any_or_all: str = 'any', *args, **kwargs): """ Initialization method. ...
Initialization method. :param hf_nsfw_model: nsfw detection model name on huggingface. :param max_score: the nsfw score threshold for samples. range from 0 to 1. Samples with nsfw score less than this threshold will be kept. :param any_or_all: keep this sample w...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/image_nsfw_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/image_nsfw_filter.py
Apache-2.0
def __init__(self, hf_clip='openai/clip-vit-base-patch32', trust_remote_code=False, min_score: ClosedUnitInterval = 0.1, max_score: ClosedUnitInterval = 1.0, any_or_all: str = 'any', *args, **kwargs): ...
Initialization method. :param hf_clip: clip model name on huggingface to compute the similarity between image and text. :param min_score: The min similarity to keep samples. :param max_score: The max similarity to keep samples. :param any_or_all: keep this sample wi...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/image_pair_similarity_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/image_pair_similarity_filter.py
Apache-2.0
def __init__(self, min_width: int = 1, max_width: int = sys.maxsize, min_height: int = 1, max_height: int = sys.maxsize, any_or_all: str = 'any', *args, **kwargs): """ Initialization me...
Initialization method. :param min_width: The min width to keep samples. :param max_width: The max width to keep samples. :param min_height: The min height to keep samples. :param max_height: The max height to keep samples. :param any_or_all: keep this sample with 'any' ...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/image_shape_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/image_shape_filter.py
Apache-2.0
def __init__(self, hf_blip: str = 'Salesforce/blip-itm-base-coco', trust_remote_code: bool = False, min_score: float = 0.003, max_score: float = 1.0, horizontal_flip: bool = False, vertical_flip: bool = False, ...
Initialization method. :param hf_blip: blip model name on huggingface to compute the matching score between image and text. :param min_score: The min matching score to keep samples. :param max_score: The max matching score to keep samples. :param horizontal_flip: Fl...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/image_text_matching_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/image_text_matching_filter.py
Apache-2.0
def __init__(self, hf_clip: str = 'openai/clip-vit-base-patch32', trust_remote_code: bool = False, min_score: float = 0.1, max_score: float = 1.0, horizontal_flip: bool = False, vertical_flip: bool = False, ...
Initialization method. :param hf_clip: clip model name on huggingface to compute the similarity between image and text. :param min_score: The min similarity to keep samples. :param max_score: The max similarity to keep samples. :param horizontal_flip: Flip image hor...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/image_text_similarity_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/image_text_similarity_filter.py
Apache-2.0
def __init__(self, hf_watermark_model: str = 'amrul-hzz/watermark_detector', trust_remote_code: bool = False, prob_threshold: float = 0.8, any_or_all: str = 'any', *args, **kwargs): """ Initialization m...
Initialization method. :param hf_watermark_model: watermark detection model name on huggingface. :param prob_threshold: the predicted watermark probability threshold for samples. range from 0 to 1. Samples with watermark probability less than this threshold ...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/image_watermark_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/image_watermark_filter.py
Apache-2.0
def __init__(self, lang: Union[str, List[str]] = '', min_score: float = 0.8, *args, **kwargs): """ Initialization method. :param lang: Samples in which languages to keep. :param min_score: The min language identificatio...
Initialization method. :param lang: Samples in which languages to keep. :param min_score: The min language identification confidence scores of samples to keep. :param args: extra args :param kwargs: extra args
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/language_id_score_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/language_id_score_filter.py
Apache-2.0
def __init__(self, api_or_hf_model: str = 'gpt-4o', min_score: float = 0.5, is_hf_model: bool = False, *, api_endpoint: Optional[str] = None, response_path: Optional[str] = None, input_keys: List[str] ...
Initialization method. :param api_or_hf_model: API or huggingface model name. :param min_score: The lowest difficulty score threshold to keep the sample. :param api_endpoint: URL endpoint for the API. :param response_path: Path to extract content from the API respon...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/llm_difficulty_score_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/llm_difficulty_score_filter.py
Apache-2.0
def __init__(self, api_or_hf_model: str = 'gpt-4o', min_score: float = 0.5, is_hf_model: bool = False, *, api_endpoint: Optional[str] = None, response_path: Optional[str] = None, input_keys: List[str] ...
Initialization method. :param api_or_hf_model: API or huggingface model name. :param min_score: The lowest quality score threshold to keep the sample. :param api_endpoint: URL endpoint for the API. :param response_path: Path to extract content from the API response....
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/llm_quality_score_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/llm_quality_score_filter.py
Apache-2.0
def __init__(self, min_len: int = 10, max_len: int = sys.maxsize, *args, **kwargs): """ Initialization method. :param min_len: The min filter length in this op, samples will be filtered if their maximum line length ...
Initialization method. :param min_len: The min filter length in this op, samples will be filtered if their maximum line length is below this parameter. :param max_len: The max filter length in this op, samples will be filtered if their maximum line length ex...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/maximum_line_length_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/maximum_line_length_filter.py
Apache-2.0
def __init__(self, lang: str = 'en', max_ppl: float = 1500, *args, **kwargs): """ Initialization method. :param lang: Compute perplexity for samples in which language. :param max_ppl: The max filter perplexity in this o...
Initialization method. :param lang: Compute perplexity for samples in which language. :param max_ppl: The max filter perplexity in this op, samples will be filtered if their perplexity exceeds this parameter. :param args: extra args :param kwargs: extra args ...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/perplexity_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/perplexity_filter.py
Apache-2.0
def __init__(self, hf_owlvit: str = 'google/owlvit-base-patch32', trust_remote_code: bool = False, min_recall: float = 0.1, max_recall: float = 1.0, horizontal_flip: bool = False, vertical_flip: bool = False, ...
Initialization method. :param hf_owlvit: Owl-ViT model name on huggingface to locate the phrases extracted from the text. :param min_recall: The min phrase grounding recall to keep samples. :param max_recall: The max phrase grounding recall to keep samples. :param h...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/phrase_grounding_recall_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/phrase_grounding_recall_filter.py
Apache-2.0
def __init__(self, min_ratio: float = 0.0, max_ratio: float = 0.25, *args, **kwargs): """ Initialization method. :param min_ratio: The min filter ratio in this op, samples will be filtered if their special-char rati...
Initialization method. :param min_ratio: The min filter ratio in this op, samples will be filtered if their special-char ratio is below this parameter. :param max_ratio: The max filter ratio in this op, samples will be filtered if their special-char ratio ex...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/special_characters_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/special_characters_filter.py
Apache-2.0
def __init__(self, field_key: str = '', target_value: List = [], *args, **kwargs): """ Initialization method. :param field_key: Filter based on the specified value corresponding to the target key. The target key ...
Initialization method. :param field_key: Filter based on the specified value corresponding to the target key. The target key corresponding to multi-level field information need to be separated by '.'. :param target_value: The range of specified field informa...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/specified_field_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/specified_field_filter.py
Apache-2.0
def __init__(self, field_key: str = '', min_value: float = -sys.maxsize, max_value: float = sys.maxsize, *args, **kwargs): """ Initialization method. :param field_key: Filter based on the specified numeric valu...
Initialization method. :param field_key: Filter based on the specified numeric value corresponding to the target key. The target key corresponding to multi-level field information need to be separated by '.'. :param min_value: The min filter value in Specifi...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/specified_numeric_field_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/specified_numeric_field_filter.py
Apache-2.0
def __init__(self, lang: str = 'en', tokenization: bool = False, min_ratio: float = 0.3, stopwords_dir: str = ASSET_DIR, use_words_aug: bool = False, words_aug_group_sizes: List[PositiveInt] = [2], wor...
Initialization method. :param lang: Consider stopwords in what language. If lang == "all", we will adopt the one merged from all the available languages :param tokenization: whether to use model to tokenize documents :param min_ratio: The min filter ratio in thi...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/stopwords_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/stopwords_filter.py
Apache-2.0
def __init__(self, suffixes: Union[str, List[str]] = [], *args, **kwargs): """ Initialization method. :param suffixes: the suffix of text that will be keep. For example: '.txt', 'txt' or ['txt', '.pdf', 'docx'] :param args: extra args :param kwargs: extra args ...
Initialization method. :param suffixes: the suffix of text that will be keep. For example: '.txt', 'txt' or ['txt', '.pdf', 'docx'] :param args: extra args :param kwargs: extra args
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/suffix_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/suffix_filter.py
Apache-2.0
def __init__(self, lang: str = 'en', min_action_num: int = 1, *args, **kwargs): """ Initialization method. :param lang: language of the text in the samples. 'en' for detection of actions in English and 'zh' for dete...
Initialization method. :param lang: language of the text in the samples. 'en' for detection of actions in English and 'zh' for detection of actions in Chinese. :param mini_action_num: The min action number in the filtering. samples will be filtered if their action numbe...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/text_action_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/text_action_filter.py
Apache-2.0
def __init__(self, lang: str = 'en', min_dependency_num: int = 1, any_or_all: str = 'all', *args, **kwargs): """ Initialization method. :param lang: language of the text in the samples. 'en' for detection of ...
Initialization method. :param lang: language of the text in the samples. 'en' for detection of entities in English and 'zh' for detection of entities in Chinese. :param mini_dependency_num: The min token number in the filtering. Objects is independent if their number of...
__init__
python
modelscope/data-juicer
data_juicer/ops/filter/text_entity_dependency_filter.py
https://github.com/modelscope/data-juicer/blob/master/data_juicer/ops/filter/text_entity_dependency_filter.py
Apache-2.0