A declarative ML language that compiles to real PyTorch code
Project description
🧠 Synapse Language
A declarative, human-friendly programming language for Machine Learning — compiles to real PyTorch code.
✨ What is Synapse?
Instead of writing 50+ lines of complex PyTorch code, you write this:
tensor x = [[1,2],[3,4]]
model TestNet:
layer dense(8, relu)
layer dense(4, sigmoid)
train TestNet on x:
epochs = 2
lr = 0.001
Synapse reads it, understands it, and trains a real neural network. That's it.
🚀 Why Synapse?
- Beginners can build neural networks without learning PyTorch boilerplate
- Researchers can prototype models in seconds
- Teachers can explain ML concepts with clean, readable syntax
- Developers can write ML code that reads like plain English
⚙️ How It Works
Your .syn file
↓
Lexer reads your code word by word
↓
Parser understands the structure
↓
Transpiler writes real PyTorch Python
↓
Runtime executes it and shows results
📦 Installation
1. Clone the repo
git clone https://github.com/YOUR_USERNAME/synapse-lang.git
cd synapse-lang
2. Create a virtual environment
# Mac/Linux
python -m venv venv
source venv/bin/activate
# Windows
python -m venv venv
venv\Scripts\activate
3. Install PyTorch (CPU)
pip install torch --index-url https://download.pytorch.org/whl/cpu
▶️ Running Synapse
Run a program
python synapse.py run examples/test.syn
See generated Python code
python synapse.py transpile examples/test.syn
See the token stream
python synapse.py tokenize examples/test.syn
See the AST
python synapse.py parse examples/test.syn
Run with full pipeline trace
python synapse.py run examples/test.syn --verbose
📝 Language Reference
Tensor Declaration
tensor mydata = [[1, 2, 3], [4, 5, 6]]
Model Declaration
model MyModel:
layer dense(64, relu)
layer dense(32, relu)
layer dense(10, sigmoid)
Train Block
train MyModel on mydata:
epochs = 10
lr = 0.001
optimizer = adam
loss = mse
Supported Layers
| Synapse | PyTorch |
|---|---|
dense |
nn.LazyLinear |
dropout |
nn.Dropout |
flatten |
nn.Flatten |
conv2d |
nn.LazyConv2d |
batchnorm |
nn.LazyBatchNorm1d |
Supported Activations
relu · sigmoid · tanh · softmax · gelu · selu · leakyrelu
Supported Optimizers
adam · sgd · adamw · rmsprop
Supported Loss Functions
mse · crossentropy · bce · l1 · huber
📁 Project Structure
synapse/
├── synapse.py # CLI entry point
├── lexer.py # Tokenizer
├── parser.py # Recursive-descent parser
├── ast_nodes.py # AST node class hierarchy
├── transpiler.py # AST → PyTorch transpiler
├── runtime.py # Execution engine
├── requirements.txt
├── README.md
└── examples/
├── test.syn # Basic example
├── advanced.syn # Multi-layer example
└── myfirst.syn # Demo example
🧪 Example Output
Running examples/test.syn:
Training TestNet for 2 epoch(s)...
Epoch 1/2 --- loss: 0.000000
Epoch 2/2 --- loss: 0.000000
Training complete.
Generated Python (via python synapse.py transpile examples/test.syn):
import torch
import torch.nn as nn
import torch.optim as optim
x = torch.tensor([[1, 2], [3, 4]], dtype=torch.float32)
class TestNet(nn.Module):
def __init__(self):
super(TestNet, self).__init__()
self.network = nn.Sequential(
nn.LazyLinear(8),
nn.ReLU(),
nn.LazyLinear(4),
nn.Sigmoid(),
)
def forward(self, x):
return self.network(x)
def main():
_model = TestNet()
_criterion = nn.MSELoss()
_optimizer = optim.Adam(_model.parameters(), lr=0.001)
# ... training loop
🔮 Roadmap
- Web playground (write Synapse in the browser)
- VS Code extension with syntax highlighting
- AI blocks — plug in LLMs with one line
- Memory system — vector stores and retrieval
- Multi-model pipelines
- PyPI package (
pip install synapse-lang)
🤝 Contributing
Pull requests are welcome! Here's how to add a new feature:
- Add a node class in
ast_nodes.py - Add a parse rule in
parser.py - Add a
visit_<NodeName>method intranspiler.py
That's all — the architecture handles the rest.
📄 License
MIT License — free to use, modify, and distribute.
👨💻 Author
Built with ❤️ — a declarative ML language for everyone.
"Synapse makes AI accessible — not just for people who memorised PyTorch." Update README with full documentation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file synapse_lang_core-1.0.0.tar.gz.
File metadata
- Download URL: synapse_lang_core-1.0.0.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1d2354232f1aeffc08d610f1da27a21f0331ebb0b3ec1fe01909cb9b09cb79e
|
|
| MD5 |
f4d78451dc5085b568dfb13a1073bb8d
|
|
| BLAKE2b-256 |
47d96fb17d91236407565f806b49e5935f01551849312b04171f59fcd8cfa2bf
|
Provenance
The following attestation bundles were made for synapse_lang_core-1.0.0.tar.gz:
Publisher:
publish.yml on maxew6/synapse-lang
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
synapse_lang_core-1.0.0.tar.gz -
Subject digest:
e1d2354232f1aeffc08d610f1da27a21f0331ebb0b3ec1fe01909cb9b09cb79e - Sigstore transparency entry: 1293424229
- Sigstore integration time:
-
Permalink:
maxew6/synapse-lang@9caa4385255d7114e8a8a6bc52a7a3c990743534 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/maxew6
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9caa4385255d7114e8a8a6bc52a7a3c990743534 -
Trigger Event:
release
-
Statement type:
File details
Details for the file synapse_lang_core-1.0.0-py3-none-any.whl.
File metadata
- Download URL: synapse_lang_core-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0dbd0f8369939856d88f1848e233202dbcd02643829415b34f2fccb60e184322
|
|
| MD5 |
0f94143d81f8b51ead08f3878d93c30b
|
|
| BLAKE2b-256 |
53668fcac3790e784c53cfd116daa6207714dca59873b3b0fa2f8c0b7bf3c41c
|
Provenance
The following attestation bundles were made for synapse_lang_core-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on maxew6/synapse-lang
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
synapse_lang_core-1.0.0-py3-none-any.whl -
Subject digest:
0dbd0f8369939856d88f1848e233202dbcd02643829415b34f2fccb60e184322 - Sigstore transparency entry: 1293424253
- Sigstore integration time:
-
Permalink:
maxew6/synapse-lang@9caa4385255d7114e8a8a6bc52a7a3c990743534 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/maxew6
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9caa4385255d7114e8a8a6bc52a7a3c990743534 -
Trigger Event:
release
-
Statement type: