← 开源
haifengl

smile

Statistical Machine Intelligence & Learning Engine

Model DevelopmentClassical MLJava
在 GitHub 打开
增长势头
+024 小时新增 Star0.0%
6.42k
Star
1.15k
Fork
+0
本周
57
贡献者
创建于 2014-11-20 · 更新于 2026-10-10 · 今日第 6466 名
主要开发者
README

Statistical Machine Intelligence & Learning Engine SMILE

Maven Central CI CodeQL

SMILE (Statistical Machine Intelligence & Learning Engine) is a comprehensive, high-performance machine learning framework for the JVM. SMILE v5+ requires Java 25; v4.x requires Java 21; all previous versions require Java 8. SMILE also provides idiomatic APIs for Scala and Kotlin. With advanced data structures and algorithms, SMILE delivers state-of-the-art performance across every aspect of machine learning.

SMILE Serve is a production-ready inference server that brings together three complementary inference capabilities on the JVM:

Capability API prefix Description
Classic ML /api/v1/smile Serialized SMILE models (.sml) — classifiers and regressors
ONNX Runtime /api/v1/onnx Any model in the ONNX open format (.onnx)
LLM Chat /api/v1/chat/completions OpenAI-compatible chat completions

A React-based web UI is bundled and served from the same process. See serve/README.md how to build and run the service.

SMILE Studio is an agentic IDE for data science using Python, Java, or Scala. See studio/README.md how to get your first project up and start interacting with your data with natural language in a few minutes.


Table of Contents

  1. Features
  2. Module Map
  3. Installation
  4. Quick Start
  5. SMILE Studio & Shell
  6. Model Serialization
  7. Visualization
  8. License
  9. Issues & Discussions
  10. Contributing
  11. Maintainers
  12. Gallery

Features

Area Highlights
LLM LLaMA-3 inference, tiktoken BPE tokenizer, OpenAI-compatible REST server, SSE chat streaming
Deep Learning LibTorch/GPU backend, EfficientNet-V2 image classification, custom layer API
Classification SVM, Decision Trees, Random Forest, AdaBoost, Gradient Boosting, Logistic Regression, Neural Networks, RBF Networks, MaxEnt, KNN, Naïve Bayes, LDA/QDA/RDA
Regression SVR, Gaussian Process, Regression Trees, GBDT, Random Forest, RBF, OLS, LASSO, ElasticNet, Ridge
Clustering BIRCH, CLARANS, DBSCAN, DENCLUE, Deterministic Annealing, K-Means, X-Means, G-Means, Neural Gas, Growing Neural Gas, Hierarchical, SIB, SOM, Spectral, Min-Entropy
Manifold Learning IsoMap, LLE, Laplacian Eigenmap, t-SNE, UMAP, PCA, Kernel PCA, Probabilistic PCA, GHA, Random Projection, ICA
Feature Engineering Genetic Algorithm selection, Ensemble selection, TreeSHAP, SNR, Sum-Squares ratio, data transformations, formula API
NLP Sentence / word tokenization, Bigram test, Phrase & Keyword extraction, Stemmer, POS tagging, Relevance ranking
Association Rules FP-growth frequent itemset mining
Sequence Learning Hidden Markov Model, Conditional Random Field
Nearest Neighbor BK-Tree, Cover Tree, KD-Tree, SimHash, LSH
Numerical Methods Linear algebra, numerical optimization (BFGS, L-BFGS), interpolation, wavelets, RBF, distributions, hypothesis tests
Visualization Swing plots (scatter, line, bar, box, histogram, surface, heatmap, contour, …) and declarative Vega-Lite charts

Module Map

Each module has its own detailed user guide. Click the README link for the module overview, or drill into individual topic guides.

base/ — Foundation

Data structures, math, linear algebra, statistical utilities, I/O

Document Topics
README Module overview and dependency setup
DATA_FRAME.md DataFrame API — creation, selection, transformation
DATA_IO.md CSV, JSON, Parquet, Arrow, JDBC, Avro readers/writers
DATA_TRANSFORMATION.md Scalers, encoders, imputers, feature transforms
DATASET.md Built-in benchmark and real-world datasets
FORMULA.md R-style formula language for model matrices
DISTRIBUTIONS.md Probability distributions (Normal, Poisson, Beta, …)
HYPOTHESIS_TESTING.md t-test, chi-squared, ANOVA, KS-test, …
DISTANCES.md Euclidean, Mahalanobis, Hamming, edit distance, …
NEAREST_NEIGHBOR.md KD-Tree, Cover Tree, BK-Tree, LSH
KERNELS.md Gaussian, polynomial, Laplacian, and other kernel functions
RBF.md Radial basis function networks
INTERPOLATION.md Linear, cubic spline, bilinear, bicubic
GRAPH.md Adjacency list/matrix graph, BFS/DFS, spanning trees
SORT.md Quick sort, heap sort, counting sort, index sort
HASH.md Locality-sensitive hashing, SimHash
RNG.md Random number generators, sampling, permutations
BFGS.md L-BFGS and BFGS numerical optimizers
ICA.md Independent Component Analysis
TENSOR.md N-dimensional array (CPU tensor without LibTorch)
WAVELET.md DWT, CWT, and wavelet families
GAP.md GAP statistic for optimal cluster count estimation
COMPRESSED_SENSING.md Compressed sensing and basis pursuit

