A plug-and-play library for neural networks written in Python

Overview

Synapses

A plug-and-play library for neural networks written in Python!

# run
pip install synapses-py==7.4.1
# in the directory of your project

Neural Network

Create a neural network

Import Synapses, call NeuralNetwork.init and provide the size of each layer.

from synapses_py import NeuralNetwork, ActivationFunction, DataPreprocessor, Statistics
layers = [4, 6, 5, 3]
neuralNetwork = NeuralNetwork.init(layers)

neuralNetwork has 4 layers. The first layer has 4 input nodes and the last layer has 3 output nodes. There are 2 hidden layers with 6 and 5 neurons respectively.

Get a prediction

inputValues = [1.0, 0.5625, 0.511111, 0.47619]
prediction = \
        NeuralNetwork.prediction(neuralNetwork, inputValues)

prediction should be something like [ 0.8296, 0.6996, 0.4541 ].

Note that the lengths of inputValues and prediction equal to the sizes of input and output layers respectively.

Fit network

learningRate = 0.5
expectedOutput = [0.0, 1.0, 0.0]
fitNetwork = \
        NeuralNetwork.fit(
            neuralNetwork,
            learningRate,
            inputValues,
            expectedOutput
        )

fitNetwork is a new neural network trained with a single observation.

To train a neural network, you should fit with multiple datapoints

Create a customized neural network

The activation function of the neurons created with NeuralNetwork.init, is a sigmoid one. If you want to customize the activation functions and the weight distribution, call NeuralNetwork.customizedInit.

def activationF(layerIndex):
    if layerIndex == 0:
        return ActivationFunction.sigmoid
    elif layerIndex == 1:
        return ActivationFunction.identity
    elif layerIndex == 2:
        return ActivationFunction.leakyReLU
    else:
        return ActivationFunction.tanh

def weightInitF(_layerIndex):
    return 1.0 - 2.0 * random()

customizedNetwork = \
        NeuralNetwork.customizedInit(
            layers,
            activationF,
            weightInitF
        )

Visualization

Call NeuralNetwork.toSvg to take a brief look at its svg drawing.

Network Drawing

The color of each neuron depends on its activation function while the transparency of the synapses depends on their weight.

svg = NeuralNetwork.toSvg(customizedNetwork)

Save and load a neural network

JSON instances are compatible across platforms! We can generate, train and save a neural network in Python and then load and make predictions in Javascript!

toJson

Call NeuralNetwork.toJson on a neural network and get a string representation of it. Use it as you like. Save json in the file system or insert into a database table.

json = NeuralNetwork.toJson(customizedNetwork)

ofJson

loadedNetwork = NeuralNetwork.ofJson(json)

As the name suggests, NeuralNetwork.ofJson turns a json string into a neural network.

Encoding and decoding

One hot encoding is a process that turns discrete attributes into a list of 0.0 and 1.0. Minmax normalization scales continuous attributes into values between 0.0 and 1.0. You can use DataPreprocessor for datapoint encoding and decoding.

The first parameter of DataPreprocessor.init is a list of tuples (attributeName, discreteOrNot).

setosaDatapoint = {
    "petal_length": "1.5",
    "petal_width": "0.1",
    "sepal_length": "4.9",
    "sepal_width": "3.1",
    "species": "setosa"
}

versicolorDatapoint = {
    "petal_length": "3.8",
    "petal_width": "1.1",
    "sepal_length": "5.5",
    "sepal_width": "2.4",
    "species": "versicolor"
}

virginicaDatapoint = {
    "petal_length": "6.0",
    "petal_width": "2.2",
    "sepal_length": "5.0",
    "sepal_width": "1.5",
    "species": "virginica"
}

datasetList = [ setosaDatapoint,
                versicolorDatapoint,
                virginicaDatapoint ]

dataPreprocessor = \
        DataPreprocessor.init(
             [ ("petal_length", False),
               ("petal_width", False),
               ("sepal_length", False),
               ("sepal_width", False),
               ("species", True) ],
             iter(datasetList)
        )

encodedDatapoints = map(lambda x:
        DataPreprocessor.encodedDatapoint(dataPreprocessor, x),
        datasetList
)

encodedDatapoints equals to:

[ [ 0.0     , 0.0     , 0.0     , 1.0     , 0.0, 0.0, 1.0 ],
  [ 0.511111, 0.476190, 1.0     , 0.562500, 0.0, 1.0, 0.0 ],
  [ 1.0     , 1.0     , 0.166667, 0.0     , 1.0, 0.0, 0.0 ] ]

Save and load the preprocessor by calling DataPreprocessor.toJson and DataPreprocessor.ofJson.

Evaluation

To evaluate a neural network, you can call Statistics.rootMeanSquareError and provide the expected and predicted values.

expectedWithOutputValuesList = \
        [ ( [ 0.0, 0.0, 1.0], [ 0.0, 0.0, 1.0] ),
          ( [ 0.0, 0.0, 1.0], [ 0.0, 1.0, 1.0] ) ]

expectedWithOutputValuesIter = \
        iter(expectedWithOutputValuesList)

