textflint.generation_layer.transformation.UT.word_case

Word case transformation class

class textflint.generation_layer.transformation.UT.word_case.WordCase(case_type='upper', **kwargs)[source]

Bases: textflint.generation_layer.transformation.transformation.Transformation

Transforms an input to upper and lower case or capitalize case. A sentence can only be transformed into one sentence of each case at most.

__init__(case_type='upper', **kwargs)[source]
Parameters

case_type – case type, only support [‘upper’, ‘lower’, ‘title’, ‘random’]

class textflint.generation_layer.transformation.UT.word_case.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.