data_juicer.analysis package

Submodules

data_juicer.analysis.collector module

class data_juicer.analysis.collector.TextTokenDistCollector(tokenizer)[源代码]

基类:object

Tokenize and collect distribution of tokens for given dataset with a specified tokenizer.

__init__(tokenizer)[源代码]

Initialization method.

参数:

tokenizer -- tokenizer name on huggingface

collect(data_path, text_key, num_proc=1) Categorical[源代码]

Tokenize and collect tokens distribution of input dataset :param data_path: path to input dataset. :param text_key: field keys that will be considered into token counts. :param num_proc: number of processes to count tokens. :return: token distribution.

data_juicer.analysis.column_wise_analysis module

data_juicer.analysis.column_wise_analysis.get_row_col(total_num, factor=2)[源代码]

Given the total number of stats figures, get the "best" number of rows and columns. This function is needed when we need to store all stats figures into one image.

参数:
  • total_num -- Total number of stats figures

  • factor -- Number of sub-figure types in each figure. In default, it's 2, which means there are histogram and box plot for each stat figure

返回:

"best" number of rows and columns, and the grid list

class data_juicer.analysis.column_wise_analysis.ColumnWiseAnalysis(dataset, output_path, overall_result=None, save_stats_in_one_file=True)[源代码]

基类:object

Apply analysis on each column of stats respectively.

__init__(dataset, output_path, overall_result=None, save_stats_in_one_file=True)[源代码]

Initialization method

参数:
  • dataset -- the dataset to be analyzed

  • output_path -- path to store the analysis results

  • overall_result -- optional precomputed overall stats result

  • save_stats_in_one_file -- whether save all analysis figures of all stats into one image file

analyze(show_percentiles=False, show=False, skip_export=False)[源代码]

Apply analysis and draw the analysis figure for stats.

参数:
  • show_percentiles -- whether to show the percentile line in each sub-figure. If it's true, there will be several red lines to indicate the quantiles of the stats distributions

  • show -- whether to show in a single window after drawing

  • skip_export -- whether save the results into disk

返回:

draw_hist(ax, data, save_path, percentiles=None, show=False)[源代码]

Draw the histogram for the data.

参数:
  • ax -- the axes to draw

  • data -- data to draw

  • save_path -- the path to save the histogram figure

  • percentiles -- the overall analysis result of the data including percentile information

  • show -- whether to show in a single window after drawing

返回:

draw_box(ax, data, save_path, percentiles=None, show=False)[源代码]

Draw the box plot for the data.

参数:
  • ax -- the axes to draw

  • data -- data to draw

  • save_path -- the path to save the box figure

  • percentiles -- the overall analysis result of the data including percentile information

  • show -- whether to show in a single window after drawing

返回:

draw_wordcloud(ax, data, save_path, show=False)[源代码]

data_juicer.analysis.diversity_analysis module

data_juicer.analysis.diversity_analysis.find_root_verb_and_its_dobj(tree_root)[源代码]

Find the verb and its object closest to the root.

参数:

tree_root -- the root of lexical tree

返回:

valid verb and its object.

data_juicer.analysis.diversity_analysis.find_root_verb_and_its_dobj_in_string(nlp, s, first_sent=True)[源代码]

Find the verb and its object closest to the root of lexical tree of input string.

参数:
  • nlp -- the diversity model to analyze the diversity strings

  • s -- the string to be analyzed

  • first_sent -- whether to analyze the first sentence in the input string only. If it's true, return the analysis result of the first sentence no matter it's valid or not. If it's false, return the first valid result over all sentences

返回:

valid verb and its object of this string

data_juicer.analysis.diversity_analysis.get_diversity(dataset, top_k_verbs=20, top_k_nouns=4, **kwargs)[源代码]

Given the lexical tree analysis result, return the diversity results.

