
Security News
Astral Launches pyx: A Python-Native Package Registry
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
🎓 Welcome to AI4R
Current version: 2.0
Your Lightweight Lab for AI and Machine Learning in Ruby.
AI4R isn’t just another machine learning library. It’s a learning playground. No black boxes and no bulky dependencies—just clean, readable Ruby implementations of core AI algorithms so you can explore, modify and really understand how they work.
AI4R is distributed as a gem and requires Ruby 3.2 or later.
Install the gem using RubyGems:
gem install ai4r
Add the library to your code:
require 'ai4r'
A quick map to AI4R’s built‑in toolkits, grouped by type. Each folder comes with examples and benchmark runners so you can dive right in.
“Meet your future coworker / overlord.”
This is not a full GPT—but it is the core logic, stripped down and readable.
AI4R ships with a bite-sized, dependency-free Transformer implementation that supports:
📂 Code: lib/ai4r/neural_network/transformer.rb
Docs: Transformer guide
💡 Try this:
Load up the transformer and walk through a simple forward pass.
Everything from attention weights to layer normalization is short enough to read and understand in one go.
"What’s the most likely outcome?"
You’ll find in lib/ai4r/classifiers/:
ZeroR
, OneR
– the simplest baselinesLogisticRegression
, SimpleLinearRegression
SupportVectorMachine
RandomForest
, GradientBoosting
MultilayerPerceptron
Docs: logistic_regression.md, random_forest.md
Try this: run compare_all.rb
to benchmark classifiers on real datasets.
"What belongs together?"
Includes in lib/ai4r/clusterers/:
KMeans
DBSCAN
Hierarchical
clustering variantsTry this: cluster the Iris dataset using both KMeans and DBSCAN.
"What if we build a brain?"
Code: lib/ai4r/neural_network/
Try this: open transformer.rb
and trace each step—it’s short enough to grok in one sitting.
"What’s the best path?"
You’ll find in lib/ai4r/search/:
BreadthFirst
, DepthFirst
, IterativeDeepening
A*
MonteCarloTreeSearch
Docs: search_algorithms.md
Try this: run A* and DFS on a maze and time the difference.
"Let’s mutate our way to a better answer."
Code: lib/ai4r/genetic_algorithm/
Try this: tweak the mutation rate in the TSP example.
"Reward me, and I’ll improve."
Code: lib/ai4r/reinforcement/
Docs: docs/reinforcement_learning.md
Try this: run a grid‑world training loop and watch the agent build its own policy.
"You can’t see the states—but you can infer them."
Code: lib/ai4r/hmm/hidden_markov_model.rb
Docs: docs/hmm.md
Try this: model a weather prediction problem with hidden states and visible activities.
"Can we project complex data onto a simpler map?"
Code: lib/ai4r/som/
Try this: reduce high‑dimensional vectors into a 2D neuron grid and color it based on class.
Each algorithm family has a benchmark runner:
bench/classifier/
bench/clusterer/
bench/search/
Shared tools in bench/common/
make it easy to run head‑to‑head comparisons, track runtime, accuracy and more, and output clean reports.
Docs: docs/benches_overview.md
Try this: run bench/search/astar_vs_dfs.rb
and explain why A* usually wins.
git clone https://github.com/SergioFierens/ai4r
cd ai4r
bundle install
ruby bench/classifier/compare_all.rb
This library is maintained for the joy of it (and perhaps a misplaced sense of duty to Ruby). You can do whatever you want with it—it’s unlicensed. If you build something cool or just find it useful, drop a note in the project's comments.
FAQs
Unknown package
We found that ai4r demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.