experanto.utils.SessionSpecificSampler

class SessionSpecificSampler(*args, **kwargs)[source]

Bases: Sampler

A batch sampler specific to a single session that efficiently generates batches from the session’s indices.

Methods

__init__(indices, batch_size[, drop_last, ...])

Initialize session-specific sampler.

get_state()

Return the state of the sampler (including RNG state).

set_position(position)

Set the current batch position.

set_state(state)

Restore the state of the sampler (including RNG state).

__init__(indices, batch_size, drop_last=False, shuffle=False, seed=None)[source]

Initialize session-specific sampler.

Parameters:
  • indices (list) – Dataset indices belonging to this session.

  • batch_size (int) – Number of samples per batch.

  • drop_last (bool, optional) – Whether to drop the last batch if smaller than batch_size. Default is False.

  • shuffle (bool, optional) – Whether to shuffle indices. Default is False.

  • seed (int, optional) – Random seed for reproducibility.

__len__()[source]

Return the number of batches.

set_position(position)[source]

Set the current batch position.

get_state()[source]

Return the state of the sampler (including RNG state).

set_state(state)[source]

Restore the state of the sampler (including RNG state).

__iter__()[source]

Yield batches of indices starting from the current position.