Skip to content

dkypuros/atomic-lang-model

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

10 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿงฌ Atomic Language Model

Extremely lightweight universal grammar implementation with provable recursion

License: MIT Rust Size

A mathematically rigorous, recursively complete language model that fits in under 50kB with zero runtime dependencies. Built on Chomsky's Minimalist Grammar theory with formal verification and empirical validation.

๐Ÿ“Š Mind-Blowing Size Comparison:

  • Our Model: 0.05 MB (50 KB)
  • GPT-3: 700,000 MB
  • Ratio: We're 14,000,000x smaller!

Yet we still provide provable recursion, next-token prediction, and formal verification. See how we did it โ†’

โœจ What Makes This Special

๐Ÿงฎ Mathematically Proven: Formal proofs of recursive capability using Coq
โšก Ultra-Lightweight: Complete implementation under 50kB binary
๐Ÿ”ฌ Scientifically Validated: Tested with standard linguistic benchmark suites
๐Ÿ—๏ธ Universal Grammar: Based on Chomsky's Minimalist Grammar theory
โ™พ๏ธ Provably Recursive: Generates a^n b^n patterns, proving non-regularity
๐Ÿค– Probabilistic Language Model: Next-token prediction with formal guarantees

๐Ÿš€ Quick Start

Prerequisites

  • Rust 1.70+ (for compilation)
  • Git (for cloning)
  • Python 3.8+ (optional, for probabilistic language model)

30-Second Demo

# Clone the repository
git clone https://github.com/user/atomic-lang-model.git
cd atomic-lang-model/atomic-lang-model

# Run the demo (shows recursive generation + parsing)
cargo run --release

# Run mathematical proof tests
cargo test --release test_complete_recursive_proof

# Run full benchmark suite
cargo test --release --features bench

# NEW: Try the probabilistic language model
cd ../python && python tiny_lm.py

What You'll See

๐Ÿงฌ Atomic Language Model - Recursive Grammar Demo
============================================================

๐Ÿ“ Mathematical Proof: aโฟbโฟ Generation
----------------------------------------
n=0: ฮต (empty)
n=1: a b  
n=2: a a b b
n=3: a a a b b b
n=4: a a a a b b b b
n=5: a a a a a b b b b b

๐Ÿ” Parsing Test: Recursive Structures
----------------------------------------
โœ… 'the student left' โ†’ the student left
   Category: S, Complete: true

โ™พ๏ธ  Unbounded Recursion Demonstration
----------------------------------------
โœ… Can generate a^6b^6 (length: 12)
โœ… Can generate a^7b^7 (length: 14)  
โœ… Can generate a^8b^8 (length: 16)

๐ŸŽฏ Theoretical Capacity: INFINITE
๐Ÿ”ฌ Practical Limit: Memory bounded

๐Ÿ“š Learning Path

1. ๐ŸŽฏ Start Here: Understanding Recursion

Read First: Recursive Language Overview

  • What is recursion in language?
  • Why does it matter?
  • How does this implementation work?

2. ๐Ÿงฎ The Mathematical Foundation

Core Mathematics: Mathematical Foundations

  • Formal language theory & Chomsky hierarchy
  • Abstract algebra & grammar operations
  • Category theory & the fibration architecture

Historical Context: Chomsky's Mathematical Proofs

  • The 1956 proof that changed linguistics
  • How finite-state grammars fail
  • Why recursion is mathematically necessary

3. โš™๏ธ Technical Deep Dive

Then: Formal Language Theory

  • Grammar hierarchies and automata
  • Minimalist Grammar operations
  • Complexity theory and parsing

4. ๐Ÿ’ป Implementation Details

Implementation: Atomic Language Model

5. ๐Ÿงช Testing and Validation

Validation: NLP Verification Methods

  • Agreement test suites
  • Colorless green tests
  • Performance benchmarking

6. โœ… Formal Verification

Advanced: Machine Verification

  • Coq proof development
  • Mechanized theorem proving
  • Mathematical rigor

๐ŸŒŸ The Complete Story

This project demonstrates the full journey from mathematical theory to practical implementation:

๐Ÿ“– The Recursive Story - The complete narrative connecting all pieces

๐Ÿ†• Probabilistic Language Model Extension

We've extended the atomic language model with probabilistic next-token prediction capabilities while maintaining all formal guarantees:

Features

  • ๐ŸŽฒ Weighted Grammar Rules: Each production has learned probabilities
  • ๐Ÿ”ฎ Next-Token Prediction: Monte Carlo sampling for language modeling
  • ๐Ÿ”„ Hybrid Architecture: Combines Rust validation with Python inference
  • ๐ŸŒ REST API: Flask server for easy integration
  • ๐Ÿ“ฆ Still Ultra-Light: <100kB total with all features

Quick Demo

# Run the probabilistic language model
cd atomic-lang-model/python
python tiny_lm.py

# Start the API server
python api_server.py

# Try the interactive demo
cd ../examples
python language_model_demo.py

Example API Usage

# Predict next token
curl localhost:5000/predict?prefix=the+student

# Generate sentences
curl localhost:5000/generate?count=5

# Validate syntax
curl -X POST localhost:5000/validate \
  -H "Content-Type: application/json" \
  -d '{"sentences": ["the student left", "student the left"]}'

This extension bridges formal grammar theory with practical NLP applications, creating the world's smallest formally verified language model.

๐ŸŽฏ Key Features

Mathematical Rigor

  • โœ… Formal Specification: Complete mathematical definition of operations
  • โœ… Coq Proofs: Machine-verified theorems about recursive properties
  • โœ… Non-regularity Proof: Constructive demonstration via a^n b^n generation
  • โœ… Complexity Bounds: Polynomial parsing with exponential generation capacity

Universal Grammar Implementation

  • โœ… Merge Operation: Merge(ฮฑ:=_X ฮฒ, X:ฮณ) = โŸจX, [], [ฮฑ, ฮณ]โŸฉ
  • โœ… Move Operation: Implements wh-movement and feature checking
  • โœ… Feature System: Categories, selectors, and movement features
  • โœ… Minimalist Compliance: Based on Chomsky's Minimalist Program

Engineering Excellence

  • โœ… Zero Dependencies: No runtime requirements
  • โœ… Size Optimized: ~35kB binary with full functionality
  • โœ… Memory Efficient: <256kB peak usage for 20-word sentences
  • โœ… Fast Parsing: Polynomial-time complexity O(nยณ)

Empirical Validation

  • โœ… Agreement Tests: Subject-verb agreement across center-embedding (Linzen et al. 2016)
  • โœ… Colorless Green: Syntactic processing with semantic anomalies (Gulordava et al. 2018)
  • โœ… Recursive Capability: Demonstrates unbounded center-embedding
  • โœ… Performance Metrics: Comprehensive benchmarking framework

๐Ÿ› ๏ธ Project Structure

atomic-lang-model/
โ”œโ”€โ”€ docs/                          # ๐Ÿ“š Complete documentation suite
โ”‚   โ”œโ”€โ”€ recursive-language-overview.md    # Start here!
โ”‚   โ”œโ”€โ”€ chomsky-mathematical-proofs.md    # The math foundation
โ”‚   โ”œโ”€โ”€ formal-language-theory.md         # Technical theory
โ”‚   โ”œโ”€โ”€ computational-processing.md       # How machines handle recursion
โ”‚   โ”œโ”€โ”€ nlp-verification-methods.md       # Testing approaches
โ”‚   โ”œโ”€โ”€ machine-verification.md           # Formal proofs
โ”‚   โ””โ”€โ”€ the-recursive-story.md            # Complete narrative
โ”œโ”€โ”€ atomic-lang-model/             # ๐Ÿงฌ Core implementation
โ”‚   โ”œโ”€โ”€ src/lib.rs                      # Main implementation (~3k lines)
โ”‚   โ”œโ”€โ”€ tests/recursion.rs              # Mathematical proof tests
โ”‚   โ”œโ”€โ”€ bench/                          # NLP evaluation suites
โ”‚   โ”œโ”€โ”€ Coq/Minimalist.v               # Machine-verified proofs
โ”‚   โ”œโ”€โ”€ spec.md                         # Formal specification
โ”‚   โ”œโ”€โ”€ REPORT.md                       # Implementation analysis
โ”‚   โ”œโ”€โ”€ python/                         # ๐Ÿค– Probabilistic LM extension
โ”‚   โ”‚   โ”œโ”€โ”€ tiny_lm.py                 # Core probabilistic grammar
โ”‚   โ”‚   โ”œโ”€โ”€ hybrid_model.py            # Rust-Python bridge
โ”‚   โ”‚   โ””โ”€โ”€ api_server.py              # REST API server
โ”‚   โ””โ”€โ”€ examples/                       # ๐ŸŽฎ Demo applications
โ”‚       โ”œโ”€โ”€ language_model_demo.py     # Interactive demo
โ”‚       โ””โ”€โ”€ quick_example.py           # Simple usage example
โ””โ”€โ”€ flow/                          # ๐ŸŒŠ Claude-flow integration
    โ””โ”€โ”€ claude-flow/                    # AI orchestration platform

๐ŸŽฎ Try It Yourself

Basic Usage

# Generate recursive patterns
cargo run --release -- generate an_bn 5
# Output: a a a a a b b b b b

# Parse sentences  
cargo run --release -- parse "the student who left smiled"
# Shows parse tree and derivation steps

# Run mathematical tests
cargo test test_an_bn_generation
cargo test test_recursive_capability

Advanced Features

# Run linguistic evaluation suites
cargo test --release agreement_suite
cargo test --release colorless_green_suite

# Performance benchmarking
cargo test --release run_complete_benchmark

# Formal verification (requires Coq)
cd Coq && coqc Minimalist.v

๐Ÿงช What This Proves

This implementation demonstrates that:

  1. Recursive universal grammar is implementable in extremely constrained environments
  2. Mathematical theory and practical engineering can be unified effectively
  3. Formal verification and empirical testing provide complementary validation
  4. Chomsky's insights about recursion remain relevant for modern AI systems

๐Ÿค Contributing

We welcome contributions! See Contributing Guidelines

Great starting points:

  • ๐Ÿ“– Improve documentation and examples
  • ๐Ÿงช Add more linguistic test cases
  • โšก Optimize performance and memory usage
  • ๐Ÿ”ฌ Extend Coq formalization
  • ๐ŸŒ Test on additional languages

๐Ÿ“„ Citation

If you use this work in research, please cite:

@software{atomic_language_model,
  title={Atomic Language Model: Recursive Universal Grammar in 50kB},
  author={Atomic Language Model Team},
  year={2024},
  url={https://github.com/user/atomic-lang-model}
}

๐Ÿ“œ License

MIT License - see LICENSE for details.

๐ŸŒŸ Acknowledgments

Built on the mathematical foundations of:

  • Noam Chomsky: Recursive language theory and Minimalist Grammar
  • Edward Stabler: Formal implementation of Minimalist Grammars
  • Linzen et al.: Agreement test methodology
  • Gulordava et al.: Colorless green evaluation framework

๐Ÿ“– Navigation

Glossary of Concepts โ†’ A comprehensive A-Z guide to all key terms and concepts in the documentation

Built with mathematical rigor. Validated through empirical testing. Optimized for practical use.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

45 stars

Watchers

2 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors