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
TThe numeric type for calculations.
- Inheritance
-
AugmentationBase<T, string[]>SynonymReplacement<T>
- Implements
-
IAugmentation<T, string[]>
- 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
replacementFractiondoubleFraction of words to replace (default: 0.1).
probabilitydoubleProbability of applying this augmentation (default: 0.3).
languageCodestringLanguage 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
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
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.