Table of Contents

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

T

The numeric type for calculations.

Inheritance
RandomSwap<T>
Implements
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

numSwaps int

Number of swap operations to perform (default: 2).

probability double

Probability of applying this augmentation (default: 0.2).

languageCode string

Language code for language-specific operations.

Properties

NumSwaps

Gets the number of word swaps to perform.

public int NumSwaps { get; }

Property Value

int

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

data string[]

The input data.

context AugmentationContext<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.