textflint.generation_layer.transformation.CWS.swap_name¶
- Make the first word of the surname and the preceding word form a word,
and the last word of the name and the following word form a word
-
class
textflint.generation_layer.transformation.CWS.swap_name.SwapName(**kwargs)[source]¶ Bases:
textflint.generation_layer.transformation.transformation.Transformation- Make the first word of the surname and the preceding word form a word,
and the last word of the name and the following word form a word
Example:
我朝小明走了过去 -> 我朝向明走了过去
-
class
textflint.generation_layer.transformation.CWS.swap_name.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.CWS.swap_name.descartes(calculation_items, n)[source]¶ - Parameters
calculation_items (list) –
n (int) – quantity to select
- Return list
list items which we random choice from Cartesian product.
-
textflint.generation_layer.transformation.CWS.swap_name.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