textflint.generation_layer.transformation.CWS.cn_swap_num

Make short numbers grow into long numbers.

class textflint.generation_layer.transformation.CWS.cn_swap_num.CnSwapNum(**kwargs)[source]

Bases: textflint.generation_layer.transformation.transformation.Transformation

Make short numbers grow into long numbers.

Example:

九百 -> 八百九十九
__init__(**kwargs)[source]
Parameters
  • num_list (list) – the list which include all the number we need if you want to change it you must change NUM_LIST, NUM_FLAG1, NUM_FLAG2, NUM_BEGIN, NUM_END

  • **kwargs

create_num(pos)[source]

create chinese number

Parameters

pos (int) – the max length of number

Returns

the new number

number_change(sentence, label, start, end)[source]

Digital conversion of start to end

Parameters
  • sentence (str) – the sentence to be changed

  • label (list) – the tag of CWS

  • start (int) – the start pos of the sentence

  • end (int) – the end pos of the sentence

Return str

the new number

Return list

the label of new number

compare(num1, num2)[source]

compare two number

Parameters
  • num1 (str) – the first number to be compared

  • num2 (str) – the second number to be compared

class textflint.generation_layer.transformation.CWS.cn_swap_num.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.