xwm.metrics¶
Linear and k-NN probes, and collapse diagnostics. See Diagnostics for what each one misses.
Metrics: is this representation any good, and has it collapsed?
Modules:
| Name | Description |
|---|---|
probes |
Linear and nearest-neighbour probes. |
representation |
Diagnosing a representation without labels. |
Functions:
| Name | Description |
|---|---|
knn_probe |
k-nearest-neighbour probe in cosine distance. |
ridge_probe |
Closed-form ridge regression from embeddings to targets. |
collapse_report |
All of the above at once, for logging alongside the loss. |
effective_rank_ratio |
|
feature_std |
Mean per-dimension standard deviation. Near zero means collapse. |
mean_cosine_similarity |
Average pairwise cosine similarity between samples (excluding self). |
rankme |
RankMe: the effective rank as the entropy of the singular-value spectrum. |
singular_values |
Singular values of the centred embedding matrix, descending. |
knn_probe
¶
knn_probe(z_train: Array, y_train: Array, z_test: Array, y_test: Array, *, k: int = 5, classification: bool = False, n_classes: int | None = None) -> dict[str, Array]
k-nearest-neighbour probe in cosine distance.
Unlike ridge_probe this reads local structure, so the two together
distinguish "linearly decodable" from "merely clustered".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classification
|
bool
|
treat |
False
|
n_classes
|
int | None
|
required when |
None
|
Source code in xwm/metrics/probes.py
ridge_probe
¶
ridge_probe(z_train: Array, y_train: Array, z_test: Array, y_test: Array, *, alpha: float = 0.001) -> dict[str, Array]
Closed-form ridge regression from embeddings to targets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z_train
|
Array
|
|
required |
y_train
|
Array
|
|
required |
alpha
|
float
|
ridge penalty, on the scale of the (standardised) features. |
0.001
|
Returns:
| Type | Description |
|---|---|
dict[str, Array]
|
|
dict[str, Array]
|
mean, so a probe that has learned nothing scores ~0 and a harmful one |
dict[str, Array]
|
scores below 0. |
Source code in xwm/metrics/probes.py
collapse_report
¶
All of the above at once, for logging alongside the loss.
Source code in xwm/metrics/representation.py
effective_rank_ratio
¶
feature_std
¶
mean_cosine_similarity
¶
Average pairwise cosine similarity between samples (excluding self).
Approaching 1.0 means every input maps to nearly the same direction --
collapse, even if the per-dimension variance still looks healthy.
Source code in xwm/metrics/representation.py
rankme
¶
RankMe: the effective rank as the entropy of the singular-value spectrum.
exp(H(p)) where p is the normalised spectrum. Equals D when every
direction carries equal energy and 1 when all the energy is in one
direction, and unlike a hard rank it responds smoothly to partial
collapse -- the failure mode that actually shows up in JEPA training.
Note that the spectrum is taken after centring, so this is blind to a
constant offset: an encoder emitting c + tiny_noise still scores a high
rank. feature_std and mean_cosine_similarity catch that
case, which is why collapse_report reports all three.
Source code in xwm/metrics/representation.py
singular_values
¶
Singular values of the centred embedding matrix, descending.