参数:
  • dataset -- lexical tree analysis result

  • top_k_verbs -- only keep the top_k_verbs largest verb groups

  • top_k_nouns -- only keep the top_k_nouns largest noun groups for each verb group

  • kwargs -- extra args

返回:

the diversity results

class data_juicer.analysis.diversity_analysis.DiversityAnalysis(dataset, output_path, lang_or_model='en')[源代码]

基类:object

Apply diversity analysis for each sample and get an overall analysis result.

__init__(dataset, output_path, lang_or_model='en')[源代码]

Initialization method :param dataset: the dataset to be analyzed :param output_path: path to store the analysis results :param lang_or_model: the diversity model or a specific language used to load the diversity model.

compute(lang_or_model=None, column_name='text')[源代码]

Apply lexical tree analysis on each sample.

参数:
  • lang_or_model -- the diversity model or a specific language used to load the diversity model

  • column_name -- the name of column to be analyzed

返回:

the analysis result.

analyze(lang_or_model=None, column_name='text', postproc_func=<function get_diversity>, **postproc_kwarg)[源代码]

Apply diversity analysis on the whole dataset.

参数:
  • lang_or_model -- the diversity model or a specific language used to load the diversity model

  • column_name -- the name of column to be analyzed

  • postproc_func -- function to analyze diversity. In default, it's function get_diversity

  • postproc_kwarg -- arguments of the postproc_func

返回:

data_juicer.analysis.draw module

data_juicer.analysis.draw.draw_heatmap(data, xlabels, ylabels='auto', figsize=None, triangle=False, show=False)[源代码]

Draw heatmap of input data with special labels.

参数:
  • data -- input data, now support [list, tuple, numpy array, 'torch tensor']

  • xlabels -- x axis labels.

  • ylabels -- y axis labels, if None, use xlabels.

  • figsize -- figure size.

  • triangle -- only display triangle.

返回:

a plot figure.

data_juicer.analysis.measure module

class data_juicer.analysis.measure.Measure[源代码]

基类:object

Base class for Measure distribution.

name = 'base'
measure(*args, **kwargs)[源代码]
class data_juicer.analysis.measure.KLDivMeasure[源代码]

基类:Measure

Measure Kullback-Leibler divergence.

name = 'kl_divergence'
measure(p, q)[源代码]
class data_juicer.analysis.measure.JSDivMeasure[源代码]

基类:Measure

Measure Jensen-Shannon divergence.

name = 'js_divergence'
measure(p, q)[源代码]
class data_juicer.analysis.measure.CrossEntropyMeasure[源代码]

基类:Measure

Measure Cross-Entropy.

name = 'cross_entropy'
measure(p, q)[源代码]
class data_juicer.analysis.measure.EntropyMeasure[源代码]

基类:Measure

Measure Entropy.

name = 'entropy'
measure(p)[源代码]
class data_juicer.analysis.measure.RelatedTTestMeasure[源代码]

基类:Measure

Measure T-Test for two related distributions on their histogram of the same bins.

Ref: https://en.wikipedia.org/wiki/Student%27s_t-test

For continuous features or distributions, the input could be dataset stats list. For discrete features or distributions, the input could be the tags or the categories list.

name = 't-test'
static stats_to_hist(p, q)[源代码]
static category_to_hist(p, q)[源代码]
measure(p, q)[源代码]
参数:
  • p -- the first feature or distribution. (stats/tags/categories)

  • q -- the second feature or distribution. (stats/tags/categories)

返回:

