https://github.com/sql-hkr/syna
Syna is a lightweight machine learning framework inspired by DeZero.
https://github.com/sql-hkr/syna
framework machine-learning reinforcement-learning
Last synced: about 1 month ago
JSON representation
Syna is a lightweight machine learning framework inspired by DeZero.
- Host: GitHub
- URL: https://github.com/sql-hkr/syna
- Owner: sql-hkr
- License: mit
- Created: 2025-10-06T13:17:50.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-10-26T01:19:06.000Z (8 months ago)
- Last Synced: 2026-01-18T16:44:01.919Z (5 months ago)
- Topics: framework, machine-learning, reinforcement-learning
- Language: Python
- Homepage: https://sql-hkr.github.io/syna/
- Size: 228 KB
- Stars: 17
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Syna




Syna is a lightweight machine learning framework inspired by [DeZero](https://github.com/oreilly-japan/deep-learning-from-scratch-3). Built from scratch using only NumPy, it follows a define-by-run (dynamic computation graph) approach and includes a basic reinforcement learning framework.
Unlike most frameworks that implement reinforcement learning as a separate library, Syna provides everything in a single library.
Designed for beginners and researchers, Syna helps you learn the fundamentals of machine learning and the inner workings of frameworks like [PyTorch](https://github.com/pytorch/pytorch). Performance is not the focus, and GPU support is intentionally omitted to keep the code simple and easy to understand.
## Installation
Get the Syna Source
```bash
git clone https://github.com/sql-hkr/syna.git
cd syna
uv venv
source .venv/bin/activate
uv sync
```
Or, from [PyPI](https://pypi.org/project/syna/):
```bash
uv add syna
```
> [!IMPORTANT]
> To visualize the computation graph, you need to install [Graphviz](https://graphviz.org).
> ```bash
> brew install graphviz # macOS
> sudo apt install graphviz # Linux
> ```
## Getting started
### Computation Graph
Visualize the computation graph for the fifth derivative of tanh(x) with respect to x.
```python
import syna
import syna.functions as F
from syna import utils
x = syna.tensor(1.0)
y = F.tanh(x)
x.name = "x"
y.name = "y"
y.backward(create_graph=True)
iters = 4
for i in range(iters):
gx = x.grad
x.cleargrad()
gx.backward(create_graph=True)
gx = x.grad
gx.name = "gx" + str(iters + 1)
utils.viz.plot_dot_graph(gx, verbose=False, to_file="tanh.svg")
```
The output graph is shown below.

### RL (Deep Q-Network; DQN)
Solve CartPole-v1 using the DQN algorithm.
```python
from syna.algo.dqn import DQNAgent
from syna.utils.rl import Trainer
trainer = Trainer(
env_name="CartPole-v1",
num_episodes=300,
agent=DQNAgent(
lr=3e-4,
),
)
trainer.train()
```
## API Reference
- [syna package](https://sql-hkr.github.io/syna/api/syna.html)
## License
Syna is licensed under the MIT License. See [LICENSE](LICENSE) for details.