Class RandomSwap<T>
- Namespace
- AiDotNet.Augmentation.Text
- Assembly
- AiDotNet.dll
Randomly swaps the positions of words in text.
public class RandomSwap<T> : TextAugmenterBase<T>, IAugmentation<T, string[]>
Type Parameters
TThe numeric type for calculations.
- Inheritance
-
AugmentationBase<T, string[]>RandomSwap<T>
- Implements
-
IAugmentation<T, string[]>
- Inherited Members
Remarks
For Beginners: Random swap changes word order, like swapping "the big dog" to "big the dog". This helps models become less sensitive to exact word ordering.
When to use:
- Sentiment analysis (where word presence matters more than order)
- Topic classification
- Tasks where word order is somewhat flexible
When NOT to use:
- Tasks where word order is critical (machine translation, grammar checking)
- Named entity recognition
Constructors
RandomSwap(int, double, string)
Creates a new random swap augmentation.
public RandomSwap(int numSwaps = 2, double probability = 0.2, string languageCode = "en")
Parameters
numSwapsintNumber of swap operations to perform (default: 2).
probabilitydoubleProbability of applying this augmentation (default: 0.2).
languageCodestringLanguage code for language-specific operations.
Properties
NumSwaps
Gets the number of word swaps to perform.
public int NumSwaps { get; }
Property Value
Remarks
Default: 2
Methods
ApplyAugmentation(string[], AugmentationContext<T>)
Implement this method to perform the actual augmentation.
protected override string[] ApplyAugmentation(string[] data, AugmentationContext<T> context)
Parameters
datastring[]The input data.
contextAugmentationContext<T>The augmentation context.
Returns
- string[]
The augmented data.
GetParameters()
Gets the parameters of this augmentation.
public override IDictionary<string, object> GetParameters()
Returns
- IDictionary<string, object>
A dictionary of parameter names to values.