skills/nlp/neutral-short-text-fallback/SKILL.md
Override model span predictions with full text for neutral sentiment or very short inputs where sub-span extraction is unreliable
npx skillsauth add wenmin-wu/ds-skills nlp-neutral-short-text-fallbackInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
In span extraction tasks, two cases reliably degrade model quality: (1) neutral-sentiment text where the entire text conveys sentiment equally, and (2) very short texts (1-2 words) where extracting a sub-span is meaningless. For both cases, bypass the model and return the full input text. This simple rule-based fallback consistently improves Jaccard scores by 1-3%.
def predict_span(text, sentiment, model, tokenizer, offsets):
"""Predict span with rule-based fallback."""
# Fallback 1: neutral sentiment → return full text
if sentiment == 'neutral':
return text
# Fallback 2: very short text → return full text
if len(text.split()) <= 2:
return text
# Fallback 3: invalid span (end < start) → return full text
start_idx, end_idx = model_predict(text, sentiment, model, tokenizer)
if end_idx < start_idx:
return text
# Normal case: extract span from offsets
span = ""
for ix in range(start_idx, end_idx + 1):
span += text[offsets[ix][0]:offsets[ix][1]]
if ix + 1 < len(offsets) and offsets[ix][1] < offsets[ix+1][0]:
span += " "
return span.strip()
data-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF