textflint.generation_layer.transformation.COREF.random_shuffle

Coref - Rnd shuffle: Randomly shuffle some sentences. At least (1-2*trans_p) sentences would be at the right pos, so don’t worry ==========================================================

class textflint.generation_layer.transformation.COREF.random_shuffle.RndShuffle(trans_p=0.2, **kwargs)[source]

Bases: textflint.generation_layer.transformation.transformation.Transformation

Randomly change the position of trans_p * num_sentences pairs of sentences

Attributes:

trans_p: proportion of deleted sentences; default 0.2 processor: textflint.common.preprocess.TextProcessor.

Example:

ori: {
    'sentences': [
        ['I', 'came'], ['I', 'saw'], ['I', 'conquered'], 
        ['Anna', 'bel', 'wanna', 'sleep'],
        ['Anna', 'bel', 'is', 'happy']],
    'clusters': [
        [[1, 1], [3, 3], [5, 5]], 
        [[7, 8], [11, 12]]]}
trans: {
    'sentences': [
        ['I', 'came'], ['I', 'saw'], ['Anna', 'bel', 'wanna', 'sleep'], 
        ['I', 'conquered'], ['Anna', 'bel', 'is', 'happy']],
    'clusters': [
        [[1, 1], [3, 3], [9, 9]], 
        [[5, 6], [11, 12]]]}
class textflint.generation_layer.transformation.COREF.random_shuffle.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.COREF.random_shuffle.ceil(x, /)

Return the ceiling of x as an Integral.

This is the smallest integer >= x.