langspace.probe.traversal package

Module contents

class langspace.probe.traversal.TraversalProbe(model: LangVAE, data: Iterable[Sentence], sample_size: int, dims: List[int], annotations: Dict[str, List[str]] = None)[source]

Bases: LatentSpaceProbe

A probe for analyzing latent space traversal in an LM-VAE.

This probe performs a systematic traversal along specified latent dimensions. It first encodes a set of input sentences into latent representations, then perturbs these representations along each of the desired dimensions. The perturbed latent points are subsequently decoded back into sentences, allowing the user to inspect how modifications in particular latent dimensions affect the generated output.

dims

List of latent space dimensions along which the probe will traverse.

Type:

List[int]

model

The LM-VAE model to be probed.

Type:

LangVAE

sample_size

The number of samples generated along each dimension.

Type:

int

annotations

Optional dictionary of annotation types to be processed and all

Type:

Dict[str, List[str]], optional

their possible values, for conditional encoding.
report() DataFrame[source]

Generate a report detailing the latent space traversal results.

Returns:

A pandas DataFrame containing the traversal report with the following columns:
  • ’seeds’: The source sentences.

  • ’dim’: The latent dimension traversed.

  • ’distance’: The perturbation magnitude used in the traversal.

  • ’generate’: The generated sentence from the traversed latent point.

Return type:

DataFrame