What are the regularization functions in lasagne?

This recipe explains what are the regularization functions in lasagne.

Recipe Objective - What are the regularization functions in lasagne?

Lasagne provides "lasagne.regularization" class to apply regularization to the weights in a network.

Learn to Build a Multi Class Image Classification Model in Python from Scratch

Regularization Functions:-

1. lasagne.regularization.apply_penalty() - Computes the total cost for applying a specified penalty to a tensor or group of tensors.

2. lasagne.regularization.regularize_layer_params() - Computes a regularization cost by applying a penalty to the parameters of a layer or group of layers.

3. lasagne.regularization.regularize_layer_params_weighted() - Computes a regularization cost by applying a penalty to the parameters of a layer or group of layers.

4. lasagne.regularization.regularize_layer_params_weighted() - Computes a regularization cost by applying a penalty to the parameters of a layer or group of layers, weighted by a coefficient for each layer.

5. lasagne.regularization.l1(x) - Computes the L1 norm of a tensor.

6. lasagne.regularization.l2(x) - Computes the L2 norm of a tensor.

For more related projects:-

/projects/data-science-projects/deep-learning-projects
/projects/data-science-projects/tensorflow-projects

Example:-

import lasagne
import theano.tensor as T
import theano
from lasagne.nonlinearities import softmax
from lasagne.layers import InputLayer, DenseLayer, get_output
from lasagne.regularization import regularize_layer_params_weighted, l2, l1
from lasagne.regularization import regularize_layer_params
layer_in = InputLayer((100, 20))
layer_1 = DenseLayer(layer_in, num_units=3)
layer_2 = DenseLayer(layer1, num_units=5, nonlinearity=softmax)
x = T.matrix('x') # shp: num_batch x num_features
y = T.ivector('y') # shp: num_batch
ly_out = get_output(layer2, x)
loss = T.mean(T.nnet.categorical_crossentropy(ly_out, y))
layers = {layer_1: 0.1, layer_2: 0.5}
l2_penalty = regularize_layer_params_weighted(layers, l2)
l1_penalty = regularize_layer_params(layer2, l1) * 1e-4
loss = loss + l2_penalty + l1_penalty

loss

Elemwise{add,no_inplace}.0

What Users are saying..

profile image

Abhinav Agarwal

Graduate Student at Northwestern University
linkedin profile url

I come from Northwestern University, which is ranked 9th in the US. Although the high-quality academics at school taught me all the basics I needed, obtaining practical experience was a challenge.... Read More

Relevant Projects

Build a Langchain Streamlit Chatbot for EDA using LLMs
In this LLM project, you will build a Streamlit Chatbot integrated with Langchain technology for natural language interactions with a SQL database, facilitating real-time visualization and insightful insights, streamlining data exploration and analysis.

OpenCV Project to Master Advanced Computer Vision Concepts
In this OpenCV project, you will learn to implement advanced computer vision concepts and algorithms in OpenCV library using Python.

Linear Regression Model Project in Python for Beginners Part 2
Machine Learning Linear Regression Project for Beginners in Python to Build a Multiple Linear Regression Model on Soccer Player Dataset.

Topic modelling using Kmeans clustering to group customer reviews
In this Kmeans clustering machine learning project, you will perform topic modelling in order to group customer reviews based on recurring patterns.

Expedia Hotel Recommendations Data Science Project
In this data science project, you will contextualize customer data and predict the likelihood a customer will stay at 100 different hotel groups.

NLP Project on LDA Topic Modelling Python using RACE Dataset
Use the RACE dataset to extract a dominant topic from each document and perform LDA topic modeling in python.

Build a Graph Based Recommendation System in Python-Part 2
In this Graph Based Recommender System Project, you will build a recommender system project for eCommerce platforms and learn to use FAISS for efficient similarity search.

Customer Market Basket Analysis using Apriori and Fpgrowth algorithms
In this data science project, you will learn how to perform market basket analysis with the application of Apriori and FP growth algorithms based on the concept of association rule learning.

House Price Prediction Project using Machine Learning in Python
Use the Zillow Zestimate Dataset to build a machine learning model for house price prediction.

Build a Autoregressive and Moving Average Time Series Model
In this time series project, you will learn to build Autoregressive and Moving Average Time Series Models to forecast future readings, optimize performance, and harness the power of predictive analytics for sensor data.

OSZAR »