textflint.generation_layer.transformation.COREF.random_insert¶
- Coref - Rnd Insert: some irrelevance sentences will be inserted
into original sentences. These sentences include no corefs.
-
class
textflint.generation_layer.transformation.COREF.random_insert.RndInsert(trans_p=0.2, **kwargs)[source]¶ Bases:
textflint.generation_layer.transformation.transformation.Transformation- RndInsert: trans_p * num_sentences of irrelevance sentences are
sampled from samples_other, and they will be inserted into original sentences in sample. These inserted sentences include no corefs.
- Attributes:
trans_p: proportion of inserted 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'], ['who', 'is', 'this', 'boy'], ['I', 'conquered'], ['Anna', 'bel', 'wanna', 'sleep'], ['Anna', 'bel', 'is', 'happy']], 'clusters': [ [[1, 1], [3, 3], [9, 9]], [[11, 12], [17, 18]]]}
-
class
textflint.generation_layer.transformation.COREF.random_insert.Transformation(**kwargs)[source]¶ Bases:
abc.ABCAn 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
-
-
textflint.generation_layer.transformation.COREF.random_insert.ceil(x, /)¶ Return the ceiling of x as an Integral.
This is the smallest integer >= x.