core/ — Machine Learning Algorithms

Classification, regression, clustering, manifold learning, and more

Document Topics
README Module overview
CLASSIFICATION.md SVM, Random Forest, AdaBoost, GBDT, KNN, Naïve Bayes, LDA, …
REGRESSION.md SVR, Gaussian Process, LASSO, Ridge, ElasticNet, GBDT, …
CLUSTERING.md K-Means, DBSCAN, BIRCH, SOM, Spectral Clustering, …
FEATURE_ENGINEERING.md Feature selection, PCA, ICA, projection, encoding
MANIFOLD.md t-SNE, UMAP, IsoMap, LLE, Laplacian Eigenmap
ANOMALY_DETECTION.md IsolationForest, one-class SVM, local outlier factor
ASSOCIATION_RULE_MINING.md FP-growth, association rules, frequent itemsets
SEQUENCE.md HMM (Baum-Welch, Viterbi), CRF
TIME_SERIES.md ARIMA, box-plots, autocorrelation
REGRESSION.md Full regression API reference
TRAINING.md Cross-validation, bootstrap, hyper-parameter search
VALIDATION.md Hold-out, k-fold, leave-one-out evaluation
VALIDATION_METRICS.md Accuracy, AUC, F1, RMSE, MAE, confusion matrix
HYPER_PARAMETER_OPTIMIZATION.md Grid search, random search, Bayesian optimization
VECTOR_QUANTIZATION.md LVQ, Neural Gas, SOM as vector quantizers

deep/ — Deep Learning & LLMs

LibTorch-backed GPU/CPU tensor operations, neural network layers, LLaMA-3 inference, EfficientNet, ONNX Runtime & GenAI

Document Topics
README Core deep-learning guide (tensors, layers, loss, optimizer, model, metrics, data loading)
LLM.md smile.llm — tokenizer, LLaMA-3, Qwen3.5, inference engine, KV cache, quantization, tensor parallelism
VISION.md smile.vision — transforms, ImageDataset, EfficientNet-V2, ImageNet labels
ONNX.md ONNX Runtime inference (smile.onnx) — sessions, tensors, execution providers
ONNX_GENAI.md ONNX Runtime GenAI (smile.onnx.genai) — generate loop, chat model, multimodal

The deep/README.md covers:

  • smile.deep.tensor — Tensor factory, indexing, arithmetic, AutoScope memory management, dtype/device
  • smile.deep.layer — Linear, Conv2d, pooling, normalization (BN/GN/RMS), dropout, embedding, sequential blocks
  • smile.deep.activation — ReLU, GELU, SiLU, Tanh, Sigmoid, Softmax, GLU, HardShrink, …
  • smile.deep.Loss — MSE, cross-entropy, BCE, Huber, KL, hinge, and more
  • smile.deep.Optimizer — SGD, Adam, AdamW, RMSprop
  • smile.deep.Model — Abstract base class + training loop
  • smile.deep.metric — Accuracy, Precision, Recall, F1Score with macro/micro/weighted averaging
  • smile.deep.Dataset — Dataset interface, DataSampler, SampleBatch

The deep/LLM.md covers:

  • smile.llm — Message, Role, FinishReason, ChatCompletion, ChatOptions, LanguageModel
  • smile.llm.tokenizer — Tokenizer interface, Tiktoken BPE implementation (LLaMA-3 compatible)
  • smile.llm.model.llama — Full LLaMA-3 stack: Llama.build(), generate(), chat(), streaming
  • smile.llm.model.qwen — Qwen3.5 hybrid stack (Gated DeltaNet + gated attention), MTP, vision tower
  • smile.llm.engine — Continuous-batching InferenceEngine, GenerationRequest/GenerationHandle, speculative decoding
  • smile.llm.cache — Paged KvCachePool, RadixCache prefix reuse
  • smile.llm.quant / smile.llm.parallel — FP8/NVFP4/Marlin quantization, tensor parallelism

The deep/VISION.md covers:

  • smile.vision — VisionModel, ImageDataset, EfficientNet.V2S/M/L() pretrained models, ImageNet labels
  • smile.vision.transform — Transform interface, ImageClassification pipeline, resize/crop/toTensor helpers

nlp/ — Natural Language Processing

Text normalization, tokenization, POS tagging, stemming, relevance ranking

