Skip to content
Back to skills

Space Aware Span Postprocessing

ASecurity

Clean up character-level span predictions by removing isolated space characters at span boundaries

  • 61 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 12, 2026
toolspython

Works with

  • cli

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill space-aware-span-postprocessing --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Space Aware Span Postprocessing?

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

Security grade badge for Space Aware Span Postprocessing
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-space-aware-span-postprocessing/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-space-aware-span-postprocessing)

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: nlp-space-aware-span-postprocessing
description: Clean up character-level span predictions by removing isolated space characters at span boundaries
domain: nlp
---

# Space-Aware Span Post-Processing

## Overview

Tokenizers (especially BPE/RoBERTa) often include leading/trailing spaces in token offsets. This causes span predictions to include stray space characters at boundaries. Post-process by removing isolated space predictions and bridging spaces between positive predictions.

## Quick Start

```python
import numpy as np

def postprocess_spaces(predictions, text):
    """Fix space artifacts in character-level span predictions."""
    preds = np.copy(predictions)
    for i in range(1, len(text) - 1):
        if text[i] == " ":
            if preds[i] and not preds[i - 1]:    # leading space
                preds[i] = 0
            if preds[i] and not preds[i + 1]:    # trailing space
                preds[i] = 0
            if preds[i - 1] and preds[i + 1]:    # bridge gap
                preds[i] = 1
    return preds
```

## Workflow

1. Get binary character-level predictions (after thresholding)
2. Scan for space characters
3. Remove spaces at span boundaries (no positive neighbor on one side)
4. Bridge spaces between two positive neighbors (merge adjacent spans)

## Key Decisions

- **Why needed**: RoBERTa tokenizer includes leading spaces in tokens (`Ġword`), so offset mapping assigns space characters the same probability as the word
- **Bridge rule**: if both neighbors are positive, the space between them should be too — avoids splitting `"chest pain"` into `"chest"` + `"pain"`
- **Apply after thresholding**: operates on binary predictions, not probabilities

## References

- Source: [roberta-strikes-back](https://www.kaggle.com/code/theoviel/roberta-strikes-back)
- Competition: NBME - Score Clinical Patient Notes

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…