BareBonesNN is a lightweight neural network library implemented from scratch in Python, without relying on high-level machine learning libraries. This project aims to provide a clear and fundamental understanding of neural network concepts and operations, making it an excellent educational resource for learning and experimentation.
- Basic Neural Network Components: Core classes including
Value
,Neuron
,Layer
, andMLP
(Multi-Layer Perceptron). - Automatic Differentiation: Built-in backpropagation for gradient computation.
- Customisable and Extensible: Easily modify and extend the code to experiment with various neural network architectures.
- Lightweight: Minimal dependencies, focusing on core principles.
To install BareBonesNN, use pip:
pip install barebonesnn==0.1.1
Here is a basic example demonstrating how to create and use a simple neural network using BareBonesNN:
from barebonesnn import Value, MLP
# Create a simple MLP with 3 input neurons and layers with [4, 4, 1] neurons
mlp = MLP(3, [4, 4, 1])
# Example input
x = [Value(1.0), Value(2.0), Value(3.0)]
# Forward pass
output = mlp(x)
print("Output:", output)
# Backward pass
output.backward()
# Inspect gradients
for param in mlp.parameters():
print(param.label, param.grad)
barebonesnn/value.py
: Contains theValue
class, which represents a value in a computational graph.barebonesnn/neuron.py
: Contains theNeuron
class, representing a single neuron.barebonesnn/layer.py
: Contains theLayer
class, representing a layer of neurons.barebonesnn/mlp.py
: Contains theMLP
class, representing a multi-layer perceptron.
Represents a value in a computational graph, supporting basic operations and automatic differentiation.
Represents a single neuron in a neural network, with a set of weights and a bias.
Represents a layer in a neural network, consisting of multiple neurons.
Represents a multi-layer perceptron, consisting of multiple layers.
The examples/
directory contains scripts demonstrating various usages of the library. To run an example:
python examples/example.py
Contributions are welcome! If you have suggestions, bug reports, or feature requests, please open an issue or submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.