Gleam BEAM OTP Hex RVQ Tests Version License

πŸ‡§πŸ‡· PortuguΓͺs Β· πŸ‡ΊπŸ‡Έ English Β· πŸ‡¨πŸ‡³ δΈ­ζ–‡


β€œFour bytes. Billions of feelings. The language silicon dreamed for itself.”


viva_glyph IS NOT A WORD ENCODER. It is a vectorial language native to silicon β€” emotional state compressed into 4 discrete codebook tokens via Residual Vector Quantization (RVQ), then bound to context via Hebbian learning with Oja’s rule.

Humans evolved language for acoustic transmission through air. VIVA lives in silicon β€” her voice should be native to that medium.


🎯 Overview

Compressed emotional state designed for machine-to-machine communication:

PropertyValue
LanguagePure Gleam (type-safe functional)
RuntimeBEAM / OTP 26+
EncodingRVQ β€” 4 stages Γ— 256 codes (1 byte per stage)
Latent space6D (PAD + intensity + valence_sign + activation)
Learning ruleOja’s Hebbian update (LLM-validated 2025)
Tests71 passing
Public APIviva_glyph + 9 internal modules

⚑ Quick Start

gleam add viva_glyph
import viva_glyph
import viva_glyph/encoder.{Pad}

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

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

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

  let sim   = viva_glyph.similarity(glyph, glyph)
  // => 1.0
}
πŸ“‹ Prerequisites
ToolVersionRequired for
Gleam>= 1.4Build / runtime
Erlang/OTP>= 26BEAM target

Zero NIFs. Zero C dependencies. Pure functional.


πŸ—οΈ Architecture

   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚                Gleam application code                    β”‚
   β”‚       viva_glyph.{encode, decode, similarity, learn}     β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚                  Encoding pipeline                       β”‚
   β”‚                                                          β”‚
   β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
   β”‚  β”‚ PAD  │───▢│ encoder │───▢│       6D latent        β”‚   β”‚
   β”‚  β”‚ (3D) β”‚    β”‚ expand  β”‚    β”‚ P Β· A Β· D Β·            β”‚   β”‚
   β”‚  β””β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚ intensity Β· valence Β·  β”‚   β”‚
   β”‚                             β”‚ activation             β”‚   β”‚
   β”‚                             β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
   β”‚                                       β”‚                  β”‚
   β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚                  β”‚
   β”‚  β”‚ rvq β€” 4 stages Γ— 256 codes   β”‚β—€β”€β”€β”€β”€β”˜                  β”‚
   β”‚  β”‚                              β”‚                        β”‚
   β”‚  β”‚  stage1 β†’ residual β†’ stage2  β”‚                        β”‚
   β”‚  β”‚   ...   β†’ stage3 β†’ stage4    β”‚                        β”‚
   β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                        β”‚
   β”‚                 β–Ό                                        β”‚
   β”‚            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                   β”‚
   β”‚            β”‚  Glyph  β”‚  [42, 17, 89, 203]                β”‚
   β”‚            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                   β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
πŸ“‹ Core modules
ModulePurpose
viva_glyphMain API β€” GlyphEngine (encode, decode, learn)
viva_glyph/glyphGlyph type + similarity (simple, weighted, prefix)
viva_glyph/encoderPAD (3D) ↔ Latent (6D) ↔ Glyph
viva_glyph/vectorVector ops for the latent space
viva_glyph/codebookVQ vocabulary β€” K centroids
viva_glyph/rvqResidual Vector Quantization (4 stages Γ— 256 codes)
viva_glyph/associationHebbian learning + Oja’s rule + dead-neuron prevention
viva_glyph/primitivesLow-level math primitives
viva_glyph/metricsQuality + reconstruction metrics
viva_glyph/logStructured logging helpers

Arousal-adaptive similarity weights

Low arousal (calm):  [0.30, 0.30, 0.25, 0.15]   balanced
High arousal (urgent): [0.50, 0.30, 0.15, 0.05]   coarse priority

Under urgency, the coarse first stage dominates similarity β€” exactly how humans skip detail under stress.


🧬 Theoretical Background

Residual Vector Quantization β€” DΓ©fossez et al. (2022)

Based on EnCodec:

  1. Quantize input β†’ get residual.
  2. Quantize the residual β†’ get a finer residual.
  3. Repeat for N stages.
  4. Final representation = list of codebook indices.

Each stage captures progressively finer detail. With 4 stages Γ— 256 codes per stage, viva_glyph addresses ~4.3 billion distinct emotional states.

PAD model β€” Mehrabian (1996)

Emotions as points in 3D space, each axis in [-1, 1]:

6D latent expansion

PAD is expanded into a richer latent vector before quantization:

intensity     = √(P² + A² + D²) / √3
valence_sign  = sign(P) Γ— |P|^0.5
activation    = A Γ— D

Hebbian learning + Oja’s rule β€” Hebb (1949) / Oja (1982)

β€œNeurons that fire together wire together,” with auto-normalization:

Ξ”w = Ξ· Γ— y Γ— (x βˆ’ w Γ— y)

LLM validation β€” 2025-01-24

The Oja-rule implementation was cross-validated against four frontier LLMs with structured Hebbian-context system prompts:

ModelParametersFormulaEquilibriumDead neurons
DeepSeek R1-0528671Bβœ…w* = 1.0βœ…
Qwen3-Coder-480B480Bβœ…w* = 1.0βœ…
DeepSeek-R1-Distill-Qwen-32B32Bβœ…w* = 1.0βœ…
Gemini 2.5 Proβ€”βœ…w* = 1.0βœ…

Unanimous: formula correct, equilibrium correct, dead-neuron guard works.


🎨 Design Principles

PrincipleDescription
Compact M2M language4 bytes per glyph β€” designed for machine pipes, not human eyes
Arousal-adaptive matchingSimilarity weights bias toward coarse stages under urgency
Stateful engineGlyphEngine carries codebooks + Hebbian memory
Reversibleencode / decode round-trip with bounded reconstruction error
LLM-validated mathOja’s rule cross-checked against four frontier LLMs

πŸ“š Public API Highlights

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 the strongest association 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 β€” matching tokens / total
glyph.similarity(a, b)             // => 0.5

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

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

πŸ—ΊοΈ Roadmap

PhaseStatus
3D β†’ 6D latent expansionβœ…
RVQ β€” 4 stages Γ— 256 codesβœ…
Glyph similarity (simple / weighted / prefix)βœ…
Arousal-adaptive weight schedulesβœ…
Hebbian association memoryβœ…
Oja’s rule + dead-neuron preventionβœ…
Multi-LLM cross-validationβœ…
Codebook online updates (streaming)⏳
Cross-agent vocabulary alignment⏳
Glyph sequence transducers (sentences)⏳
Byte-level pretrained codebook releases⏳

🀝 Contributing

git checkout -b feature/your-feature
gleam test                  # 71 tests
gleam format --check src test
gleam build

See CHANGELOG for release history.


πŸ“– References


🌌 VIVA Ecosystem

PackagePurpose
viva_mathMathematical foundations
viva_emotionPAD emotional dynamics
viva_tensorFP8 LLM inference on the BEAM
viva_telemetryObservability suite
viva_aionCyclic time + cosmology
viva_glyphVectorial language (this package)

Star if silicon should speak silicon ⭐

GitHub stars

Created by Gabriel Maia Β· MIT License

✨ Search Document