augmentTrainingSamples function exported ✓ 100.0%

Last updated: 2026-02-24T21:07:57.551Z

Metrics

LOC: 34 Complexity: 5 Params: 2 Coverage: 100.0% (11/11 lines, 6x executed)

Signature

augmentTrainingSamples( config: AugmentationConfig = DEFAULT_AUGMENTATION, ): : TrainingSample[]

Summary

Generate augmented training samples by applying random transformations. Returns only the new augmented samples (not the originals).

Source Code

export function augmentTrainingSamples(
  config: AugmentationConfig = DEFAULT_AUGMENTATION,
): TrainingSample[] {
  const augmented: TrainingSample[] = [];
  const strategyFns: Record<string, (s: string) => string> = {
    shuffle: augmentShuffle,
    drop: (s: string) => augmentDrop(s, config.dropRate ?? 0.2),
    typo: augmentTypo,
  };

  for (const sample of TRAINING_SAMPLES) {
    for (let i = 0; i < config.multiplier; i++) {
      // Pick a random strategy
      const strategy =
        config.strategies[Math.floor(Math.random() * config.strategies.length)];
      const fn = strategyFns[strategy];
      if (fn) {
        const signalText = flattenStructuredSignals(sample.signals);
        augmented.push({
          signals: fromFlatSignals(fn(signalText)),
          category: sample.category,
          type: sample.type,
          source: "augmented",
          domain: sample.domain,
          difficulty: sample.difficulty,
          language: sample.language,
          domFeatures: sample.domFeatures,
        });
      }
    }
  }

  return augmented;
}

Dependencies (Outgoing)

graph LR augmentTrainingSamples["augmentTrainingSamples"] augmentDrop["augmentDrop"] flattenStructuredSignals["flattenStructuredSignals"] augmentTrainingSamples -->|calls| augmentDrop augmentTrainingSamples -->|calls| flattenStructuredSignals style augmentTrainingSamples fill:#dbeafe,stroke:#2563eb,stroke-width:2px click augmentTrainingSamples "40bb393b12ff4d6e.html" click augmentDrop "fc8dabee39176edb.html" click flattenStructuredSignals "a5d367e2c926f76e.html"
TargetType
augmentDrop calls
flattenStructuredSignals calls

Impact (Incoming)

graph LR augmentTrainingSamples["augmentTrainingSamples"] EvalMisclassified["EvalMisclassified"] FIELD_DICTIONARY["FIELD_DICTIONARY"] EvalMisclassified -->|uses| augmentTrainingSamples FIELD_DICTIONARY -->|uses| augmentTrainingSamples style augmentTrainingSamples fill:#dbeafe,stroke:#2563eb,stroke-width:2px click augmentTrainingSamples "40bb393b12ff4d6e.html" click EvalMisclassified "4e0d00ef54656ad2.html" click FIELD_DICTIONARY "9c3a352ea31b8001.html"
SourceType
EvalMisclassified uses
FIELD_DICTIONARY uses