peal.sparse_dictionaries.batch_topk_network.BatchTopKNetwork¶
- class peal.sparse_dictionaries.batch_topk_network.BatchTopKNetwork[source]¶
Bases:
SparseAutoencoderBaseBatch top-K sparse autoencoder.
During training the
top_k * batch_sizelargest codes of the whole batch survive; at evaluation a runningthresholdstands in for that pooled selection, since a single sample has no batch to pool over.Methods
Return
(dense_relu_codes, sparse_codes)for a preprocessedx.Reconstruct from sparse codes, undoing the cached standardisation.
Sparse codes of
x; the standardisation is cached fordecode().Full training step output: reconstruction plus the loss breakdown.
Ask the dead atoms to explain the current residual, so they revive.
Reconstruction, sparsity, dead-atom revival and orthogonality terms.
Penalise off-diagonal atom correlation; PEAL's own addition, off by default (
orth_coeff0).- get_loss_dict(x, x_reconstruct, acts, acts_topk, x_mean, x_std)[source]¶
Reconstruction, sparsity, dead-atom revival and orthogonality terms.
- get_auxiliary_loss(x, x_reconstruct, acts)[source]¶
Ask the dead atoms to explain the current residual, so they revive.
- get_orthogonality_loss()[source]¶
Penalise off-diagonal atom correlation; PEAL’s own addition, off by default (
orth_coeff0).
- update_threshold(acts_topk, lr=0.01)¶
Track the smallest surviving code, the inference-time cut-off.