<?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 John Tzolas on Medium]]></title>
        <description><![CDATA[Stories by John Tzolas on Medium]]></description>
        <link>https://medium.com/@ioannis.g.tzolas?source=rss-a4d14a7246db------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*O6RYC4_A5h5ENJJT.</url>
            <title>Stories by John Tzolas on Medium</title>
            <link>https://medium.com/@ioannis.g.tzolas?source=rss-a4d14a7246db------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 12:48:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ioannis.g.tzolas/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[DQN Algorithm: A father-son tale]]></title>
            <link>https://medium.com/analytics-vidhya/dqn-algorithm-a-father-son-tale-b4bf6ff1ae2f?source=rss-a4d14a7246db------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4bf6ff1ae2f</guid>
            <category><![CDATA[reinforcement-learning]]></category>
            <category><![CDATA[deep-q-learning]]></category>
            <dc:creator><![CDATA[John Tzolas]]></dc:creator>
            <pubDate>Fri, 20 Mar 2020 16:41:15 GMT</pubDate>
            <atom:updated>2020-05-17T16:29:55.219Z</atom:updated>
            <content:encoded><![CDATA[<p>The Deep Q-Network (DQN) Reinforcement learning algorithm has a surprisingly simple and real life analogy with which it can be explained. It helps understand the sequence of operations involved by the algorithm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*SKPmItMuayIDYpxm" /><figcaption>Father walking with son</figcaption></figure><p>The algorithm can be conceptually understood via the following simple narrative which illustrates the evolution of training:</p><p>We have a FATHER and a SON (=&gt; 2 distinct neural networks)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*Xwcz_gYkjncBlaabk6sJgw.png" /></figure><p>0. The <strong>FATHER </strong>teaches the <strong>SON </strong>what he knows to be able to act independently in life. <strong>FATHER </strong>gives birth to <strong>SON</strong>.</p><p>1–2. The <strong>SON </strong>is found in current state and based on what he knows, he calculates Q-values for the actions he can take. I like to think that <strong>Q-</strong>values =<strong> Quality-</strong>values.</p><p>3–4. <strong>SON</strong> follows a policy and takes an action which brings him in next state.</p><p><em>Time for</em><strong><em> parental advice</em></strong><em>. The </em><strong><em>SON </em></strong><em>asks the </em><strong><em>FATHER </em></strong><em>what the value of his actions are.</em></p><p>5–6. The <strong>FATHER </strong>lets the <strong>SON </strong>know what the maximum Q-value of the state the son has been found is.</p><p>7. SON updates his weights/factors that affect him in his decisions based on FATHER input.</p><p>The epitomy of the training can be found in the following sentence the father tells to the son:</p><blockquote><em>‘I cannot tell you my </em><strong><em>SON </em></strong><em>if you have been right or wrong. The only thing that i can tell you is that with the actions you have taken in the states you have been found which have led you to new states, my experience as a </em><strong><em>FATHER </em></strong><em>tells me that the best you can gain is &lt;QMAX&gt; for your actions now onwards’.</em></blockquote><h4>8. After some time (years = episodes played by son receiving advice from father) the SON becomes himself a FATHER and next generation training carries on.</h4><p>The metaphor also supports the replay buffer notion in which most recent episodes are kept. This makes sense in an evolving system where knowledge is accumulated across generations and following generations need be updated and guided by most recent ones.</p><p>A pytorch based implementation of the algorithm as described above taking into account the notions of father, son, generation, etc can be found in : <a href="https://gist.github.com/igtzolas/8a8f3156153bcec85abde7544f2832da">https://gist.github.com/igtzolas/8a8f3156153bcec85abde7544f2832da</a></p><p>The code has been heavily based on the following : <a href="https://github.com/seungeunrho/minimalRL/blob/master/dqn.py">https://github.com/seungeunrho/minimalRL/blob/master/dqn.py</a></p><h3>Double DQN</h3><p>Now that we have the metaphor to understand DQN we can easily update our metaphor to explain the idea behind Double DQN.</p><p>The epitomy of the doubld dqn training can be found in the following sentence the father tells to the son:</p><blockquote><em>‘You are telling me my son that you think your next action should be NextAction based on what you think. I tell you that NextAction is worth that much if you take it now(in your next state). Please update your beliefs !’</em></blockquote><p>In code the differences between DQN and Double DQN are :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e652b8bc6ef840e0e3470e62e9b40bde/href">https://medium.com/media/e652b8bc6ef840e0e3470e62e9b40bde/href</a></iframe><p>The implementation for Double DQN can be found in : <a href="https://gist.github.com/igtzolas/cd01b6e5a4df71bbff541f65e254f781">https://gist.github.com/igtzolas/cd01b6e5a4df71bbff541f65e254f781</a></p><p>Thank you very much for reading !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4bf6ff1ae2f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/dqn-algorithm-a-father-son-tale-b4bf6ff1ae2f">DQN Algorithm: A father-son tale</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Transformer Intuitions (NLP)]]></title>
            <link>https://medium.com/@ioannis.g.tzolas/transformer-intuitions-nlp-b387be0034a1?source=rss-a4d14a7246db------2</link>
            <guid isPermaLink="false">https://medium.com/p/b387be0034a1</guid>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[transformers]]></category>
            <dc:creator><![CDATA[John Tzolas]]></dc:creator>
            <pubDate>Thu, 03 Oct 2019 07:47:20 GMT</pubDate>
            <atom:updated>2019-10-03T07:47:20.674Z</atom:updated>
            <content:encoded><![CDATA[<p>This short article is an effort to provide for some intuitions on the attention mechanism used as a building block by the Transformer Architecture.</p><p>The basic analogies are :</p><h4><strong>Words -&gt; People</strong></h4><h4><strong>Sentence -&gt; Neighborhood/Environment</strong></h4><p>A person, although having some intrinsic/personal characteristics, these characteristics flourish or are hidden based on the surrounding environment.</p><p><strong>Values</strong> : When a person enters an environment, the environment asks some questions to the person and decomposes his/her characteristics to the ones the environment is interested (values extractor matrix).</p><p>A characteristic of the environment may be whether the person is male or female.</p><p><strong>VALUES : Information a person POSSESSES</strong></p><p><strong>Queries</strong> : How open a person is to be influenced by other people + what a person would want to acquire from the environment . The person will try to make use of the others to fill in gaps (“I need this kind of information”).</p><p><strong>QUERIES : Information a person seeks/wants</strong></p><p><strong>Keys</strong> : How capable a person is to influence other people. Each person has some information which make him play a key role in the whole environment. The key extractor matrix of the environment identifies these information for every person.</p><p><strong>KEYS : Information a person can provide/can propagate to the environment.</strong></p><p>Having these intuitions in mind, we can understand the meaning of <strong>positional encoding</strong>. A person can more easily be influenced by someone nearby compared to a person who is far away.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b387be0034a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gradient Boost Decomposition = pytorch optimization + sklearn decision tree regressor]]></title>
            <link>https://medium.com/analytics-vidhya/gradient-boost-decomposition-pytorch-optimization-sklearn-decision-tree-regressor-41a3d0cb9bb7?source=rss-a4d14a7246db------2</link>
            <guid isPermaLink="false">https://medium.com/p/41a3d0cb9bb7</guid>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[gradient-boosting]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[John Tzolas]]></dc:creator>
            <pubDate>Wed, 25 Sep 2019 09:39:25 GMT</pubDate>
            <atom:updated>2022-09-26T07:13:00.668Z</atom:updated>
            <cc:license>https://creativecommons.org/publicdomain/mark/1.0/</cc:license>
            <content:encoded><![CDATA[<h4><strong>Gradient Boost Implementation = pytorch optimization + sklearn </strong>decision tree regressor</h4><p>In order to understand the Gradient Boosting Algorithm, effort has been made to implement it from first principles using <strong>pytorch </strong>to perform the necessary optimizations (minimize loss function) and calculate the residuals (partial derivatives with respect to predictions) of the loss function and <strong>decision tree regressor from sklearn</strong> to create the regression decision trees.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*omQKD1B6QAHxe23mswi-WA.jpeg" /><figcaption>A line of trees</figcaption></figure><p>An updated version of the medium story can be found in the following kaggle notebooks : <br><a href="https://www.kaggle.com/code/igtzolas/inventing-gradient-boosting-regression">https://www.kaggle.com/code/igtzolas/inventing-gradient-boosting-regression</a><br><a href="https://www.kaggle.com/code/igtzolas/inventing-gradient-boosting-classification">https://www.kaggle.com/code/igtzolas/inventing-gradient-boosting-classification</a></p><h3>Algorithm Outline</h3><p>The outline of the algorithm can be seen in the following figure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*xQXPUxSnBd1lOxjLoePoVQ.png" /><figcaption>Steps of the algorithm</figcaption></figure><p>We will try to implement this step by step and also try to understand why the steps the algorithm takes make sense along the way.</p><h3><strong><em>Explanations + Code snippets</em></strong></h3><h4>Loss function minimization</h4><p>What is crucial is that the algorithm tries to minimize a loss function, be it square distance in the case of regression or binary cross entropy in the case of classification.</p><p>The loss function parameters are the predictions we make for the training examples : <strong>L(prediction_for_train_point_1, prediction_for_train_pont_2, …., prediction_for_train_point_m).</strong></p><p>pytorch is used to minimize the loss function as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd027edb08c784e763cd80cbef737bb3/href">https://medium.com/media/fd027edb08c784e763cd80cbef737bb3/href</a></iframe><h4>Calculating the residuals</h4><p>What are the so called residuals?</p><p>They are the first order partial derivatives of the loss function with respect to the current predictions for thedata point examples.</p><p>In plain words the residuals are vectors (<strong>directions + norms</strong>) of where should the value of the prediction up to now change so that the loss function gets minimized. In our case the direction is provided by the sign of the residual (since it is a one dimensional scalar). <strong>It makes sense that data points with have same loss function minimization tendencies are grouped and treated in the very same way (into the same treatment bucket as the leaf of the tree)</strong>! This is the most important conceptual intuition of the algorithm. Why<strong> the decision trees are being constructed on the partial gradients with respect to current predictions of the loss function/objective.</strong></p><p>The code to calculate the derivatives/residuals is the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/edf9b8e37e682183200652cd2e1ca5f0/href">https://medium.com/media/edf9b8e37e682183200652cd2e1ca5f0/href</a></iframe><h4><strong>Constructing the decision regression trees</strong></h4><p>Decision tree regressor is used to create the regression trees. The decision paths are kept because a single prediction will be calculated for the data that fall within each one of the decision paths/leaf buckets.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/812a4af5a403251fbb54504df13dac21/href">https://medium.com/media/812a4af5a403251fbb54504df13dac21/href</a></iframe><h4><strong>Putting all the pieces together and creating an sklearn like class</strong></h4><p>The algorithm implementation is provided below making use of the already defined code. At each step, the residuals are fed to a regression tree and then the predictions for the data points get updated based on the value that minimizes the loss function on the data of the same bucket (leaf).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74bf79ac01f1bc139768d8ecd5e2bbec/href">https://medium.com/media/74bf79ac01f1bc139768d8ecd5e2bbec/href</a></iframe><p>The code in its entirety can be found in the following <a href="https://github.com/igtzolas/ml_algorithms"><strong><em>github link</em></strong></a>.</p><h3><strong>Using the custom implementation in an example and Comparison to vanilla algorithm results</strong></h3><p>The following example makes use of the custom and the vanilla sklearn implementations to perform a classification task and compare the results:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ebdf214466600cba5c4aca24916024e3/href">https://medium.com/media/ebdf214466600cba5c4aca24916024e3/href</a></iframe><p>The output of the program is :</p><p>Custom Implementation : Accuracy score for training data : 0.7661290322580645<br>Custom Implementation : Accuracy score for testing data : 0.625</p><p>Vanilla Implementation : Accuracy score for training data : 0.7580645161290323<br>Vanilla Implementation : Accuracy score for training data : 0.625</p><p>Thank you very much for taking the time to read through this thread!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41a3d0cb9bb7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/gradient-boost-decomposition-pytorch-optimization-sklearn-decision-tree-regressor-41a3d0cb9bb7">Gradient Boost Decomposition = pytorch optimization + sklearn decision tree regressor</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>