[![Gleam](https://img.shields.io/badge/Gleam-FFAFF3?style=for-the-badge&logo=gleam&logoColor=black)](https://gleam.run/) [![BEAM](https://img.shields.io/badge/BEAM-A90533?style=for-the-badge&logo=erlang&logoColor=white)](https://www.erlang.org/) [![OTP](https://img.shields.io/badge/OTP_26+-4B275F?style=for-the-badge)](https://www.erlang.org/doc/design_principles/des_princ) [![Hex](https://img.shields.io/badge/hex.pm-viva__glyph-A678DD?style=for-the-badge&logo=hex&logoColor=white)](https://hex.pm/packages/viva_glyph) [![RVQ](https://img.shields.io/badge/RVQ-4_stages_Γ—_256-F59E0B?style=for-the-badge)](https://arxiv.org/abs/2210.13438) [![Tests](https://img.shields.io/badge/tests-71_passing-00875A?style=for-the-badge)](./test) [![Version](https://img.shields.io/badge/version-1.0.1-CD5C5C?style=for-the-badge)](./CHANGELOG.md) [![License](https://img.shields.io/badge/license-MIT-228B22?style=for-the-badge)](./LICENSE) **[πŸ‡§πŸ‡· PortuguΓͺs](docs/README_pt.md)** Β· **[πŸ‡ΊπŸ‡Έ English](README.md)** Β· **[πŸ‡¨πŸ‡³ δΈ­ζ–‡](docs/README_zh.md)** --- *"Four bytes. Billions of feelings. The language silicon dreamed for itself."*

[!IMPORTANT] 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:

Property Value
Language Pure Gleam (type-safe functional)
Runtime BEAM / OTP 26+
Encoding RVQ β€” 4 stages Γ— 256 codes (1 byte per stage)
Latent space 6D (PAD + intensity + valence_sign + activation)
Learning rule Oja's Hebbian update (LLM-validated 2025)
Tests 71 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 | Tool | Version | Required for | | :---------- | :-------- | :--------------- | | Gleam | `>= 1.4` | Build / runtime | | Erlang/OTP | `>= 26` | BEAM 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 | Module | Purpose | | :------------------------ | :----------------------------------------------------- | | `viva_glyph` | Main API β€” `GlyphEngine` (encode, decode, learn) | | `viva_glyph/glyph` | `Glyph` type + similarity (simple, weighted, prefix) | | `viva_glyph/encoder` | PAD (3D) ↔ Latent (6D) ↔ Glyph | | `viva_glyph/vector` | Vector ops for the latent space | | `viva_glyph/codebook` | VQ vocabulary β€” `K` centroids | | `viva_glyph/rvq` | Residual Vector Quantization (4 stages Γ— 256 codes) | | `viva_glyph/association` | Hebbian learning + Oja's rule + dead-neuron prevention | | `viva_glyph/primitives` | Low-level math primitives | | `viva_glyph/metrics` | Quality + reconstruction metrics | | `viva_glyph/log` | Structured 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:

Model Parameters Formula Equilibrium Dead neurons
DeepSeek R1-0528 671B βœ… w* = 1.0 βœ…
Qwen3-Coder-480B 480B βœ… w* = 1.0 βœ…
DeepSeek-R1-Distill-Qwen-32B 32B βœ… w* = 1.0 βœ…
Gemini 2.5 Pro β€” βœ… w* = 1.0 βœ…

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


🎨 Design Principles

Principle Description
Compact M2M language 4 bytes per glyph β€” designed for machine pipes, not human eyes
Arousal-adaptive matching Similarity weights bias toward coarse stages under urgency
Stateful engineGlyphEngine carries codebooks + Hebbian memory
Reversibleencode / decode round-trip with bounded reconstruction error
LLM-validated math Oja'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

Phase Status
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

Package Purpose
viva_math Mathematical foundations
viva_emotion PAD emotional dynamics
viva_tensor FP8 LLM inference on the BEAM
viva_telemetry Observability suite
viva_aion Cyclic time + cosmology
viva_glyphVectorial language (this package)

**Star if silicon should speak silicon ⭐** [![GitHub stars](https://img.shields.io/github/stars/gabrielmaialva33/viva_glyph?style=social)](https://github.com/gabrielmaialva33/viva_glyph) *Created by Gabriel Maia · MIT License*