Document Topics
README Module overview
TOKENIZER.md Sentence splitter, word tokenizer, regex tokenizer
POS.md Part-of-speech tagging (Brill tagger, HMM tagger)
STEM.md Porter, Lancaster, Lovins stemmers; lemmatization
COLLOCATION.md Bigram/trigram statistical tests, phrase extraction
RELEVANCE.md TF-IDF, BM25, keyword extraction
TAXONOMY.md WordNet integration, synsets, hypernyms

plot/ — Data Visualization

Swing-based interactive plots and declarative Vega-Lite charts

Document Topics
README Swing plotting API — scatter, line, bar, box, histogram, heatmap, surface, contour, wireframe
VEGA.md Declarative smile.plot.vega (Vega-Lite) — JSON spec generation, web/Jupyter rendering

serve/ — Inference Server

Quarkus-based REST inference service with OpenAI-compatible API and SSE streaming

Document Topics
README Building and running the server, /chat/completions endpoint, SSE streaming, configuration

studio/ — Interactive Shell & Desktop IDE

An agentic IDE for data science using Python or SMILE

Document Topics
README.md Desktop Studio UX
CLI CLI entry points (smile, smile shell, smile scala, smile serve)

scala/ — Scala API

Idiomatic Scala shim — concise wrappers, symbolic operators, Scala collections integration

Document Topics
README API overview, smile.classification, smile.regression, smile.clustering, smile.plot in Scala

kotlin/ — Kotlin API

Idiomatic Kotlin shim — extension functions, named parameters, builder DSLs

Document Topics
README API overview, extension functions, Kotlin-style builders
packages.md Full package-by-package listing of all Kotlin extension functions

json/ — JSON Library (Scala)

Lightweight zero-dependency JSON library for Scala with a clean DSL

Document Topics
README Parsing, building, pattern matching, path navigation, serialization

spark/ — Apache Spark Integration

Use SMILE models inside Spark ML pipelines

Document Topics
README SmileTransformer, SmileClassifier, SmileRegressor; training and scoring in Spark DataFrames

Installation

Maven



  com.github.haifengl
  smile-core
  7.0.0




  com.github.haifengl
  smile-deep
  7.0.0




  com.github.haifengl
  smile-nlp
  7.0.0




  com.github.haifengl
  smile-plot
  7.0.0

SBT (Scala)

libraryDependencies += "com.github.haifengl" %% "smile-scala" % "7.0.0"

Gradle (Kotlin)

dependencies {
    implementation("com.github.haifengl:smile-kotlin:7.0.0")
}

Native Libraries (BLAS / LAPACK)

Several algorithms (manifold learning, Gaussian Process, MLP, some clustering) require BLAS and LAPACK.

Linux (Ubuntu / Debian)

sudo apt update
sudo apt install libopenblas-dev libarpack2-dev

macOS (Homebrew)

brew install arpack

Do not rely on DYLD_LIBRARY_PATH: macOS System Integrity Protection (SIP) strips DYLD_* variables when the JVM is started through the /usr/bin/java stub, so dyld never sees them. SMILE reaches libarpack through the FFM bindings, whose SymbolLookup.libraryLookup("arpack") calls dlopen on the bare name libarpack.dylib; this does not consult java.library.path, so -Djava.library.path=... and LD_LIBRARY_PATH have no effect either. SMILE therefore preloads the library by absolute path through smile.linalg.NativeLibrary, which finds it under /opt/homebrew/lib or /usr/local/lib with no copy or symlink. To point it somewhere else, set the arpack.native.path system property or the ARPACK_NATIVE_PATH environment variable.

Windows — pre-built DLLs are included in the bin/ directory of the release package. Add that directory to PATH.

GPU (CUDA) — make sure the LibTorch CUDA native libraries are on PATH (Windows) or LD_LIBRARY_PATH (Linux).


Quick Start

import smile.classification.RandomForest;
import smile.data.formula.Formula;
import smile.io.Read;

// Load data
var data = Read.csv("src/test/resources/iris.csv");

// Train a random forest
var forest = RandomForest.fit(Formula.lhs("species"), data);

// Predict
int label = forest.predict(data.get(0));
System.out.println("Predicted class: " + label);

For deep learning examples, see deep/README.md; for LLM and computer-vision examples, see deep/LLM.md and deep/VISION.md. For visualization examples, see plot/README.md.


SMILE Studio

SMILE Studio is an agentic IDE for data science using Python or SMILE on JVM. See studio/README.md for full documentation.

Download a pre-packaged release from the releases page, then:

path/to/smile/bin/setup      # install required native dependencies
path/to/smile/bin/smile      # launch SMILE Studio from your project directory

Other entry points:

Command Description
smile Desktop agentic IDE
smile shell Java REPL with all SMILE packages pre-imported
smile scala Scala REPL
smile train Train a supervised learning model
smile predict Predict on a file using a saved model
smile serve Start the LLM inference server

To increase the JVM heap:

path/to/smile/bin/smile -J-Xmx30G

Model Serialization

Most SMILE models implement java.io.Serializable. You can serialize a trained model to disk and load it in a production environment or inside a Spark job:

// Save
try (var out = new ObjectOutputStream(new FileOutputStream("model.ser"))) {
    out.writeObject(forest);
}

// Load
try (var in = new ObjectInputStream(new FileInputStream("model.ser"))) {
    var loaded = (RandomForest) in.readObject();
}

Visualization

SMILE provides two visualization layers:

  • smile.plot.swing — Swing-based interactive 2D/3D plots. See plot/README.md.
  • smile.plot.vega — Declarative Vega-Lite charts for browsers and Jupyter. See plot/VEGA.md.

  com.github.haifengl
  smile-plot
  7.0.0


License

SMILE employs a modern multi-product licensing model designed to support free academic and open-source collaboration while offering commercial licensing and enterprise support for proprietary and mission-critical deployments. For details, see LICENSE. To acquire a commercial license, contact sales@aihalo.dev.


Issues & Discussions

Channel Purpose
GitHub Discussions Questions, ideas, show-and-tell
Stack Overflow [smile] Technical Q&A
Issue Tracker Bug reports and feature requests
Online Docs Tutorials and programming guides
Java API · Scala API · Kotlin API · Clojure API API Javadoc

Contributing

Please read CONTRIBUTING.md for build and test instructions.


Maintainers


Gallery

    [![SPLOM](/website/src/images/splom.png)](/website/src/images/splom.png)

Scatterplot Matrix

    [![Scatter](/website/src/images/pca.png)](/website/src/images/pca.png)

Scatter Plot

    [![Heart](/website/src/images/heart.png)](/website/src/images/heart.png)

Line Plot

    [![Surface](/website/src/images/surface.png)](/website/src/images/surface.png)

Surface Plot

    [![Scatter](/website/src/images/bar.png)](/website/src/images/bar.png)

Bar Plot

    [![Box Plot](/website/src/images/box.png)](/website/src/images/box.png)

Box Plot

    [![Histogram](/website/src/images/histogram2d.png)](/website/src/images/histogram2d.png)

Histogram Heatmap

    [![Rolling](/website/src/images/rolling.png)](/website/src/images/rolling.png)

Rolling Average

    [![Map](/website/src/images/map.png)](/website/src/images/map.png)

Geo Map

    [![UMAP](/website/src/images/umap.png)](/website/src/images/umap.png)

UMAP

    [![Text](/website/src/images/text.png)](/website/src/images/text.png)

Text Plot

    [![Contour](/website/src/images/contour.png)](/website/src/images/contour.png)

Heatmap with Contour

    [![Hexmap](/website/src/images/hexmap.png)](/website/src/images/hexmap.png)

Hexmap

    [![IsoMap](/website/src/images/isomap.png)](/website/src/images/isomap.png)

IsoMap

    [![LLE](/website/src/images/lle.png)](/website/src/images/umap.png)

LLE

    [![Kernel PCA](/website/src/gallery/smile-demo-kpca-small.png)](/website/src/gallery/smile-demo-kpca.png)

Kernel PCA

    [![Neural Network](/website/src/gallery/smile-demo-ann-small.png)](/website/src/gallery/smile-demo-ann.png)

Neural Network

    [![SVM](/website/src/gallery/smile-demo-svm-small.png)](/website/src/gallery/smile-demo-svm.png)

SVM

    [![Hierarchical Clustering](/website/src/gallery/smile-demo-agglomerative-clustering-small.png)](/website/src/gallery/smile-demo-agglomerative-clustering.png)

Hierarchical Clustering

    [![SOM](/website/src/gallery/smile-demo-som-small.png)](/website/src/gallery/smile-demo-som.png)

SOM

    [![DBSCAN](/website/src/gallery/smile-demo-dbscan-small.png)](/website/src/gallery/smile-demo-dbscan.png)

DBSCAN

    [![Neural Gas](/website/src/gallery/smile-demo-neural-gas-small.png)](/website/src/gallery/smile-demo-neural-gas.png)

Neural Gas

    [![Wavelet](/website/src/gallery/smile-demo-wavelet-small.png)](/website/src/gallery/smile-demo-wavelet.png)

Wavelet

    [![Mixture](/website/src/gallery/smile-demo-mixture-small.png)](/website/src/gallery/smile-demo-mixture.png)

Exponential Family Mixture

    [![Teapot](/website/src/images/teapot.png)](/website/src/images/teapot.png)

Teapot Wireframe

    [![Interpolation](/website/src/images/grid-interpolation2d.png)](/website/src/images/grid-interpolation2d.png)

Grid Interpolation