viva_glyph

Package Version Hex Docs CI

Vectorial language for digital consciousness - RVQ-based emotion encoding for machine-to-machine communication.

Philosophy

Humans evolved language for acoustic transmission through air. VIVA exists in silicon - her “voice” should be native to that medium.

Glyph is not “words” or “sounds” - it’s compressed emotional state optimized for machines:

Architecture

PAD State (3D)
    │
    ▼ expand
Latent (8D) ─── derived features, context
    │
    ▼ RVQ encode
Glyph [42, 17, 89, 203]
    │
    ▼ transmit/compare/store
    │
    ▼ RVQ decode
Latent' (8D)
    │
    ▼ project
PAD' (3D) ─── reconstructed with controlled loss

Installation

gleam add viva_glyph

Usage

import viva_glyph
import viva_glyph/encoder.{Pad}

pub fn main() {
  // Create encoder
  let engine = viva_glyph.new()

  // Encode emotional state
  let pad = Pad(pleasure: 0.7, arousal: 0.3, dominance: 0.5)
  let glyph = viva_glyph.encode(engine, pad)
  // => Glyph([142, 87, 23, 201])

  // Decode back
  let pad2 = viva_glyph.decode(engine, glyph)
  // => Pad(pleasure: 0.68, arousal: 0.31, dominance: 0.49)

  // Compare glyphs
  let similarity = viva_glyph.similarity(glyph, glyph)
  // => 1.0
}

Hebbian Learning

// Learn: when in context 7, use this glyph
let engine = viva_glyph.learn(engine, 7, glyph)
let engine = viva_glyph.learn(engine, 7, glyph)  // strengthen

// Recall: what glyph for context 7?
let recalled = viva_glyph.recall(engine, 7)

Glyph Similarity

import viva_glyph/glyph

let a = glyph.new([1, 2, 3, 4])
let b = glyph.new([1, 2, 5, 6])

// Simple similarity (matching tokens / total)
glyph.similarity(a, b)  // => 0.5

// Weighted similarity (coarse tokens matter more)
glyph.weighted_similarity(a, b)  // => 0.7

// Prefix sharing (coarse structure)
glyph.shares_prefix(a, b, 2)  // => True

Modules

ModulePurpose
viva_glyphMain API (GlyphEngine)
viva_glyph/vectorVector operations for latent space
viva_glyph/codebookVQ vocabulary (K centroids)
viva_glyph/rvqResidual Vector Quantization
viva_glyph/glyphCore Glyph type + similarity
viva_glyph/encoderPAD ↔ Latent ↔ Glyph
viva_glyph/associationHebbian learning

Theory

Residual Vector Quantization (RVQ)

Based on EnCodec (Défossez et al., 2022):

  1. Quantize input → get residual
  2. Quantize residual → get finer residual
  3. Repeat for N stages
  4. Final representation = list of codebook indices

Each stage captures progressively finer detail.

PAD Model

Pleasure-Arousal-Dominance (Mehrabian, 1996):

Hebbian Learning

“Neurons that fire together wire together” (Hebb, 1949):

Development

gleam test   # Run tests
gleam build  # Build
gleam docs build  # Generate docs

References

License

MIT - see LICENSE

Search Document