the T-Test results object -- ([ref](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats._result_classes.TtestResult.html#scipy.stats._result_classes.TtestResult)) # noqa: E501

data_juicer.analysis.overall_analysis module

class data_juicer.analysis.overall_analysis.OverallAnalysis(dataset, output_path)[源代码]

基类:object

Apply analysis on the overall stats, including mean, std, quantiles, etc.

__init__(dataset, output_path)[源代码]

Initialization method.

参数:
  • dataset -- the dataset to be analyzed

  • output_path -- path to store the analysis results.

refine_single_column(col)[源代码]
analyze(percentiles=[], num_proc=1, skip_export=False)[源代码]

Apply overall analysis on the whole dataset based on the describe method of pandas.

参数:
  • percentiles -- percentiles to analyze

  • num_proc -- number of processes to analyze the dataset

  • skip_export -- whether export the results to disk

返回:

the overall analysis result.

Module contents

class data_juicer.analysis.ColumnWiseAnalysis(dataset, output_path, overall_result=None, save_stats_in_one_file=True)[源代码]

基类:object

Apply analysis on each column of stats respectively.

__init__(dataset, output_path, overall_result=None, save_stats_in_one_file=True)[源代码]

Initialization method

参数:
  • dataset -- the dataset to be analyzed

  • output_path -- path to store the analysis results

  • overall_result -- optional precomputed overall stats result

  • save_stats_in_one_file -- whether save all analysis figures of all stats into one image file

analyze(show_percentiles=False, show=False, skip_export=False)[源代码]

Apply analysis and draw the analysis figure for stats.

参数:
  • show_percentiles -- whether to show the percentile line in each sub-figure. If it's true, there will be several red lines to indicate the quantiles of the stats distributions

  • show -- whether to show in a single window after drawing

  • skip_export -- whether save the results into disk

返回:

draw_hist(ax, data, save_path, percentiles=None, show=False)[源代码]

Draw the histogram for the data.

参数:
  • ax -- the axes to draw

  • data -- data to draw

  • save_path -- the path to save the histogram figure

  • percentiles -- the overall analysis result of the data including percentile information

  • show -- whether to show in a single window after drawing

返回:

draw_box(ax, data, save_path, percentiles=None, show=False)[源代码]

Draw the box plot for the data.

参数:
  • ax -- the axes to draw

  • data -- data to draw

  • save_path -- the path to save the box figure

  • percentiles -- the overall analysis result of the data including percentile information

  • show -- whether to show in a single window after drawing

返回:

draw_wordcloud(ax, data, save_path, show=False)[源代码]
class data_juicer.analysis.DiversityAnalysis(dataset, output_path, lang_or_model='en')[源代码]

基类:object

Apply diversity analysis for each sample and get an overall analysis result.

__init__(dataset, output_path, lang_or_model='en')[源代码]

Initialization method :param dataset: the dataset to be analyzed :param output_path: path to store the analysis results :param lang_or_model: the diversity model or a specific language used to load the diversity model.

compute(lang_or_model=None, column_name='text')[源代码]

Apply lexical tree analysis on each sample.

参数:
  • lang_or_model -- the diversity model or a specific language used to load the diversity model

  • column_name -- the name of column to be analyzed

返回:

the analysis result.

analyze(lang_or_model=None, column_name='text', postproc_func=<function get_diversity>, **postproc_kwarg)[源代码]

Apply diversity analysis on the whole dataset.

参数:
  • lang_or_model -- the diversity model or a specific language used to load the diversity model

  • column_name -- the name of column to be analyzed

  • postproc_func -- function to analyze diversity. In default, it's function get_diversity

  • postproc_kwarg -- arguments of the postproc_func

返回:

class data_juicer.analysis.OverallAnalysis(dataset, output_path)[源代码]

基类:object

Apply analysis on the overall stats, including mean, std, quantiles, etc.

__init__(dataset, output_path)[源代码]

Initialization method.

参数:
  • dataset -- the dataset to be analyzed

  • output_path -- path to store the analysis results.

refine_single_column(col)[源代码]
analyze(percentiles=[], num_proc=1, skip_export=False)[源代码]

Apply overall analysis on the whole dataset based on the describe method of pandas.

参数:
  • percentiles -- percentiles to analyze

  • num_proc -- number of processes to analyze the dataset

  • skip_export -- whether export the results to disk

返回:

the overall analysis result.