textflint.input_layer.config.config

textflint Config Class

class textflint.input_layer.config.config.Config(task='UT', out_dir=None, max_trans=1, random_seed=1, fields=None, flint_model=None, trans_methods=None, trans_config=None, return_unk=True, sub_methods=None, sub_config=None, attack_methods=None, validate_methods=None, **kwargs)[source]

Bases: object

Hold some config params to control generation and report procedure.

__init__(task='UT', out_dir=None, max_trans=1, random_seed=1, fields=None, flint_model=None, trans_methods=None, trans_config=None, return_unk=True, sub_methods=None, sub_config=None, attack_methods=None, validate_methods=None, **kwargs)[source]
Parameters
  • task (str) – task name

  • out_dir (string) – out dir for saving generated samples, default current path.

  • max_trans (int) – maximum transformed samples generate by one original sample pre Transformation.

  • random_seed (int) – random number seed to reproduce generation.

  • fields (str|list[str]) – fields on which new samples are generated.

::param str model_file: path to the python file containing

the FlintModel instance which named ‘model’.

Parameters
  • trans_methods (list) – indicate what transformations to apply to dataset.

  • trans_config (dict) – parameters for the initialization of the transformation instances.

  • return_unk (bool) – whether apply transformations which may influence label of sample.

  • sub_methods (list) – indicate what subpopulations to apply to dataset.

  • sub_config (dict) – parameters for the initialization of the subpopulation instances.

  • attack_methods (str) – path to the python file containing the Attack instances which named “attacks”.

  • validate_methods (str|list[str]) – indicate use which validate methods to calculate confidence of generated samples.

check_config()[source]

Check common config params.

get_generate_methods(methods, task_to_methods, allow_pipeline=False)[source]

Validate transformation or subpopulation methods.

Watch out! Some UT transformations/subpopulations may not compatible with your task, please choose your method carefully.

Parameters
  • methods (list) – transformation or subpopulation need to apply to dataset. If not provide, return default generated methods.

  • task_to_methods (dict) – map allowed methods by task name.

  • allow_pipeline (bool) – whether allow pipeline input

Returns

list of transformation/subpopulation.

classmethod from_dict(json_object)[source]

Constructs a Config from a Python dictionary of parameters.

classmethod from_json_file(json_file)[source]

Constructs a Config from a json file of parameters.

to_dict()[source]

Serializes this instance to a Python dictionary.

to_json_string()[source]

Serializes this instance to a JSON string.

to_json_file(json_file)[source]

Serializes this instance to a JSON file.