|
| 1 | +--- |
| 2 | +title: Confidence Integration |
| 3 | +--- |
| 4 | + |
| 5 | +# Confidence Integration |
| 6 | + |
| 7 | +Stickler supports confidence scores alongside field values to evaluate how well prediction confidence correlates with actual accuracy. |
| 8 | + |
| 9 | +## AUROC for Confidence Calibration: Theoretical Foundation |
| 10 | + |
| 11 | +### What is Confidence Estimation? |
| 12 | + |
| 13 | +Confidence estimation in machine learning refers to a model's ability to assess the reliability of its own predictions. Rather than simply outputting a prediction, a well-calibrated model also provides a confidence score indicating how likely that prediction is to be correct. This is crucial for production systems where understanding prediction uncertainty enables better decision-making, error handling, and human-AI collaboration. |
| 14 | + |
| 15 | +In structured data extraction tasks, confidence estimation allows systems to: |
| 16 | +- Flag uncertain extractions for human review |
| 17 | +- Prioritize high-confidence predictions for automated processing |
| 18 | +- Provide transparency about model reliability to end users |
| 19 | +- Enable adaptive thresholding based on use case requirements |
| 20 | + |
| 21 | +### Research Foundation and Motivation |
| 22 | + |
| 23 | +The choice of AUROC for confidence evaluation is grounded in research on model calibration and confidence assessment. Other approaches to evaluating confidence, such as Expected Calibration Error (ECE), have significant limitations that motivated our selection of AUROC. |
| 24 | + |
| 25 | +#### Limitations of Expected Calibration Error (ECE) |
| 26 | + |
| 27 | +As noted in recent research (Jiang et al., 2025), Expected Calibration Error has a fundamental flaw: |
| 28 | + |
| 29 | +> "Expected calibration error (ECE) (Guo et al., 2017a; Naeini et al., 2015) is also a standard metric to measure how closely a model's confidence matches its accuracy. However, ECE does not assess a model's ability to discriminate between correct and incorrect answers—a model with accuracy 0.5 can achieve perfect ECE by outputting a confidence of 0.5 for all of its answers. Therefore, we focus our results on the AUC." |
| 30 | +
|
| 31 | +This limitation means ECE can be "gamed" by models that output uniform confidence scores, making it unsuitable for evaluating whether confidence scores actually help distinguish between correct and incorrect predictions. |
| 32 | + |
| 33 | +#### Why AUROC for Confidence Evaluation? |
| 34 | + |
| 35 | +AUROC addresses the core question: **"Do higher confidence scores correspond to more accurate predictions?"** This discrimination ability is essential for practical applications where confidence scores guide decision-making. |
| 36 | + |
| 37 | +**Mathematical Definition:** |
| 38 | +AUROC measures the probability that a randomly chosen correct prediction has higher confidence than a randomly chosen incorrect prediction. It treats confidence estimation as a binary classification problem where: |
| 39 | +- **Positive class**: Correct predictions (field matches ground truth) |
| 40 | +- **Negative class**: Incorrect predictions (field doesn't match ground truth) |
| 41 | +- **Classifier score**: Model's confidence score |
| 42 | + |
| 43 | +**Advantages over alternatives:** |
| 44 | +1. **Discrimination focus**: Directly measures whether confidence correlates with accuracy |
| 45 | +2. **Threshold independence**: Evaluates performance across all possible confidence thresholds |
| 46 | +3. **Intuitive interpretation**: Values closer to 1.0 indicate better calibration |
| 47 | +4. **Robust to class imbalance**: Works well even when correct/incorrect predictions are unbalanced |
| 48 | + |
| 49 | +### AUROC Calculation in Stickler |
| 50 | + |
| 51 | +**AUROC (Area Under ROC Curve)** measures confidence calibration quality: |
| 52 | + |
| 53 | +- **1.0**: Perfect calibration (high confidence = correct, low confidence = incorrect) |
| 54 | +- **0.5**: Random calibration (confidence doesn't correlate with accuracy) |
| 55 | +- **0.0**: Inverse calibration (high confidence = incorrect, low confidence = correct) |
| 56 | + |
| 57 | +#### Implementation Details |
| 58 | + |
| 59 | +1. For each field with confidence, determine if it matches ground truth |
| 60 | +2. Create binary classification: match (1) or no-match (0) |
| 61 | +3. Use confidence scores as prediction probabilities |
| 62 | +4. Calculate ROC curve and area under it |
| 63 | + |
| 64 | +#### Requirements |
| 65 | + |
| 66 | +- At least one field with confidence scores |
| 67 | +- Both matches and non-matches in the comparison |
| 68 | +- `document_field_comparisons=True` must be enabled |
| 69 | + |
| 70 | +### Interpretation Guidelines |
| 71 | + |
| 72 | +**Well-Calibrated Models (AUROC ≈ 0.8-1.0):** |
| 73 | +- High confidence predictions are predominantly correct |
| 74 | +- Low confidence predictions are predominantly incorrect |
| 75 | +- Confidence scores provide meaningful signal for decision-making |
| 76 | + |
| 77 | +**Poorly-Calibrated Models (AUROC ≈ 0.0-0.3):** |
| 78 | +- High confidence predictions are predominantly incorrect |
| 79 | +- May indicate systematic overconfidence or model issues |
| 80 | +- Confidence scores mislead rather than inform |
| 81 | + |
| 82 | +**Random Calibration (AUROC ≈ 0.5):** |
| 83 | +- Confidence scores don't correlate with accuracy |
| 84 | +- Model may need confidence calibration techniques |
| 85 | +- Consider post-processing methods like Platt scaling |
| 86 | + |
| 87 | +### Limitations and Considerations |
| 88 | + |
| 89 | +**Edge Cases:** |
| 90 | +- **All predictions correct**: AUROC undefined (no negative class) |
| 91 | +- **All predictions incorrect**: AUROC undefined (no positive class) |
| 92 | +- **Uniform confidence**: AUROC = 0.5 regardless of accuracy |
| 93 | + |
| 94 | +**Sample Size Requirements:** |
| 95 | +- Reliable AUROC calculation requires sufficient examples of both correct and incorrect predictions |
| 96 | +- Very small datasets may produce unstable AUROC estimates |
| 97 | + |
| 98 | +**Interpretation Context:** |
| 99 | +- AUROC should be interpreted alongside overall accuracy |
| 100 | +- High AUROC with low accuracy may indicate good uncertainty awareness |
| 101 | +- Low AUROC with high accuracy suggests overconfident correct predictions |
| 102 | + |
| 103 | +### References and Further Reading |
| 104 | + |
| 105 | +**Key Papers:** |
| 106 | +- Jiang, Z., et al. (2025). "Confidence Estimation in Large Language Models." [arXiv:2502.01126](https://arxiv.org/pdf/2502.01126) |
| 107 | +- Guo, C., et al. (2017). "On Calibration of Modern Neural Networks." ICML 2017 |
| 108 | +- Naeini, M. P., et al. (2015). "Obtaining Well Calibrated Probabilities Using Bayesian Binning." AAAI 2015 |
| 109 | + |
| 110 | +**Additional Resources:** |
| 111 | +- Scikit-learn ROC AUC documentation: [sklearn.metrics.roc_auc_score](https://scikit-learn.org/stable/modules/generated/sklearn.metrics.roc_auc_score.html) |
| 112 | + |
| 113 | +## JSON Structure |
| 114 | + |
| 115 | +### Standard Format |
| 116 | +```json |
| 117 | +{ |
| 118 | + "name": "Widget", |
| 119 | + "price": 29.99 |
| 120 | +} |
| 121 | +``` |
| 122 | + |
| 123 | +### Confidence Format |
| 124 | +```json |
| 125 | +{ |
| 126 | + "name": {"value": "Widget", "confidence": 0.95}, |
| 127 | + "price": {"value": 29.99, "confidence": 0.8} |
| 128 | +} |
| 129 | +``` |
| 130 | + |
| 131 | +### Mixed Format |
| 132 | +```json |
| 133 | +{ |
| 134 | + "name": {"value": "Widget", "confidence": 0.95}, |
| 135 | + "price": 29.99, |
| 136 | + "sku": {"value": "ABC123", "confidence": 0.7} |
| 137 | +} |
| 138 | +``` |
| 139 | + |
| 140 | +## Confidence Structure Rules |
| 141 | + |
| 142 | +A valid confidence structure must have exactly two keys: |
| 143 | +- `"value"`: The actual field value |
| 144 | +- `"confidence"`: Float between 0.0 and 1.0 |
| 145 | + |
| 146 | +## Nested Structures |
| 147 | + |
| 148 | +Confidence works with nested objects and arrays: |
| 149 | + |
| 150 | +```json |
| 151 | +{ |
| 152 | + "customer": { |
| 153 | + "name": {"value": "John Doe", "confidence": 0.92}, |
| 154 | + "address": { |
| 155 | + "street": {"value": "123 Main St", "confidence": 0.85}, |
| 156 | + "city": "New York" |
| 157 | + } |
| 158 | + }, |
| 159 | + "items": [ |
| 160 | + { |
| 161 | + "product": {"value": "Laptop", "confidence": 0.89}, |
| 162 | + "price": {"value": 1299.99, "confidence": 0.76} |
| 163 | + } |
| 164 | + ] |
| 165 | +} |
| 166 | +``` |
| 167 | + |
| 168 | +## Confidence Access API |
| 169 | + |
| 170 | +```python |
| 171 | +# Get individual field confidence |
| 172 | +confidence = model.get_field_confidence("name") # Returns float or None |
| 173 | + |
| 174 | +# Get all confidences |
| 175 | +all_confidences = model.get_all_confidences() # Returns dict |
| 176 | + |
| 177 | +# Nested field access |
| 178 | +street_conf = model.get_field_confidence("address.street") |
| 179 | + |
| 180 | +# Array field access |
| 181 | +item_conf = model.get_field_confidence("items[0].product") |
| 182 | +``` |
| 183 | + |
| 184 | +## Field Path Format |
| 185 | + |
| 186 | +Confidence paths use dot notation for nested fields and bracket notation for arrays: |
| 187 | + |
| 188 | +- Simple field: `"name"` |
| 189 | +- Nested field: `"address.street"` |
| 190 | +- Array element: `"items[0].product"` |
| 191 | +- Nested in array: `"orders[1].customer.name"` |
0 commit comments