A PyTorch model generator from YAML configurations
Project description
Neural Machines (neuralm)
neuralm is a Python/PyTorch package that generates PyTorch models from YAML configuration files. It focuses on neural architecture modeling, allowing users to create various types of PyTorch models without writing boilerplate code. The resulting Pytorch models can be translated into ONNX format for deployment or interoperability with other frameworks. In the era of agentic-AI, and vibe coding, this package can be used to streamline coding operations, and make things easier for human researchers and practicioners. It is also a good tool for learning neural networks.
Table of Contents
- Installation
- Features
- Usage
- Supported Model Types
- Supported Layer Types
- Advanced Usage
- Contributing
- License
- Citing neuralm
Installation
pip install neuralm
Or install from source:
git clone https://github.com/IgorSadoune/neuralm.git
cd neuralm
pip install -e .
Features
- Generate PyTorch models from YAML configuration files
- Support for various model architectures (see below)
- Support custom model
- Allow for building Transformers via attention type model
- Flexible layer configuration
- Allow for saving and reusing custom layers via neuralm LayerFactory
- Provide extensive documentation and use case to get started
- Provide extensive documentation for learning neural network model arhcitecture
Usage
Basic Usage
from neuralm import build_model_from_yaml
# Build a model from a YAML file
model = build_model_from_yaml('model_config.yaml')
# Use the model like any PyTorch model
output = model(input_data)
Example YAML Configuration: Creating GANs
model_type: gan
name: MyGAN
latent_size: 100
generator_layers:
- type: linear
in_features: 100
out_features: 256
is_first: true
- type: relu
- type: linear
in_features: 256
out_features: 512
- type: relu
- type: linear
in_features: 512
out_features: 784
- type: sigmoid
discriminator_layers:
- type: linear
in_features: 784
out_features: 512
- type: leakyrelu
negative_slope: 0.2
- type: linear
in_features: 512
out_features: 256
- type: leakyrelu
negative_slope: 0.2
- type: linear
in_features: 256
out_features: 1
- type: sigmoid
Note that model_type and layers are required fields.
Programmatic Model Building
You can also build models programmatically using a configuration dictionary:
from neuralpy import build_model_from_config
config = {
'model_type': 'sequential',
'layers': [
{'type': 'linear', 'in_features': 784, 'out_features': 128},
{'type': 'relu'},
{'type': 'linear', 'in_features': 128, 'out_features': 10}
]
}
model = build_model_from_config(config)
Error Handling
neuralm provides detailed error messages when there are issues with your configuration:
- Missing required keys
- Unsupported model types or layer types
- Invalid parameter values
- Inconsistent layer dimensions
Make sure to check the error messages if you encounter any issues.
Supported Model Types
sequential: The most general model type to build anythingmlp: The building block, Multi-layer perceptron are simple feedforward networks with fully connected layers that can process any type of data, but not as efficiently as specialized architecturesrnn,lstm,gru: Recurrent neural networks for processing sequential data like text or time seriescnn1d,cnn2d,cnn3d: Convolutional neural networks for processing data with spatial patterns (1D signals, images, videos)attention: Attention-based models (e.g., Transformers) that focus on relevant parts of the input dataautoencoder,vae: Models that learn to compress data and reconstruct it, useful for dimensionality reduction or data encodinggan: Generative adversarial networks that can create new data similar to training examplessiamese: Networks with two identical subnetworks used to compare two inputs, great for similarity tasksgnn: Graph neural networks for processing data represented as graphs (coming soon)rbm: Restricted Boltzmann machines, generative stochastic networks for unsupervised learning (coming soon)
Supported Layer Types
Linear Layers
linear: Fully connected layer
- type: linear
in_features: 784
out_features: 128
bias: true # Optional, default is true
Convolutional Layers
conv1d,conv2d,conv3d: Convolutional layers
Example:
- type: conv2d
in_channels: 3
out_channels: 16
kernel_size: 3
stride: 1 # Optional, default is 1
padding: 1 # Optional, default is 0
dilation: 1 # Optional, default is 1
groups: 1 # Optional, default is 1
bias: true # Optional, default is true
padding_mode: zeros # Optional, default is 'zeros'
Pooling Layers
maxpool1d,maxpool2d,maxpool3d: Max pooling layersavgpool1d,avgpool2d,avgpool3d: Average pooling layers
Example:
- type: maxpool2d
kernel_size: 2
stride: 2 # Optional, default is kernel_size
padding: 0 # Optional, default is 0
dilation: 1 # Optional, default is 1
ceil_mode: false # Optional, default is false
Recurrent Layers
rnn: Simple RNN layerlstm: LSTM layergru: GRU layer
Example:
- type: lstm
input_size: 300
hidden_size: 256
num_layers: 2 # Optional, default is 1
bias: true # Optional, default is true
batch_first: true # Optional, default is false
dropout: 0.2 # Optional, default is 0
bidirectional: true # Optional, default is false
Normalization Layers
batchnorm1d,batchnorm2d,batchnorm3d: Batch normalization layerslayernorm: Layer normalizationinstancenorm1d,instancenorm2d,instancenorm3d: Instance normalization layers
Example:
- type: batchnorm2d
num_features: 16
eps: 1e-5 # Optional, default is 1e-5
momentum: 0.1 # Optional, default is 0.1
affine: true # Optional, default is true
track_running_stats: true # Optional, default is true
Dropout Layers
dropout,dropout2d,dropout3d: Dropout layers
Example:
- type: dropout
p: 0.5 # Optional, default is 0.5
inplace: false # Optional, default is false
Activation Layers
relu,leakyrelu,prelu,elu,selu,celu,gelu: ReLU and variantssigmoid: Sigmoid activationtanh: Tanh activationsoftmax: Softmax activationlogsoftmax: LogSoftmax activation
Example:
- type: relu
inplace: false # Optional, default is false
Attention Layers
multiheadattention: Multi-head attention layerselfattention: Self-attention layer
Example:
- type: multiheadattention
embed_dim: 512
num_heads: 8
dropout: 0.1 # Optional, default is 0
bias: true # Optional, default is true
batch_first: true # Optional, default is false
Other Layers
embedding: Embedding layerflatten: Flatten layerreshape: Reshape layer
Advanced Usage
For advanced user case please refer to the tutorial.
Contributing
Contributions are welcome! If you wish to contribute to the project read the the contributing guidelines and contact me (igor.sadoune@pm.me).
License
This project is licensed under the MIT License - see the LICENSE file for details.
Citing neuralm
If you use this software in your work, please cite neuralm:
@software{neuralm,
author = {Sadoune, Igor},
title = {NeuralM: A Neural Network Model Builder},
year = {2025},
url = {https://github.com/IgorSadoune/neuralm},
version = {0.1.0},
publisher = {GitHub},
description = {A flexible framework for building and training neural network models with YAML configuration.}
}
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 neuralm-0.1.1.tar.gz.
File metadata
- Download URL: neuralm-0.1.1.tar.gz
- Upload date:
- Size: 26.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
326c5fc26286e68926a71d044dd2c79de45711a51d9c26496230f7cf30a35698
|
|
| MD5 |
33adb90ba39a53704ad6d5280c679796
|
|
| BLAKE2b-256 |
75e94ecc33c7a4f8a8ee8099244ee38c71d613d33ab9150bd22c985e1cd2abbf
|
File details
Details for the file neuralm-0.1.1-py3-none-any.whl.
File metadata
- Download URL: neuralm-0.1.1-py3-none-any.whl
- Upload date:
- Size: 21.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79d56e68b47cc8cde9ddc5b746e9d4b61f51a5b9d39c8610ecd887c37854ce27
|
|
| MD5 |
578df7ece54dd85c3796fc9903e05dfc
|
|
| BLAKE2b-256 |
c6ec0944852a0424563e9236d623cec0c666dc5afe5e2c24c6a133321b3a0bfa
|