Manuscript Offprint

arXiv:2610.22529

Pearl-Chat: Engineering a native Luganda language model from first principles in JAX and Flax NNX

Wesley Kambale, Roland Sankara

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Wesley Kambale1,∗^{1,*} and Roland Sankara2^{2}

1^{1}AI for Uganda Initiative, 2^{2}ISBAT University

Autoregressive foundation language models predominantly target high-resource Indo-European languages, imposing severe computational and morphological penalties on under-represented African languages. Generic multilingual tokenizers routinely suffer from high fertility rates exceeding 3.2 tokens per word on agglutinative Bantu languages, degrading context efficiency and inflating inference latency. This paper presents Pearl-Chat, an 8,473,122-parameter (~8.5M) causal decoder-only transformer engineered specifically for Luganda (Oluganda, ISO 639-2: lg), a low-resource Niger-Congo Bantu language spoken by over 10 million people in East Africa. Built from first mathematical principles in JAX and Flax NNX, Pearl-Chat avoids monolithic black-box abstractions, demonstrating explicit functional state decomposition (nnx.split and nnx.merge), deterministic resumable data streaming through Google Grain, and SPMD tensor parallelism using jax.sharding.Mesh. We introduce a custom byte-level byte-pair encoding (BPE) subword tokenizer trained from scratch on curated Luganda corpora (V = 8,192), achieving a compression ratio of 4.88 characters per token and a sequence fertility of 1.60 tokens per word. This represents a two-fold compression improvement over LLaMA-3 (128K) and Gemma (256K). The model is trained using a two-stage curriculum: Stage 1 foundational pre-training on 59,501 sequence records across parallel, biblical, encyclopedic, and journalistic corpora, followed by Stage 2 conversational instruction fine-tuning on 510 dialogues with assistant-only loss masking. During training across 4,000 optimization steps, cross-entropy validation loss drops monotonically from an uninitialized baseline of 9.4695 (perplexity: 12,958.98) to 0.1818 (perplexity: 1.20), yielding an absolute decrease of 9.2877 nats. In a three-tier held-out diagnostic benchmark, Pearl-Chat achieves a held-out ROUGE-L of 0.9792 and BLEU of 0.9405 while demonstrating grammatical concordial agreement across Bantu noun classes. We provide a lightweight Python Server-Sent Events (SSE) streaming runtime and open-source all weights, tokenizers, and interactive environments to establish an open engineering standard for African language model research.

Keywords: Natural language processing, low-resource languages, Bantu morphology, Luganda, JAX, Flax NNX, byte-level BPE, functional neural state, two-stage curriculum, open science.

1. Introduction

The global landscape of natural language processing exhibits a severe digital divide [1]. Despite the existence of over 7,000 living spoken languages worldwide, more than 95% of contemporary large language model compute, pre-training token volume, and architectural optimization focus on a small subset of high-resource Indo-European languages [2–4]. The African continent, representing over 2,000 distinct languages and 1.4 billion people, remains under-represented in modern foundation model architectures [5, 6].

Among East African languages, Luganda (Oluganda, ISO 639-2: lg) is a major Niger-Congo language of the Narrow Bantu branch (JE.15), spoken by more than 10 million people across Uganda and the northern Lake Victoria basin [7, 8]. Luganda exhibits rich agglutinative verbal morphology, an extensive noun-class system comprising 23 distinct nominal genders with alliterative concordial agreement, phonemic vowel length, and consonant gemination. When state-of-the-art multilingual language models such as LLaMA-3 [4], GPT-4 [9], or Gemma [10] process Luganda text, they encounter what is recognized in multilingual and African NLP research as the tokenizer tax [6, 11]. Because their massive vocabularies ( V∈[128K,256K]V \in [128K, 256K]) are trained predominantly on English, European, and East Asian text, Luganda words are fragmented into isolated characters or arbitrary byte sequences. This fragmentation inflates token fertility to between 3.2 and 3.9 tokens per word, truncating effective context length, inflating inference costs by up to 400%, and degrading semantic representations [11, 12].

Simultaneously, machine learning engineering has become heavily reliant on monolithic, stateful frameworks. PyTorch abstractions frequently rely on implicit object mutation, hidden runtime hooks, and imperative graph interception that obscure the underlying mathematical formulation of deep learning [13, 14]. In contrast, the JAX ecosystem formulates deep learning as composable mathematical function transformations:

f:(θ,x)↦(y^,θ′)f:(\theta,x)\mapsto(\hat{y},\theta^{\prime})

leveraging Accelerated Linear Algebra (XLA) compilation, functional gradient transformations (jax.grad), automatic vectorization (jax.vmap), and declarative Single Program Multiple Data (SPMD) distributed tensor sharding (jax.sharding.Mesh) [13].

In this work, we present Pearl-Chat, an autoregressive

∗^{*}Corresponding author: kambale@aiforuganda.org

© 2026 AI for Uganda Initiative. All rights reserved.

decoder-only language model engineered from first mathematical principles specifically for Luganda, developed as part of the advanced research track at PyCon Africa 2026 [15]. Pearl-Chat is implemented in JAX and Flax NNX, eliminating third-party modeling abstractions and PyTorch dependencies.

The core contributions of this work are summarized as follows:

  1. Linguistically aligned native tokenizer: We train a custom byte-level BPE tokenizer (V = 8, 192) from scratch on native Luganda text, achieving a compression ratio of 4.88 characters per token and a sequence fertility of 1.60 tokens per word. This reduces sequence lengths by more than half compared to frontier multilingual models.

  2. JAX and Flax NNX architecture: We implement an 8.5M-parameter GPT-2 style transformer incorporating Pre-Layer Normalization, GELU activations, and parameter-efficient embedding weight tying, explicitly managing functional state through nnx.split and nnx.merge.

  3. Deterministic resumable streaming: We integrate Google Grain for preemption-resilient, deterministic data loading across four heterogeneous Luganda datasets totaling over 59,500 curated sequences.

  4. Two-stage optimization curriculum: We formulate a two-stage training curriculum combining Stage 1 foundational causal pre-training with Stage 2 assistant-masked conversational instruction tuning using Optax AdamW and cosine decay.

  5. Empirical verification and serving: We validate Pearl-Chat across a three-tier diagnostic benchmark (achieving a held-out ROUGE-L of 0.9792 and BLEU of 0.9405) and deploy a lightweight Server-Sent Events (SSE) streaming runtime published openly on GitHub and the Hugging Face Hub.

References (41)