Skip to content
Back to skills

Generative Output Numeric Cleaning

ASecurity

Clean noisy numeric strings from generative model output by removing invalid characters, fixing malformed floats, and handling multiple decimal points

  • 61 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 12, 2026
toolspythongit

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill generative-output-numeric-cleaning --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Generative Output Numeric Cleaning?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Generative Output Numeric Cleaning
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-generative-output-numeric-cleaning/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-generative-output-numeric-cleaning)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: cv-generative-output-numeric-cleaning
description: Clean noisy numeric strings from generative model output by removing invalid characters, fixing malformed floats, and handling multiple decimal points
---

# Generative Output Numeric Cleaning

## Overview

Generative vision-language models (Donut, Pix2Struct, Florence) often produce noisy numeric strings — extra spaces, stray characters, multiple decimal points, or malformed scientific notation. A robust cleaning pipeline strips invalid characters, fixes structural issues (multiple dots, multiple signs), and falls back to zero for unparseable values, preventing downstream errors.

## Quick Start

```python
import re

def clean_numeric(str_list):
    result = []
    for s in str_list:
        s = re.sub(r"\s", "", s)
        dtype = float if "." in s else int
        try:
            result.append(dtype(s))
            continue
        except ValueError:
            pass
        s = re.sub(r"[^0-9.\-eE]", "", s)
        if not s:
            result.append(0)
            continue
        if s.count(".") > 1:
            parts = s.split(".")
            s = parts[0] + "." + "".join(parts[1:])
        if s.count("-") > 1:
            s = "-" + s.replace("-", "")
        try:
            result.append(dtype(s))
        except ValueError:
            result.append(0)
    return result

raw = ["12.5", "1,234.5", " -3..2 ", "abc", "1.2e3"]
clean_numeric(raw)  # [12.5, 1234.5, -3.2, 0, 1200.0]
```

## Workflow

1. Strip whitespace from each string
2. Attempt direct `int()` or `float()` parse — fast path for clean values
3. Remove all non-numeric characters (keep digits, `.`, `-`, `e`, `E`)
4. Fix multiple decimal points by merging after first dot
5. Fix multiple negative signs by keeping only one at the start
6. Return 0 as fallback for unparseable values

## Key Decisions

- **Zero fallback**: safer than NaN for downstream aggregation; adjust per use case
- **Comma handling**: `re.sub` removes commas naturally in the stripping step
- **Scientific notation**: preserve `e`/`E` characters for values like `1.2e3`
- **Type detection**: use `.` presence to choose int vs float

## References

- [donut-infer (LB 0.44) [benetech]](https://www.kaggle.com/code/nbroad/donut-infer-lb-0-44-benetech)
- [Tuned Donut](https://www.kaggle.com/code/cody11null/tuned-donut)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…