rmse = Statistics.rootMeanSquareError(
                        expectedWithOutputValuesIter
)
Owner
Dimos Michailidis
Dimos Michailidis
Author's PyTorch implementation of TD3 for OpenAI gym tasks

Addressing Function Approximation Error in Actor-Critic Methods PyTorch implementation of Twin Delayed Deep Deterministic Policy Gradients (TD3). If y

Scott Fujimoto 1.3k Dec 25, 2022
Pytorch implementation of VAEs for heterogeneous likelihoods.

Heterogeneous VAEs Beware: This repository is under construction 🛠️ Pytorch implementation of different VAE models to model heterogeneous data. Here,

Adrián Javaloy 35 Nov 29, 2022
A large-scale video dataset for the training and evaluation of 3D human pose estimation models

ASPset-510 ASPset-510 (Australian Sports Pose Dataset) is a large-scale video dataset for the training and evaluation of 3D human pose estimation mode

Aiden Nibali 36 Oct 30, 2022
Discriminative Region Suppression for Weakly-Supervised Semantic Segmentation

Discriminative Region Suppression for Weakly-Supervised Semantic Segmentation (AAAI 2021) Official pytorch implementation of our paper: Discriminative

Beom 74 Dec 27, 2022
Database Reasoning Over Text project for ACL paper

Database Reasoning over Text This repository contains the code for the Database Reasoning Over Text paper, to appear at ACL2021. Work is performed in

Facebook Research 320 Dec 12, 2022
Weight initialization schemes for PyTorch nn.Modules

nninit Weight initialization schemes for PyTorch nn.Modules. This is a port of the popular nninit for Torch7 by @kaixhin. ##Update This repo has been

Alykhan Tejani 69 Jan 26, 2021
[NeurIPS'21] Shape As Points: A Differentiable Poisson Solver

Shape As Points (SAP) Paper | Project Page | Short Video (6 min) | Long Video (12 min) This repository contains the implementation of the paper: Shape

394 Dec 30, 2022
3D-Transformer: Molecular Representation with Transformer in 3D Space

3D-Transformer: Molecular Representation with Transformer in 3D Space

55 Dec 19, 2022
ESPNet: Efficient Spatial Pyramid of Dilated Convolutions for Semantic Segmentation

ESPNet: Efficient Spatial Pyramid of Dilated Convolutions for Semantic Segmentation This repository contains the source code of our paper, ESPNet (acc

Sachin Mehta 515 Dec 13, 2022
A crash course in six episodes for software developers who want to become machine learning practitioners.

Featured code sample tensorflow-planespotting Code from the Google Cloud NEXT 2018 session "Tensorflow, deep learning and modern convnets, without a P

Google Cloud Platform 2.6k Jan 08, 2023
Facial expression detector

A tensorflow convolutional neural network model to detect facial expressions.

Carlos Tardón Rubio 5 Apr 20, 2022
InferPy: Deep Probabilistic Modeling with Tensorflow Made Easy

InferPy: Deep Probabilistic Modeling Made Easy InferPy is a high-level API for probabilistic modeling written in Python and capable of running on top

PGM-Lab 141 Oct 13, 2022
Time should be taken seer-iously

TimeSeers seers - (Noun) plural form of seer - A person who foretells future events by or as if by supernatural means TimeSeers is an hierarchical Bay

279 Dec 26, 2022
Code for the AI lab course 2021/2022 of the University of Verona

AI-Lab Code for the AI lab course 2021/2022 of the University of Verona Set-Up the environment for the curse Download Anaconda for your System. Instal

Davide Corsi 5 Oct 19, 2022
Seq2seq - Sequence to Sequence Learning with Keras

Seq2seq Sequence to Sequence Learning with Keras Hi! You have just found Seq2Seq. Seq2Seq is a sequence to sequence learning add-on for the python dee

Fariz Rahman 3.1k Dec 18, 2022
Deep learning with dynamic computation graphs in TensorFlow

TensorFlow Fold TensorFlow Fold is a library for creating TensorFlow models that consume structured data, where the structure of the computation graph

1.8k Dec 28, 2022
LUKE -- Language Understanding with Knowledge-based Embeddings

LUKE (Language Understanding with Knowledge-based Embeddings) is a new pre-trained contextualized representation of words and entities based on transf

Studio Ousia 587 Dec 30, 2022
MOpt-AFL provided by the paper "MOPT: Optimized Mutation Scheduling for Fuzzers"

MOpt-AFL 1. Description MOpt-AFL is a AFL-based fuzzer that utilizes a customized Particle Swarm Optimization (PSO) algorithm to find the optimal sele

172 Dec 18, 2022
This is the official Pytorch implementation of "Lung Segmentation from Chest X-rays using Variational Data Imputation", Raghavendra Selvan et al. 2020

README This is the official Pytorch implementation of "Lung Segmentation from Chest X-rays using Variational Data Imputation", Raghavendra Selvan et a

Raghav 42 Dec 15, 2022
Framework web SnakeServer.

SnakeServer - Framework Web 🐍 Documentação oficial do framework SnakeServer. Conteúdo Sobre Como contribuir Enviar relatórios de segurança Pull reque

Jaedson Silva 0 Jul 21, 2022