Table of Contents

Class SynonymReplacement<T>

Namespace
AiDotNet.Augmentation.Text
Assembly
AiDotNet.dll

Replaces random words with their synonyms.

public class SynonymReplacement<T> : TextAugmenterBase<T>, IAugmentation<T, string[]>

Type Parameters

T

The numeric type for calculations.

Inheritance
SynonymReplacement<T>
Implements
Inherited Members

Remarks

For Beginners: Synonym replacement swaps words with similar-meaning words. For example, "happy" might become "joyful" or "glad". This helps models understand that different words can have the same meaning.

When to use:

  • Text classification tasks
  • Sentiment analysis
  • When training data has limited vocabulary variation

Constructors

SynonymReplacement(double, double, string)

Creates a new synonym replacement augmentation.

public SynonymReplacement(double replacementFraction = 0.1, double probability = 0.3, string languageCode = "en")

Parameters

replacementFraction double

Fraction of words to replace (default: 0.1).

probability double

Probability of applying this augmentation (default: 0.3).

languageCode string

Language code for language-specific operations.

Properties

CustomSynonyms

Gets or sets the custom synonym dictionary.

public Dictionary<string, string[]>? CustomSynonyms { get; set; }

Property Value

Dictionary<string, string[]>

Remarks

If null, uses the default English synonyms.

ReplacementFraction

Gets the fraction of words to replace.

public double ReplacementFraction { get; }

Property Value

double

Remarks

Default: 0.1 (10% of words)

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.