Tensors + gradients
Two-dimensional float32 tensors, built-in model gradient calculations, and tests that check gradient accuracy.
0.6.0-alpha · Java 20+
Learn, train, and inspect GPT-, Llama-, and DeepSeek-style decoder models without leaving the JVM. Run anywhere on CPU or opt into Metal on Apple Silicon.
Install
Add DeepJ to a Java 20 or newer project. The published release includes binary, source, and Javadoc artifacts.
View the artifact on Maven Central<dependency>
<groupId>io.github.kirstenali</groupId>
<artifactId>deepj</artifactId>
<version>0.6.0-alpha</version>
</dependency>
Core library
DeepJ keeps the path from tensor math to text generation visible, with focused APIs and no hidden Python runtime.
Two-dimensional float32 tensors, built-in model gradient calculations, and tests that check gradient accuracy.
Compact GPT-, Llama-, and DeepSeek-style decoder architectures behind a shared causal-LM API.
UTF-8 byte tokenization plus trainable, persistent byte-level BPE with special-token support.
AdamW, cosine schedules, gradient clipping, evaluation, checkpoints, and bounded-memory datasets.
A pure Java CPU backend runs everywhere; the optional Metal backend accelerates Apple Silicon.
Versioned DeepJ model bundles include weights, tokenizer, configuration, and a model card.
Quick start
The checkpoint and configuration must describe the same architecture. Swap in a trained BPE tokenizer when loading a BPE-trained model.
See the repository guideTokenizer tokenizer = new ByteTokenizer();
DeepSeekConfig config = new DeepSeekConfig(
tokenizer.vocabSize(), 128, 64, 4, 2, 256, 32, 16);
DeepSeekModel model = new DeepSeekModel(config, 42L);
model.load(Path.of("model.dj"));
String text = TextGenerator.generate(
model, tokenizer, config, "Once upon a time", 80, 0.8f, 20, 42L);
Architectures
GPT-style
Learned positions, causal multi-head attention, LayerNorm, and GELU feed-forward layers.
Llama-style
Rotary position embeddings, causal multi-head attention, RMSNorm, and SwiGLU layers.
DeepSeek-style
Low-rank query and key/value projections with RoPE, RMSNorm, and SwiGLU.
These are compact educational architectures, not drop-in reproductions of the official GPT, Llama, or DeepSeek releases.
Published model
A 1.3M-parameter DeepJ model trained from scratch, published with its BPE tokenizer, configuration, model card, and native DeepJ weights.
Know the edges