Class ActiveLearningSampler<T>
A sampler for active learning that selects the most informative samples for labeling.
public class ActiveLearningSampler<T> : DataSamplerBase, IDataSampler
Type Parameters
TThe numeric type for uncertainty scores.
- Inheritance
-
ActiveLearningSampler<T>
- Implements
- Inherited Members
Remarks
ActiveLearningSampler implements uncertainty sampling and other active learning strategies to select unlabeled samples that would be most valuable to label.
For Beginners: In active learning, you don't have labels for all data. This sampler helps you decide which unlabeled samples to ask an expert to label:
- Uncertainty sampling: Ask about samples the model is unsure about
- Diversity sampling: Ask about samples that are different from what you've seen
- Expected model change: Ask about samples that would change the model most
This can dramatically reduce labeling costs (50-90% less labels needed)!
Constructors
ActiveLearningSampler(int, ActiveLearningStrategy, double, int?)
Initializes a new instance of the ActiveLearningSampler class.
public ActiveLearningSampler(int datasetSize, ActiveLearningStrategy strategy = ActiveLearningStrategy.Uncertainty, double diversityWeight = 0.3, int? seed = null)
Parameters
datasetSizeintThe total number of samples.
strategyActiveLearningStrategyThe active learning selection strategy.
diversityWeightdoubleWeight for diversity in hybrid strategy (0-1).
seedint?Optional random seed for reproducibility.
Fields
NumOps
Numeric operations for type T.
protected static readonly INumericOperations<T> NumOps
Field Value
- INumericOperations<T>
Properties
LabeledCount
Gets the number of labeled samples.
public int LabeledCount { get; }
Property Value
Length
Gets the total number of samples this sampler will produce per epoch.
public override int Length { get; }
Property Value
Remarks
This may differ from the dataset size for oversampling or undersampling strategies.
UnlabeledCount
Gets the number of unlabeled samples.
public int UnlabeledCount { get; }
Property Value
Methods
GetIndicesCore()
Core implementation for generating indices. Override this in derived classes.
protected override IEnumerable<int> GetIndicesCore()
Returns
- IEnumerable<int>
An enumerable of sample indices.
MarkAsLabeled(IEnumerable<int>)
Marks multiple samples as labeled.
public void MarkAsLabeled(IEnumerable<int> indices)
Parameters
indicesIEnumerable<int>The sample indices.
MarkAsLabeled(int)
Marks a sample as labeled.
public void MarkAsLabeled(int index)
Parameters
indexintThe sample index.
SelectForLabeling(int)
Selects the most informative unlabeled samples for labeling.
public IEnumerable<int> SelectForLabeling(int numToSelect)
Parameters
numToSelectintNumber of samples to select.
Returns
- IEnumerable<int>
Indices of selected samples.
UpdateUncertainties(IReadOnlyList<int>, IReadOnlyList<T>)
Batch updates uncertainty scores.
public void UpdateUncertainties(IReadOnlyList<int> indices, IReadOnlyList<T> uncertainties)
Parameters
indicesIReadOnlyList<int>The sample indices.
uncertaintiesIReadOnlyList<T>The uncertainty scores.
UpdateUncertainty(int, T)
Updates the uncertainty score for a sample.
public void UpdateUncertainty(int index, T uncertainty)
Parameters
indexintThe sample index.
uncertaintyTThe uncertainty score (higher = more uncertain).