textflint.generation_layer.transformation.SA.add_sum

Add summaries according to the person or movies in the sentence from csv file

class textflint.generation_layer.transformation.SA.add_sum.AddSum(entity_type='person', **kwargs)[source]

Bases: textflint.generation_layer.transformation.transformation.Transformation

Transforms an input by adding summaries of person and movies provided by csv.

Example:

ori: Titanic is my favorite movie.
trans: Titanic(A seventeen-year-old aristocrat falls in love with a
kind but poor artist aboard the
       luxurious,ill-fated R.M.S. Titanic.) is my favorite movie.
__init__(entity_type='person', **kwargs)[source]

init AddEntitySummary Class

Parameters

entity_type (string) – add summary for which entity type

class textflint.generation_layer.transformation.SA.add_sum.Transformation(**kwargs)[source]

Bases: abc.ABC

An abstract class for transforming a sequence of text to produce a list of potential adversarial example.

processor = <textflint.common.preprocess.en_processor.EnProcessor object>
transform(sample, n=1, field='x', **kwargs)[source]

Transform data sample to a list of Sample.

Parameters
  • sample (Sample) – Data sample for augmentation.

  • n (int) – Max number of unique augmented output, default is 5.

  • field (str|list) – Indicate which fields to apply transformations.

  • **kwargs (dict) –

    other auxiliary params.

Returns

list of Sample

classmethod sample_num(x, num)[source]

Get ‘num’ samples from x.

Parameters
  • x (list) – list to sample

  • num (int) – sample number

Returns

max ‘num’ unique samples.

textflint.generation_layer.transformation.SA.add_sum.download_if_needed(folder_name)[source]

Folder name will be saved as .cache/textflint/[folder_name]. If it doesn’t exist on disk, the zip file will be downloaded and extracted.

Parameters

folder_name (str) – path to folder or file in cache

Returns

path to the downloaded folder or file on disk