peal.sparse_dictionaries.interfaces.SparseDictionary¶
- class peal.sparse_dictionaries.interfaces.SparseDictionary[source]¶
Bases:
ABCAbstract interface of a sparse dictionary.
Subclasses hold a
config(aSparseDictionaryConfig) and implement fitting from a tensor of activations or from dataloaders, plus serialisation. Most concrete implementations additionally offerencode/decompose,get_componentsandeval, which the explainers call but which are not part of this minimal base class.- Variables:
config (
SparseDictionaryConfig) – The configuration the dictionary was built from.
Methods
Fit the dictionary on a tensor of activations.
Fit the dictionary by iterating over one or more dataloaders.
Restore the fitted state from
path.Serialise the fitted state to
path.Attributes
- config: SparseDictionaryConfig¶
- abstract fit(X)[source]¶
Fit the dictionary on a tensor of activations.
- Parameters:
X (
torch.Tensor) – Activations of shape[N, act_size].- Raises:
NotImplementedError – Always, in the base class.
- abstract fit_from_dataloaders(dataloaders)[source]¶
Fit the dictionary by iterating over one or more dataloaders.
- Parameters:
dataloaders (
listoftorch.utils.data.DataLoader) – Loaders yielding(x, y)batches; implementations run the encoder themselves and collect the activations.- Raises:
NotImplementedError – Always, in the base class.
- abstract save_on_disk(path)[source]¶
Serialise the fitted state to
path.- Raises:
NotImplementedError – Always, in the base class.
- abstract load_from_disk(path)[source]¶
Restore the fitted state from
path.- Raises:
NotImplementedError – Always, in the base class.