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:
- Create a latent space with NewLatentSpace(dim).
- Register models via Register(name, inputDim).
- Train projection matrices via TrainProjections with aligned data.
- Use Project to map model features into the shared space.
- 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 ¶
- type LatentSpace
- func (ls *LatentSpace) Project(name string, features []float64) []float64
- func (ls *LatentSpace) Register(name string, inputDim int)
- func (ls *LatentSpace) Retrieve(name string, latent []float64) []float64
- func (ls *LatentSpace) TrainProjections(data map[string][][]float64, config ProjectionConfig) error
- type ProjectionConfig
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.