<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mazid Osseni on Medium]]></title>
        <description><![CDATA[Stories by Mazid Osseni on Medium]]></description>
        <link>https://medium.com/@mazido?source=rss-e3afa9dd37eb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*G1XyTukRu41-TIxCySHkwg.jpeg</url>
            <title>Stories by Mazid Osseni on Medium</title>
            <link>https://medium.com/@mazido?source=rss-e3afa9dd37eb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 15 Nov 2026 15:02:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mazido/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Different types of regularization On Neuronal Network with Pytorch]]></title>
            <link>https://medium.com/data-science/different-types-of-regularization-on-neuronal-network-with-pytorch-a9d6faf4793e?source=rss-e3afa9dd37eb------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9d6faf4793e</guid>
            <category><![CDATA[l1]]></category>
            <category><![CDATA[sparsity]]></category>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Mazid Osseni]]></dc:creator>
            <pubDate>Mon, 06 May 2019 13:15:40 GMT</pubDate>
            <atom:updated>2019-05-06T13:16:06.088Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>Implementation of regularization tools in pyTorch</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JG9jwKZh-uHTJG_bdtgpvg.jpeg" /><figcaption>Image by <a href="https://pixabay.com/users/geralt-9301/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=3098693">Gerd Altmann</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=3098693">Pixabay</a></figcaption></figure><p>I was doing some research about <em>sparsity</em> in neuronal network framework and I came around the article “<a href="https://www.sciencedirect.com/science/article/pii/S0925231217302990."><em>Group sparse regularization for deep neural networks</em></a><em>”. This paper </em>addressed the challenging task of simultaneously optimizing (i) the weights of a neural network, (ii) the number of neurons for each hidden layer, and (iii) the subset of active input features (i.e., feature selection). They essentially proposed an integration of <em>lasso penalties </em>in the regularization framework in the neuronal network. There is plenty of posts and extensive research on the definition and the importance of <em>regularization. </em>For example these posts<em> </em><a href="https://towardsdatascience.com/l1-and-l2-regularization-methods-ce25e7fc831c"><em>[1]</em></a><em> </em>and<em> </em><a href="https://towardsdatascience.com/over-fitting-and-regularization-64d16100f45c"><em>[2]</em></a><em> </em>are a quick introduction to the<em> regularization </em>subject.</p><p>In order to reproduce the experiments in “<a href="https://www.sciencedirect.com/science/article/pii/S0925231217302990."><em>Group sparse regularization for deep neural networks</em></a><em>”</em>,<em> </em>I<em> </em>decided to build my project using <a href="https://pytorch.org/">PyTorch</a> which is a well known deep learning framework. According to Medium, this is the <a href="https://medium.com/the-mission/8-best-deep-learning-frameworks-for-data-science-enthusiasts-d72714157761">4th</a> best deep learning framework. It is gaining more and more popularity in academic levels since it’s easily modulable to test new ideas faster than most of its competitors.</p><p>I realize there is not such tools available to do any kind of regularization unless the L2-regularization. In pyTorch, the L2 is implemented in the “<em>weight decay</em>” option of the <em>optimizer</em> unlike <a href="https://github.com/Lasagne/Lasagne/tree/master/lasagne"><em>Lasagne</em></a><em> (another deep learning framework), </em>that makes available the L1 and L2 regularization in their built-in implementation. You can find a lot of <a href="https://discuss.pytorch.org/t/simple-l2-regularization/139/2"><em>proposed solutions</em> </a>explaining how to implement the L1 regularization using the pyTorch framework but there is not easy implementation tool available to plug in your experimentation.</p><p>To compensate this absence, I decided to build some <em>“ready to use” </em>regularization object using the pyTorch framework. The implementation can be found <a href="https://github.com/dizam92/pyTorchReg/blob/master/src/regularization/regularizer.py"><em>here</em></a>. I implemented the <a href="https://github.com/dizam92/pyTorchReg/blob/5ad3ca0a0cc7561741871a4135c2c08bc0bbef6c/src/regularization/regularizer.py#L21">L1</a> regularization , the classical <a href="https://github.com/dizam92/pyTorchReg/blob/5ad3ca0a0cc7561741871a4135c2c08bc0bbef6c/src/regularization/regularizer.py#L44">L2 </a>regularization, the <a href="https://github.com/dizam92/pyTorchReg/blob/5ad3ca0a0cc7561741871a4135c2c08bc0bbef6c/src/regularization/regularizer.py#L67">ElasticNet</a> regularization (L1 + L2), the <a href="https://github.com/dizam92/pyTorchReg/blob/5ad3ca0a0cc7561741871a4135c2c08bc0bbef6c/src/regularization/regularizer.py#L124">GroupLasso</a> regularization and a more restrictive penalty the <a href="https://github.com/dizam92/pyTorchReg/blob/5ad3ca0a0cc7561741871a4135c2c08bc0bbef6c/src/regularization/regularizer.py#L99">SparseGroupLasso</a>, introduced in <em>Group sparse regularization for deep neural networks.</em></p><p>The class object is built to have the pyTorch <em>model as a parameter. </em>We can apply the regularization penalty on specific <em>parameter</em> weights or on all the weights of every layer in the model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lB2rOFbuy6pJOZxdrYmCog.png" /><figcaption>Base model of regularizer object</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gvR6A1x89cEwav_dZUqUhw.png" /><figcaption>Example of implementation of the L1 regularizer</figcaption></figure><p>I applied these implementations in the case of a fully connected neuronal network. This is the most simple suited model architecture to see the impact of the different types of regularization on the model performances.</p><p>Like the original article, I tested the implementation on the <a href="https://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_digits.html">Digits</a> dataset which represents an image classification problem. It is composed of 1797 8 × 8 grey images of handwritten digits collected from several dozens different people. I used a simple fully connected neural network with two hidden layers having respectively 40 and 20 neurons.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WzelW6dOP90dnT_LSgChGQ.png" /><figcaption>Results Performances with different type of regularization applied to the simple FC model</figcaption></figure><p>Looking at the results we can see that the <strong>L2-regularized </strong>model and the <strong>Weight Decay regularized</strong> model have the same performances on the test set. This is pretty good and what we expected since the <strong>Weight Decay</strong> is the L2 implementation already proposed by pyTorch. The sparser methods (L1-regularized and GL-regularized models) perfom quite well too but they are not better than the <strong>Weight Decay regularized</strong> model. We can now look at the real sparsity of the model. To study this we fixed that weights under 10e-3 in absolute value are set to 0. And then we analyzed all the % of sparsity of the neurons in each model. The % of sparsity is calculated by taking the number of neuron that have all their weights summed up at 0 and divide that number by the size of each layer. As expected, the <strong>L1-regularized</strong> model have sparser density than the <strong>L2-regularized </strong>model. But the performance still look great in this case. Sometimes, too much sparsity is not good for the model too.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xIHWju0DmLkQpKiARTAGWQ.png" /></figure><p>In conclusion I made available a built-in and adaptable implementation of different type of regularization options. I tested all the regularization on a simpler fully connected model on the Digits datasets in order to see the performance between the different regularizer. We can see that sparsity in those case still perform pretty well on the task. The next step is to see how we can extend the <a href="https://github.com/dizam92/pyTorchReg">pyTorchReg</a> module to other model architecture.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9d6faf4793e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/different-types-of-regularization-on-neuronal-network-with-pytorch-a9d6faf4793e">Different types of regularization On Neuronal Network with Pytorch</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>