MCPcopy
hub / github.com/QData/TextAttack / CharSwapAugmenter

Class CharSwapAugmenter

textattack/augmentation/recipes.py:131–155  ·  view source on GitHub ↗

Augments words by swapping characters out for other characters.

Source from the content-addressed store, hash-verified

129
130
131class CharSwapAugmenter(Augmenter):
132 """Augments words by swapping characters out for other characters."""
133
134 def __init__(self, **kwargs):
135 from textattack.transformations import (
136 CompositeTransformation,
137 WordSwapNeighboringCharacterSwap,
138 WordSwapRandomCharacterDeletion,
139 WordSwapRandomCharacterInsertion,
140 WordSwapRandomCharacterSubstitution,
141 )
142
143 transformation = CompositeTransformation(
144 [
145 # (1) Swap: Swap two adjacent letters in the word.
146 WordSwapNeighboringCharacterSwap(),
147 # (2) Substitution: Substitute a letter in the word with a random letter.
148 WordSwapRandomCharacterSubstitution(),
149 # (3) Deletion: Delete a random letter from the word.
150 WordSwapRandomCharacterDeletion(),
151 # (4) Insertion: Insert a random letter in the word.
152 WordSwapRandomCharacterInsertion(),
153 ]
154 )
155 super().__init__(transformation, constraints=DEFAULT_CONSTRAINTS, **kwargs)
156
157
158class CheckListAugmenter(Augmenter):

Callers 1

test_charwap_augmenterFunction · 0.90

Calls

no outgoing calls

Tested by 1

test_charwap_augmenterFunction · 0.72