skills/nlp/anchor-grouped-validation/SKILL.md
Split validation by unique anchor/query entities so no anchor appears in both train and val, preventing data leakage in pairwise matching tasks
npx skillsauth add wenmin-wu/ds-skills nlp-anchor-grouped-validationInstall 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 pairwise matching tasks (phrase similarity, question-answer matching), the same anchor/query maps to multiple targets. If the same anchor appears in both train and validation, the model memorizes anchor-specific patterns rather than learning general similarity. Splitting by unique anchors ensures the model is evaluated on truly unseen queries.
import numpy as np
from sklearn.model_selection import StratifiedGroupKFold
groups = df['anchor'].values
scores = (df['score'] * 100).astype(int) # bin for stratification
sgkf = StratifiedGroupKFold(n_splits=4, shuffle=True, random_state=42)
for fold, (train_idx, val_idx) in enumerate(sgkf.split(df, scores, groups)):
train_df = df.iloc[train_idx]
val_df = df.iloc[val_idx]
assert set(train_df['anchor']) & set(val_df['anchor']) == set()
StratifiedGroupKFold for balanced + grouped splits, or manual shuffle-split on unique entitiesdata-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