shared

package
v1.25.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Experimental — this package is not yet wired into the main framework.

Package shared provides a cross-model latent space for knowledge sharing.

A LatentSpace defines a common embedding space that multiple models can project into and read from. Each model registers with its own input dimension. Learned projection matrices map between model-specific representation spaces and the shared latent space.

The workflow is:

  1. Create a latent space with NewLatentSpace(dim).
  2. Register models via Register(name, inputDim).
  3. Train projection matrices via TrainProjections with aligned data.
  4. Use Project to map model features into the shared space.
  5. Use Retrieve to map shared representations back to a model's space.

This enables knowledge transfer: what one model learns can benefit other models through the shared embedding.

(Stability: alpha)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LatentSpace

type LatentSpace struct {
	// contains filtered or unexported fields
}

LatentSpace is a shared embedding space that multiple models can project into and read from via learned linear projections.

func NewLatentSpace

func NewLatentSpace(dim int) *LatentSpace

NewLatentSpace creates a shared latent space with the given dimension.

func (*LatentSpace) Project

func (ls *LatentSpace) Project(name string, features []float64) []float64

Project maps model features into the shared latent space. features must have length equal to the model's registered input dimension.

func (*LatentSpace) Register

func (ls *LatentSpace) Register(name string, inputDim int)

Register adds a model to the latent space with the specified input dimension. Projection matrices are initialized with Xavier uniform initialization.

func (*LatentSpace) Retrieve

func (ls *LatentSpace) Retrieve(name string, latent []float64) []float64

Retrieve maps a latent-space vector back to a model's representation space.

func (*LatentSpace) TrainProjections

func (ls *LatentSpace) TrainProjections(data map[string][][]float64, config ProjectionConfig) error

TrainProjections learns projection and reconstruction matrices from aligned data. The data map keys are model names; values are slices of feature vectors. All models must have the same number of samples (aligned by index). Training minimises reconstruction loss plus an alignment loss that pulls corresponding samples from different models toward the same point in latent space.

type ProjectionConfig

type ProjectionConfig struct {
	// LatentDim overrides the latent space dimension for training. If zero,
	// the dimension specified at construction time is used.
	LatentDim int

	// LearningRate is the step size for gradient descent. Default: 0.01.
	LearningRate float64

	// NEpochs is the number of training epochs. Default: 100.
	NEpochs int

	// AlignmentWeight controls how strongly the alignment loss (bringing
	// corresponding samples from different models close in latent space)
	// is weighted relative to reconstruction loss. Default: 1.0.
	AlignmentWeight float64
}

ProjectionConfig controls the training of projection matrices.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL