Skip to main content
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

  1. Zero-sample categories: Some categories have no training examples
  2. Weak classifiers: Categories with 1-2 examples produce unreliable predictions
  3. Overfitting to majority: Model learns to always predict common categories
  4. 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’s balanced 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
Limitation: Class weighting helps when you have at least a few examples per category. It cannot help with categories that have zero training examples.

2. Sample Augmentation

Use the min_examples_per_category parameter to guarantee minimum representation:
When enabled, Delve will:
  1. After initial LLM labeling, check category distribution
  2. For underrepresented categories, use embedding similarity to find likely candidates from the unlabeled pool
  3. Label those candidates with the LLM
  4. Add confirmed matches to the training set
Set min_examples_per_category to 3-5 for most use cases. Higher values improve classifier accuracy but increase LLM costs.

3. Confidence-Based Handling

Use classifier_confidence_threshold to catch uncertain predictions:
When the classifier’s confidence for a document is below the threshold, Delve handles it according to low_confidence_action:
The default "other" action is recommended for most use cases. It’s honest about uncertainty (the classifier truly doesn’t know) and avoids expensive LLM calls.
Safeguard for "llm" action: If more than 20 documents need re-labeling, Delve automatically falls back to "other" to prevent excessive LLM costs. For large datasets with significant imbalance, use min_examples_per_category instead.

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
Recommendations:

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

Don’t try to infer “Other” from classifier confidence. Always include an “Other” category in your taxonomy if you expect some documents won’t fit your defined categories.

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:
The LLM learns what truly doesn’t fit during the labeling phase, which is far more accurate than guessing from classifier confidence.

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)
A large gap between weighted and macro F1 is a sign of class imbalance. The weighted score is dominated by majority classes, hiding poor performance on rare categories. Use per_class_f1 to identify which specific categories are struggling.

Next Steps

Configuration Guide

Full parameter reference

How It Works

Understand the pipeline