skills/cv/siamese-pairwise-comparison-head/SKILL.md
Siamese network head that compares two embeddings via element-wise multiply, add, abs-diff, and squared-diff features for verification tasks
npx skillsauth add wenmin-wu/ds-skills cv-siamese-pairwise-comparison-headInstall 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 verification tasks (same/different identity), a siamese network produces two embeddings from shared weights. Instead of a simple distance metric, concatenate four element-wise operations (multiply, add, absolute difference, squared difference) and pass through a small CNN to learn which comparison features matter. This captures richer pair relationships than Euclidean or cosine distance alone.
from tensorflow.keras.layers import *
from tensorflow.keras.models import Model
import tensorflow.keras.backend as K
def build_head(branch_model, mid=32):
xa = Input(shape=branch_model.output_shape[1:])
xb = Input(shape=branch_model.output_shape[1:])
x1 = Lambda(lambda x: x[0] * x[1])([xa, xb])
x2 = Lambda(lambda x: x[0] + x[1])([xa, xb])
x3 = Lambda(lambda x: K.abs(x[0] - x[1]))([xa, xb])
x4 = Lambda(lambda x: K.square(x))(x3)
x = Concatenate()([x1, x2, x3, x4])
emb_dim = branch_model.output_shape[1]
x = Reshape((4, emb_dim, 1))(x)
x = Conv2D(mid, (4, 1), activation='relu', padding='valid')(x)
x = Reshape((emb_dim, mid, 1))(x)
x = Conv2D(1, (1, mid), activation='linear', padding='valid')(x)
x = Flatten()(x)
x = Dense(1, activation='sigmoid')(x)
return Model([xa, xb], x)
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