How to build a Recurrent Network using PyBrain

This recipe helps you build a Recurrent Network using PyBrain

Recipe Objective - How to build a Recurrent Network using PyBrain?

Recurrent networks are similar to the feed-through network; the only difference is that you must remember the data at each step. The history of each step must be saved.

For more related projects -

https://www.projectpro.io/projects/data-science-projects/deep-learning-projects
https://www.projectpro.io/projects/data-science-projects/keras-deep-learning-projects

Let's try to build a recurrent network -

# Importing libraries
from pybrain.structure import RecurrentNetwork
from pybrain.structure import LinearLayer, SigmoidLayer
from pybrain.structure import FullConnection

# Building feed forward network model
recurrent_network = RecurrentNetwork()

# Making layer for input => 3 , hidden=> 3 and output=>1
input_layer = LinearLayer(3)
hidden_layer = SigmoidLayer(3)
output_layer = LinearLayer(1)

# Adding the layer to feedforward network
recurrent_network.addInputModule(input_layer)
recurrent_network.addModule(hidden_layer)
recurrent_network.addOutputModule(output_layer)

# Making connection between input ,hidden and output
input_to_hidden = FullConnection(input_layer, hidden_layer)
hidden_to_output = FullConnection(hidden_layer, output_layer)

# Adding connection to the network
recurrent_network.addConnection(input_to_hidden)
recurrent_network.addConnection(hidden_to_output)

# Add recurrent connection from hidden to hidden layers
recurrent_network.addRecurrentConnection(FullConnection(hidden_layer, hidden_layer))

# Sorting modules
recurrent_network.sortModules()

# Printing network
print(recurrent_network)

# Activating network by passing 3 input values
print("Output => ",recurrent_network.activate((1, 1, 1)))

# Clearing the history of the network by calling reset method
recurrent_network.reset()

Output -
RecurrentNetwork-7
   Modules:
    [<LinearLayer 'LinearLayer-4'>, <SigmoidLayer 'SigmoidLayer-8'>, <LinearLayer 'LinearLayer-9'>]
   Connections:
    [<FullConnection 'FullConnection-5': 'LinearLayer-4' -> 'SigmoidLayer-8'>, <FullConnection 'FullConnection-6': 'SigmoidLayer-8' -> 'LinearLayer-9'>]
   Recurrent Connections:
    [<FullConnection 'FullConnection-3': 'SigmoidLayer-8' -> 'SigmoidLayer-8'>]
Output =>  [0.1918294]

In this way, we can build a recurrent network using pybrain.

What Users are saying..

profile image

Jingwei Li

Graduate Research assistance at Stony Brook University
linkedin profile url

ProjectPro is an awesome platform that helps me learn much hands-on industrial experience with a step-by-step walkthrough of projects. There are two primary paths to learn: Data Science and Big Data.... Read More

Relevant Projects

Model Deployment on GCP using Streamlit for Resume Parsing
Perform model deployment on GCP for resume parsing model using Streamlit App.

Credit Card Fraud Detection as a Classification Problem
In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

Loan Eligibility Prediction using Gradient Boosting Classifier
This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.

Build Real Estate Price Prediction Model with NLP and FastAPI
In this Real Estate Price Prediction Project, you will learn to build a real estate price prediction machine learning model and deploy it on Heroku using FastAPI Framework.

Census Income Data Set Project-Predict Adult Census Income
Use the Adult Income dataset to predict whether income exceeds 50K yr based oncensus data.

Build a Multi-Class Classification Model in Python on Saturn Cloud
In this machine learning classification project, you will build a multi-class classification model in Python on Saturn Cloud to predict the license status of a business.

Hands-On Approach to Regression Discontinuity Design Python
In this machine learning project, you will learn to implement Regression Discontinuity Design Example in Python to determine the effect of age on Mortality Rate in Python.

Build a Graph Based Recommendation System in Python -Part 1
Python Recommender Systems Project - Learn to build a graph based recommendation system in eCommerce to recommend products.

Multi-Class Text Classification with Deep Learning using BERT
In this deep learning project, you will implement one of the most popular state of the art Transformer models, BERT for Multi-Class Text Classification

Build an AI Quiz Generator from Video with OpenAI API
In this LLM project, you will build a model to automate the transcription of video content and generate interactive quizzes using OpenAI’s Whisper and GPT-4o.

OSZAR »