The Unified AI (UAI) specification defines a standard for implementing and managing feed-forward neural networks in web browsers. The reference implementation carbono
demonstrates this specification in practice.
carbono
is a lightweight, UAI-compatible feed-forward neural network implementation that provides a unified interface for training, inference, and model management. The UAI specification aims to establish a common web standard for managing feed-forward neural networks in browsers.
class carbono {
constructor(debug = true) {
this.layers = []; // Network layers configuration
this.weights = []; // Layer weights matrices
this.biases = []; // Layer biases vectors
this.details = {}; // Model metadata and training details
}
}
layers
: Array of layer configurations, each containing:inputSize
: Number of input nodesoutputSize
: Number of output nodesactivation
: Activation function identifier
weights
: Array of weight matrices for each layerbiases
: Array of bias vectors for each layerdetails
: Object containing model metadata and training information
- Dynamic layer addition via
layer(inputSize, outputSize, activation)
method - Automatic layer size validation between consecutive layers
- Xavier weight initialization for optimal training
- Support for various activation functions
- Forward propagation with cached layer inputs and outputs
- Backward propagation with comprehensive error computation
- Support for multiple optimization methods
- Early stopping capability
- Optional test set evaluation
- Training progress callbacks
- Stochastic Gradient Descent (SGD)
- Adam optimizer with momentum and adaptive learning rates
- β₁ = 0.9
- β₂ = 0.999
- ε = 1e-8
All activation functions must implement both forward pass and derivative:
tanh
: Hyperbolic tangentsigmoid
: Logistic functionrelu
: Rectified Linear Unitselu
: Scaled Exponential Linear Unitsoftmax
: Softmax function (for classification)
Each loss function must provide both loss calculation and derivative:
mse
: Mean Squared Errorcross-entropy
: Cross-Entropy Loss
- Binary Format (.uai)
- Header structure (Uint32Array):
- Metadata length
- Metadata padding
- Weight buffer length
- Bias buffer length
- Metadata section (JSON)
- Weight buffer (Float32Array)
- Bias buffer (Float32Array)
- JSON Format (.json)
- Complete model state in JSON format
- Includes weights, biases, layer configurations, and metadata
{
parameters: number, // Total number of parameters
training: {
loss: number, // Final training loss
testLoss: number, // Final test loss (if applicable)
time: number, // Training duration in ms
epochs: number, // Number of epochs trained
learningRate: number // Learning rate used
},
info: { // Optional model information
name: string,
author: string,
license: string,
note: string,
date: string
}
}
- Zero external dependencies
- Pure JavaScript implementation
- Web-first architecture
- Asynchronous operations support
- File system interaction via browser APIs
- Efficient matrix operations
- Automatic cleanup of optimization states
- Browser-friendly resource usage
- Proper TypedArray usage for binary operations
- Layer size validation
- Numerical stability checks
- Graceful fallbacks
- Comprehensive error messages
The .uai format is a binary file format optimized for neural network storage:
- Header Section (16 bytes)
[0-3] Uint32: Metadata length
[4-7] Uint32: Metadata padding
[8-11] Uint32: Weight buffer length
[12-15] Uint32: Bias buffer length
- Metadata Section
- JSON-encoded string containing:
{ layers: LayerConfig[], details: ModelMetadata, layerInfo: { weightShapes: number[][], biasShapes: number[] }, tags?: string[] // Optional for classification }
- Padded to 4-byte alignment
- Data Section
- Weight values (Float32Array)
- Bias values (Float32Array)
- Specification Version: 1.1
- Implementation Status: Production Ready
- Last Updated: January 15, 2025
- Reference Implementation: carbono.js
This specification defines the complete requirements for implementing UAI-compatible neural networks, with a focus on browser-based deployment and standardization.