skills/nlp/sentiment-conditioned-qa-span/SKILL.md
Prepend a sentiment token as the query in a QA-style input to condition span extraction on sentiment class without architectural changes
npx skillsauth add wenmin-wu/ds-skills nlp-sentiment-conditioned-qa-spanInstall 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.
For extracting sentiment-bearing spans from text, frame it as a QA task where the "question" is a single sentiment token. Encode the sentiment label (positive/negative/neutral) as a specific vocabulary token ID and prepend it before the text. The model learns to extract different spans depending on which sentiment token is present. No architecture changes needed — just input formatting.
from transformers import RobertaTokenizer
tokenizer = RobertaTokenizer.from_pretrained('roberta-base')
# Map sentiment labels to specific token IDs
sentiment_id = {
'positive': tokenizer.encode('positive', add_special_tokens=False)[0],
'negative': tokenizer.encode('negative', add_special_tokens=False)[0],
'neutral': tokenizer.encode('neutral', add_special_tokens=False)[0],
}
def encode_qa_input(text, sentiment, tokenizer, max_len=96):
"""Build QA-style input: [CLS] sentiment_token [SEP] [SEP] text [SEP]"""
enc = tokenizer.encode(text, add_special_tokens=False)
s_tok = sentiment_id[sentiment]
input_ids = [tokenizer.cls_token_id] + [s_tok] + \
[tokenizer.sep_token_id] * 2 + enc + [tokenizer.sep_token_id]
token_type_ids = [0] * 4 + [0] * (len(enc) + 1)
attention_mask = [1] * len(input_ids)
# Pad
pad_len = max_len - len(input_ids)
input_ids += [tokenizer.pad_token_id] * pad_len
token_type_ids += [0] * pad_len
attention_mask += [0] * pad_len
return input_ids, attention_mask, token_type_ids
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