This guide explains how class imbalance affects taxonomy classification and how to diagnose and address it using Delve’s built-in tools and configuration options.
The Problem
Class imbalance occurs when some categories in your taxonomy have significantly more documents than others. This is extremely common in real-world data:- Support tickets: 80% billing issues, 20% technical problems
- Product reviews: 90% positive, 10% negative
- Document types: 95% standard reports, 5% edge cases
Why Random Sampling Fails
When you use random sampling with imbalanced data, rare categories get underrepresented or completely missed:
With 100 random samples from data with this distribution, Category E would have zero training examples. The classifier simply cannot learn to recognize it.
What Happens Without Intervention
- Zero-sample categories: Some categories have no training examples
- Weak classifiers: Categories with 1-2 examples produce unreliable predictions
- Overfitting to majority: Model learns to always predict common categories
- Poor F1 scores: Test metrics look okay overall but hide per-class failures
How Delve Addresses It
Delve provides three mechanisms to handle class imbalance:1. Built-in: Class-Weighted Training
Delve’s classifier automatically uses class-weighted training via scikit-learn’sbalanced class weights. This means:
- Rare categories get higher weight during training
- Errors on minority classes are penalized more heavily
- The model doesn’t completely ignore rare categories
2. Sample Augmentation
Use themin_examples_per_category parameter to guarantee minimum representation:
- After initial LLM labeling, check category distribution
- For underrepresented categories, use embedding similarity to find likely candidates from the unlabeled pool
- Label those candidates with the LLM
- Add confirmed matches to the training set
3. Confidence-Based Handling
Useclassifier_confidence_threshold to catch uncertain predictions:
low_confidence_action:
Diagnosing Imbalance
Delve provides several diagnostic metrics to help you identify and understand imbalance issues.Understanding the Metrics
sample_distribution
What it is: Count of documents per category in the training sample (LLM-labeled documents).
What to look for: Categories with very low or zero counts.
How to act: If a category has fewer than 3 samples, the classifier will struggle with it.
zero_sample_categories
What it is: List of taxonomy categories with no training examples.
What to look for: Any non-empty list indicates guaranteed blind spots.
How to act: Increase sample_size or enable min_examples_per_category.
per_class_f1
What it is: F1 score for each category on the classifier’s test set.
What to look for: Scores below 0.5, especially 0.0.
How to act: Low F1 for specific categories means the classifier can’t reliably predict them.
Aggregate Classifier Metrics
What it is: Overall train/test accuracy and F1. What to look for: Large gap between training (high) and test (low) metrics.Reading the Warning Signs
Watch for these patterns in your results:Tuning for Your Data
For Predefined Taxonomies
When using a predefined taxonomy, you know your categories in advance. This is actually the harder case for imbalance because:- The taxonomy may include rare categories
- You can’t remove categories that don’t appear in your data
For Discovered Taxonomies
When Delve discovers the taxonomy, it creates categories based on what it sees in your sample. This naturally tends toward balance, but edge cases can still be missed. Recommendations:Cost vs. Accuracy Tradeoffs
Example: Diagnosing and Fixing a Problem
Here’s a complete example showing how to diagnose and address imbalance issues:Best Practice: Keep “Other” in Your Taxonomy
Why This Matters
You might think: “If the classifier is uncertain, the document probably doesn’t fit any category, so label it as Other.” This doesn’t work well in practice. When the classifier has low confidence, it’s usually uncertain between valid categories (e.g., “Planning” vs “General Questions”), not because the document doesn’t fit any category. Real-world test results:The Right Approach
Include “Other” in your taxonomy with a clear description:Understanding F1 Scores: Macro vs Weighted
When evaluating your results, you’ll see two F1 metrics:Why Macro F1 Can Be Low
If you have 15 categories and 5 of them have F1 = 0.0 (the classifier never predicts them correctly), your macro F1 will be dragged down significantly, even if the major categories perform well. Example from real data:- F1 Weighted: 88.8% (great overall performance)
- F1 Macro: 36.0% (several rare categories have F1 = 0)
Next Steps
Configuration Guide
Full parameter reference
How It Works
Understand the pipeline
