Skip to content
Back to skills

Rail Representation Loss

ASecurity

Compute RAIL-KD layerwise and concatenated intermediate representation losses from pooled hidden states.

  • 247 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 9, 2026
businesspythonbash

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned September 9, 2026

npx -y skills add VectorSpaceLab/AREX-Skill --skill rail_representation_loss --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Rail Representation Loss?

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

Security grade badge for Rail Representation Loss
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/vectorspacelab-rail-representation-loss/badge)](https://www.skillsdirectory.com/skills/vectorspacelab-rail-representation-loss)

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: rail_representation_loss
description: Compute RAIL-KD layerwise and concatenated intermediate representation losses from pooled hidden states.
---

# RAIL Representation Loss

Use this skill when a distillation experiment must implement the RAIL-KD intermediate representation objective. It is appropriate after a teacher-layer mapping has selected exactly one teacher layer for each student layer. Do not use it for attention distribution matching, MiniLM relation losses, or layer-search logic.

## Inputs

- Teacher hidden states: nested numeric lists shaped `[m][tokens][teacher_dim]`.
- Student hidden states: nested numeric lists shaped `[m][tokens][student_dim]`.
- Projection matrices for teacher and student vectors.
- Variant: `layerwise` for RAIL-KDl or `concatenated` for RAIL-KDc.
- Optional layer weights for layerwise mode.

## Outputs

- Scalar intermediate loss.
- Diagnostics containing pooled vectors, normalized vectors, and per-layer distances when applicable.

## Workflow

1. Mean-pool each selected hidden-state layer across tokens.
2. Project teacher and student vectors to the same dimension.
3. L2-normalize projected vectors with a small epsilon guard.
4. For layerwise mode, compute weighted squared distances and sum them.
5. For concatenated mode, concatenate pooled vectors first, project once, normalize, then compute one squared distance.
6. Return diagnostics for recovery mechanism checks.

## Validation

Run:

```bash
python scripts/rail_loss.py --demo
python -m pytest tests
```

## Limitations

This skill uses small pure-Python numeric lists for portability. Production transformer code should pass actual tensors through equivalent pooling, projection, normalization, and distance operations while preserving the same contracts.

Files in this skill

  • SKILL.md1.7 KB
  • scripts/rail_loss.py4 KB
  • tests/test_rail_loss.py1.2 KB

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…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.