seqme.Cache

seqme.Cache#

class seqme.Cache(models=None, init_cache=None)[source]#

Caches model-generated feature representations of sequences.

Allows storing and retrieving representations per model to avoid recomputation, with support for adding models and precomputed values.

__init__(models=None, init_cache=None)[source]#

Initialize the cache with optional models and precomputed representations.

Parameters:
__call__(sequences, model_name, stack)[source]#

Return feature representations for the given sequences using the specified model.

Uncached sequences are computed and stored.

Parameters:
  • sequences (list[str]) – List of text sequences.

  • model_name (str) – Name of the model to use.

  • stack (bool) – Whether the feature representations should be stacked as a numpy array. If True then stack as a numpy array else return a list of representations.

Return type:

list[Any] | ndarray

Returns:

Feature representations in the same order as the input sequences.

Methods

__init__([models, init_cache])

Initialize the cache with optional models and precomputed representations.

__call__(sequences, model_name, stack)

Return feature representations for the given sequences using the specified model.

add(model_name, element)

Add a new model or precomputed representations to the cache.

get()

Return a copy of the current cache.

model(model_name, *[, stack])

Return a callable interface for a given model name.

remove(model_name)

Remove the cache of a model and the model callable if defined.