<?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 Akhilesh Kapse on Medium]]></title>
        <description><![CDATA[Stories by Akhilesh Kapse on Medium]]></description>
        <link>https://medium.com/@akhileshkapse?source=rss-18fc04711604------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*nLKuVn3uCN9-c4b4uJOehw.png</url>
            <title>Stories by Akhilesh Kapse on Medium</title>
            <link>https://medium.com/@akhileshkapse?source=rss-18fc04711604------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 05:00:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@akhileshkapse/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[A Comprehensive Overview of Feature Selection Methods in Machine Learning]]></title>
            <link>https://medium.com/@akhileshkapse/a-comprehensive-overview-of-feature-selection-methods-in-machine-learning-8b1101ee3d8?source=rss-18fc04711604------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b1101ee3d8</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[feature-engineering]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Akhilesh Kapse]]></dc:creator>
            <pubDate>Sat, 24 Dec 2022 11:59:12 GMT</pubDate>
            <atom:updated>2022-12-24T11:59:12.738Z</atom:updated>
            <content:encoded><![CDATA[<h4>Mastering Feature Selection: Tips and Tricks for Choosing the Best Features for Your Data</h4><p>A critical phase of machine learning is feature selection. To enhance the model’s effectiveness and generalizability, it includes choosing and creating a subset of features from a dataset that are most related to the target variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*j1IAUmwz8dqqBW_J" /><figcaption>Photo by <a href="https://unsplash.com/es/@imagesbykayla?utm_source=medium&amp;utm_medium=referral">Kayla Farmer</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>There are many different techniques that can be used for feature selection, and the appropriate technique will depend on the specific problem and the type of data you are working with. Some common methods include:</p><ol><li>Filter methods: These methods evaluate the relevance of each feature by calculating a statistical score and selecting a subset of the highest-scoring features. These methods are fast and simple, <em>but they do not consider the interaction between features or the overall predictive power of the subset</em>.</li><li>Wrapper methods: These methods use a learning algorithm to evaluate the performance of a subset of features. The subset with the best performance is selected. Wrapper methods are more computationally intensive than filter methods, but they can provide better results by considering the interaction between features.</li><li>Embedded methods: These methods learn the optimal feature subset as part of the learning algorithm itself. For example, Lasso regression is a type of linear regression that includes a regularization term that penalizes large coefficients and can effectively zero out some of the less important features.</li><li>Hybrid methods: These methods combine elements of multiple feature selection techniques. For example, a hybrid method might use a filter method to select a subset of features and then use a wrapper method to further refine the selection.</li></ol><blockquote>NOTE- Filter methods measure the relevance of features by their correlation with dependent variable while wrapper methods measure the usefulness of a subset of feature by actually training a model on it.</blockquote><p>It’s important to note that feature selection is a trade-off between model complexity and predictive power. Adding more features to a model can potentially improve its performance, but it can also make the model more difficult to interpret and increase the risk of overfitting (performing well on the training data but poorly on unseen data).</p><h3>Filter methods</h3><ul><li><a href="https://drive.google.com/file/d/16Ddzu9IXDSviMSuBCx77_ZtlL1jqZcB1/view?usp=sharing"><strong>Chi-squared test</strong></a>: This method calculates the chi-squared statistic for each feature, which measures the dependence between the feature and the target variable. <em>Features with a high chi-squared statistic are considered to be more important, as they have a stronger relationship with the target variable</em>.</li><li><strong>Mutual information</strong>: This method calculates the mutual information between the feature and the target variable, which measures the amount of information that the feature provides about the target.</li><li><a href="https://drive.google.com/file/d/1gBZBO-7emyZuPzvXIklq4Lj6gYEWVZVv/view?usp=share_link"><strong>ANOVA F-value</strong></a>: This method calculates the F-value for each feature, which measures the difference in the mean of the feature between different classes of the target variable. Features with a high F-value are considered to be more important, as they have a strong relationship with the target.</li><li><strong>Information gain</strong>: This method measures the amount of information that a feature provides about the target, based on the entropy of the target before and after knowing the value of the feature.</li></ul><h3>Wrapper method</h3><ul><li><strong>Forward selection</strong>: This method starts with an empty set of features, and iteratively adds one feature at a time based on its impact on the model performance. The feature that results in the greatest improvement in model performance is added to the set, and the process is repeated until no further improvement can be achieved.</li><li><strong>Sequential forward floating selection (SFFS)</strong>: This method is similar to forward selection, but instead of adding one feature at a time, it adds a group of features at a time. It starts with an empty set of features, and iteratively adds the most promising group of features based on their impact on the model performance.</li><li><strong>Backward elimination</strong>: This method starts with a set of all features, and iteratively removes one feature at a time based on its impact on the model performance. The feature that results in the least deterioration in model performance is removed from the set, and the process is repeated until no further improvement can be achieved.</li><li><strong>Sequential backward floating selection (SBFS)</strong>: This method is similar to backward elimination, but instead of removing one feature at a time, it removes a group of features at a time. It starts with a set of all features, and iteratively removes the least important group of features based on their impact on the model performance.</li></ul><p><a href="https://medium.com/analytics-vidhya/feature-selection-85539d6a2a88">Feature Selection: Wrapper Methods</a></p><h3>Embedded method</h3><ul><li><strong>L1 &amp; L2 techniques</strong>: This method is a linear model that includes a regularization term that shrinks the coefficients of the features towards zero. The regularization term has a tuning parameter that controls the strength of the shrinkage, and features with a zero or ~zero coefficient are removed from the model.</li></ul><p><a href="https://towardsdatascience.com/l1-and-l2-regularization-methods-ce25e7fc831c">L1 and L2 Regularization Methods</a></p><ul><li><strong>Decision trees</strong>: Decision trees are a type of machine learning algorithm that creates a tree-like model of decisions, based on the features in the data. The decision tree algorithm includes a feature selection component, as it determines which features are most important for making the decisions in the tree.</li></ul><p><a href="https://towardsdatascience.com/the-mathematics-of-decision-trees-random-forest-and-feature-importance-in-scikit-learn-and-spark-f2861df67e3">The Mathematics of Decision Trees, Random Forest and Feature Importance in Scikit-learn and Spark</a></p><ul><li><strong>Ridge regression, Elastic net, Least absolute deviation (LAD)</strong></li></ul><h3>Hybrid method</h3><p>A hybrid method involves combining two or more of the above methods to find the optimal subset of features. For example, a hybrid method could involve using a filter method to pre-select a subset of features, and then using a wrapper method to fine-tune the selection of features.</p><ul><li><strong>Stacked generalization</strong></li><li><strong>Multi-objective optimization</strong></li></ul><h3>Other Feature selection method</h3><ul><li><strong>Correlation-based feature selection</strong>: This method involves selecting a subset of features that are highly correlated with the target variable and uncorrelated with each other.</li><li><strong>Feature binning</strong>: This method involves dividing the range of a continuous feature into bins and treating each bin as a separate categorical feature.</li><li><strong>Low-variance feature</strong>: Drop the low variance feature, snice they doesn&#39;t contribute in model prediction.</li><li><strong>Remove Duplicate feature</strong> both as numerically co-related or as per intuitive domain knowledge.</li><li><strong>PCA </strong>(principal component analysis): This is a dimensionality reduction technique that projects the data onto a lower-dimensional space while preserving as much of the variance as possible.</li></ul><h3>Tips and Tricks</h3><ol><li><strong>Start with a large set of features</strong>: It is generally a good idea to start with a large set of features, and then select the most important features.</li><li><strong>Use multiple methods</strong>: Different feature selection methods may give different results, depending on the characteristics of the data and the requirements of the problem.</li><li><strong>Use a validation set</strong>: It is important to evaluate the performance of the model on a validation set, rather than just on the training set. This ensures that the model generalizes well to unseen data.</li><li><strong>Use domain knowledge</strong>: Domain knowledge can be a valuable source of information for feature selection.</li><li><strong>Consider the interpretability of the features</strong>: In some cases, it may be important to retain interpretable features, even if they do not have the highest importance according to a feature selection method.</li><li><strong>Keep track of the selected features</strong>: It can be helpful to keep a record of the selected features, in case it is necessary to revisit them later.</li><li><strong>Avoid selecting too many features</strong>: It is generally a good idea to avoid selecting too many features, as this can lead to a model that is unnecessarily complex and prone to overfitting.</li><li><strong>Use automated feature selection tools</strong>: There are many automated feature selection tools available, such as scikit-learn’s “<em>SelectFromModel</em>” and “<em>RFE</em>”, which can make the feature selection process more efficient.</li><li><strong>Consider the complexity of the model</strong>: It may be necessary to trade off model complexity for improved performance, depending on the characteristics of the data and the requirements of the problem.</li></ol><p>Thanks for reading this long…</p><p>Suggestions and new methods are welcome.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b1101ee3d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Simplified Explanation of the Transformer Block [Must-Read Blog for NLP Enthusiasts]]]></title>
            <link>https://medium.com/@akhileshkapse/a-simplified-explanation-of-the-transformer-block-must-read-blog-for-nlp-enthusiasts-12ef240a62ac?source=rss-18fc04711604------2</link>
            <guid isPermaLink="false">https://medium.com/p/12ef240a62ac</guid>
            <category><![CDATA[transformers]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[naturallanguageprocessing]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[quick-reads]]></category>
            <dc:creator><![CDATA[Akhilesh Kapse]]></dc:creator>
            <pubDate>Tue, 20 Dec 2022 07:38:19 GMT</pubDate>
            <atom:updated>2022-12-20T07:43:56.743Z</atom:updated>
            <content:encoded><![CDATA[<h4>A Detailed Look at the Different Components of the Transformer Blocks</h4><p>For a broad overview and information on seq2seq RNNs, see this blog.</p><p><a href="https://medium.com/@akhileshkapse/quick-intuition-why-attention-is-all-you-need-p1-7d42b69b3073">Seq2Seq RNNs with Attention: A Quick Intuition for Understanding the Basics</a></p><h3>Introduction</h3><p><strong>ChatGPT</strong> is an AI chatbot (<em>created by OpenAI</em>) that excels at performing amazing tasks at a human level, including question-answering, dialogue, writing essays, mail, and even code.</p><p>The key innovation of the transformer architecture is the use of self-attention mechanisms, which allow the model to efficiently process input sequences of variable length and to learn relationships between elements in the sequence. This makes transformers particularly well-suited for tasks that involve processing long-range dependencies, such as language translation, where the meaning of a word may depend on the context in which it appears several words earlier in the input sequence.</p><p>Paper — <a href="https://arxiv.org/pdf/1706.03762.pdf">https://arxiv.org/pdf/1706.03762.pdf</a></p><p>Due to the fast-moving nature of the paper’s description of the overall transformer model and attention mechanism. Sometimes it can be overwhelming to understand and get the intuition right upon first reading.</p><p>In this blog, I will go over each transformer component individually. We will subsequently compile all of our knowledge to create the final transformer block.</p><h3>Input to model</h3><p>We have a language translation task. We will discuss the working and concept with a example <em>X </em>( <em>no batch feeding</em>). Lets assume we have done all the text-preprocessing needed.</p><p>First things first, we have tokenized vector as an input. This input passes through embedding matrix followed by positional encoding (why we need position info. ? will discuss this below further) to convert it into dense vectors. Now, the input <em>X </em>feeded to transformer block has shape [<em>T </em>x <em>Dmodel</em>] where T is for word sequence and <em>Dmodel</em> is feature vector for the word.</p><h3>Key, Query, Value and multi-head concept</h3><p>This concept in field of deep learning is new. We pass input through 3 different linear layer of nodes <em>Dk</em>. These output are called the “key <em>K</em>”, “query <em>Q</em>”, and “value <em>V</em>”. Each shape [<em>T </em>x <em>Dk</em>].</p><h4>View I</h4><p>Lets talk in matrix sense.</p><ul><li>We 1st take dot product of query and key vector/matrix. Resultant <em>QK</em> matrix will have shape [<em>T </em>x <em>T</em>].</li></ul><blockquote>The transformer encoder training builds the weight parameter matrices <em>Wq </em>and <em>Qk </em>in the way <em>Q </em>and <em>K </em>builds the Inquiry System that answers the inquiry &quot;<strong>What is <em>k </em>for the word <em>q</em></strong>&quot;.</blockquote><blockquote>Also, this dot product followed with its normalization co-relates the <strong>pearson correlation</strong> formula with zero mean. Mean, <strong>we are eventually finding the co-relation matrix for each word with other words in input</strong>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6y6uk26xE4iNnEQhWMzyhw.png" /></figure><blockquote>This attention weight matrix <em>QK</em> makes model to understand context around words. Take the intuition from blow example, how the word “NLP” related to other words in sequence.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9r9yATrqKi4Ra5-vLastGw.png" /></figure><ul><li>We the multiply the <em>QK </em>attention matrix to the “<em>Value V”</em> vector to get <strong>final intermediate output <em>X</em> of shape [<em>T</em> x <em>Dv</em>]</strong>. (NOTE <em>Dk=Dv=Dq)</em></li></ul><h4>Multi-Head Attention</h4><ul><li>The independent stack of self-attention computation describe in above points is know as multi-head attention system.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wzrXts0Xfm5xBls14Dd7qg.png" /></figure><p>We need <strong>multi <em>self-attention</em></strong> stacked modules because it might be the case that our model learns “Why we use nlp?” in one self-attention block and “what is a sub-part of ML?” in another block.</p><h4>View II</h4><ol><li>The transformer takes in a sequence of input vectors and applies an attention mechanism to compute a weighted sum of the input vectors.</li></ol><ul><li>The attention mechanism consists of three components: <strong>the query, the key, and the value</strong>.</li><li>The <strong>query </strong>is a vector that represents the current position in the input sequence. It is used to determine the relationship between the current position and the other positions in the input sequence.</li><li>The <strong>key</strong> is a vector that represents each position in the input sequence. It is used to determine the output (value) of the attention mechanism.</li><li>The <strong>value </strong>is the result of the attention computation and is used to compute the output of the transformer.</li></ul><blockquote>To compute the attention, the transformer computes the dot product of the query vector with the key vectors for each position in the input sequence. These dot products are then used to compute the weights for each value vector, which are then used to compute the weighted sum of the value vectors.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*b9fgRqcsx1mNBeCQ7alYLA.png" /><figcaption>Pair strength determines the co-relation of each word to other.</figcaption></figure><p><strong>Note- all operation done above are linear in nature</strong></p><h3><strong>Attention mask and </strong>Non-linearity <strong>in model [complex understanding]</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*mFuJyxtOgM7NWxdTF8tzLQ.png" /></figure><p>Before multiplying <em>QK </em>to “<em>Value V</em>” matrix/vector to get intermediate value, note there is an option named “<em>Mask</em>”. We have fixed input length. This <strong>attention mask</strong> resemble for this input sequence. “1” for the position where there is actual word. “0” for padded position.</p><p>The output of all stacked self-attention module (<em>multi-head attention</em>) is then concatenated. Resulting shape (<em>h</em>*[<em>T </em>x <em>Dv</em>]) is [<em>T </em>x <em>h.Dv</em>]. Followed by Linear operation (weight matrix shape [<em>h.Dv</em> x <em>Dmodel</em>]) with non-linear activation. The resultant output shape at this stage is [<em>T </em>x <em>Dmodel</em>].</p><blockquote>To conclude, Multi-Head Attention Block takes 3 input <em>K</em>, <em>Q</em>, <em>V </em>all of same input shape i.e. [<em>T </em>x <em>Dk</em>] and outputs [<em>T</em> x <em>Dmodel</em>].</blockquote><h3>Compiling all Blocks</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*NVGL3uZAOZLk6dsh-Pu3uQ.png" /><figcaption>Transformer Block [inp/out dimension]</figcaption></figure><blockquote><strong>NOTE- input and output of the block in same [<em>T </em>x <em>Dmodel</em>]. SO, we can stack this block “N” times.</strong></blockquote><p>The input is added with multi-head attention ad itself followed by layer norm. Then passed to non-linear layer with skip-connection again.</p><h3>Positional encoding</h3><p>The self-attention mechanism does not have any information about the relative or absolute position of the input tokens in the sequence.</p><p>Positional encoding is a way of representing the position of each token in the input sequence as a vector, which is then added to the input embedding of the token.</p><p>There are several ways to create positional encodings, but one common approach is to use sinusoidal functions of different frequencies to create a set of vectors that can be added to the input embeddings. <strong>The sinusoidal functions are chosen so that the resulting vectors have different periodicities, which allows them to encode information about the position of the tokens in the sequence.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/473/1*v3AF1DHhy18CvWaKlMaPxw.png" /></figure><p>Positional encoding is important because it allows the transformer to capture the relationships between the tokens in the sequence and their relative positions, which can be useful for tasks such as language translation and language modeling.</p><h3>SOTA architecture which uses transformer block</h3><p>The transformer is a versatile architecture that is well-suited to many different types of tasks. It has become a popular choice for many state-of-the-art models in the field.</p><h4>1. BERT (Bidirectional Encoder Representations from Transformers)</h4><p>BERT is called a <strong>bidirectional model </strong>because it is trained to consider the context on both the left and the right sides of each word in the input text (<em>masked language modeling</em>).</p><p>Encoder Representations means it has several stacked transformer blocks to generate deep input embeddings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*WGd2UAvpPV6Sh6XhD-Uohg.png" /></figure><h4>2. GPT (Generative Pre-training Transformer)</h4><p>GPT is a model that is trained to generate human-like text. It can be fine-tuned for a wide range of language generation tasks, such as machine translation, summarization, and dialog systems.</p><p>GPT is trained using a technique called “<em>unsupervised language modeling</em>” in which the model is given a large dataset of text and is required to predict the next word in a sequence given the context of the previous words. It’s a decoder-type transformer model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/407/1*B05My0eTG7Zza5ichkBmxw.png" /></figure><p>Open for any help and suggestions.</p><p>Thanks</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12ef240a62ac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick intuition, why Attention is all you need ? [P1]]]></title>
            <link>https://medium.com/analytics-vidhya/quick-intuition-why-attention-is-all-you-need-p1-7d42b69b3073?source=rss-18fc04711604------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d42b69b3073</guid>
            <category><![CDATA[top-10]]></category>
            <category><![CDATA[naturallanguageprocessing]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[transformers]]></category>
            <category><![CDATA[attention]]></category>
            <dc:creator><![CDATA[Akhilesh Kapse]]></dc:creator>
            <pubDate>Fri, 16 Dec 2022 14:21:16 GMT</pubDate>
            <atom:updated>2022-12-20T07:40:37.472Z</atom:updated>
            <content:encoded><![CDATA[<h3>Seq2Seq RNNs with Attention: A Quick Intuition for Understanding the Basics</h3><h4>Exploring the Role of the Encoder and Decoder in Seq2Seq RNNs with Attention: Quick key concepts</h4><p>Seq2seq RNNs (recurrent neural networks) are a type of architecture that is used for tasks such as machine translation, language modeling, and text summarization. They consist of two RNNs: an encoder and a decoder.</p><p>The encoder processes the input sequence and produces a fixed-length vector, known as the context vector, which summarizes the input. The decoder then processes this context vector to generate the output sequence.</p><blockquote>I’ll be giving you a quick thorough and intuitive understanding of seq2seq and attention in seq2seq.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GahFA0ymnTq0gGTAefy8bA.png" /></figure><h3>Prerequisite</h3><p>This blog is suitable for both beginners who want to get the real understanding behind and for experts who wish to refresh or brush up on the material quickly.</p><p>Basic understanding of</p><ul><li>working of ANNs, RNNs and CNNs</li><li>mathematics (vectorization, dot product)</li></ul><h3>What is Attention?</h3><p>Simply said, you can think of it as any technique that enables you to draw attention to a certain element while suppressing unwanted noise in a sequence of data/features.</p><blockquote>(T<em>echnically</em>) Masking or soft-weighting the sequence node/value.</blockquote><p>Attention is a mechanism that allows a model to focus on specific parts of the input when generating the output. It is often used in seq2seq models, which are a type of architecture used for tasks such as machine translation, language modeling, and text summarization.</p><h3>Seq2Seq RNN</h3><p>Seq2Seq is a Encoder-Decoder model of RNN used in machine translation, POS tagging, NER, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q9Ejr3XD67teulyafCGe2g.jpeg" /><figcaption>Figure 1</figcaption></figure><p>The Core idea of normal seq2seq model is to Encode every timestep word through RNN/LSTM to generate hidden states (<em>Hi</em>). Decoder takes Hf ( <em>Hf — function of all input word</em>) or it can take the stack of all state as initial hidden state and it will predict the word, as a function of previous decoder hidden state (<em>S[t-1]</em>) and output word (<em>ŷ[t-1]</em>) (<em>figure 1</em>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*Q_t0QB-1zGERy795hLZfDQ.png" /><figcaption>Figure 2</figcaption></figure><p>However, as is well known, extended input sequences are difficult for RNN/LSTM to predict (<em>vanishing gradients or long-term dependence issue</em>). After a particular sequence length, their performance began to decline (<em>figure 2</em>). To sustain and improve this performance, we must apply an attention mechanism.</p><h3>Attention in Seq2Seq RNN</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*G6cPcD8Raexp05OuivEmZQ.jpeg" /><figcaption>Figure 3</figcaption></figure><p>In given model, we feed relevant context vector (<em>Ci</em>) to decoder RNN/LSTM with the previous hidden state (<em>S[t-1]</em>) at every timestep (t) for its prediction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*ZS7Kkq_pf6pd-K9igZ6pEA.jpeg" /><figcaption>Figure 4</figcaption></figure><p>The context vector is the soft-weighted sum of all the encoder hidden state (<em>Hi</em>) at every timestep (t) (f<em>igure 4</em>). This weights are denoted by <em>A</em> (<em>alpha α</em>). Note, <em>A(t,j) </em>(<em>alpha α</em>) is 2 dimensional, for all timestep (<em>T</em>) we have to calculate <em>α </em>for all encoder hidden state (<em>Hj</em>).</p><p>Attention method which takes all encoder hidden state (<em>h1, h2, h3, h4</em>) and pervious timestep decoder hidden state (<em>S[t-1]</em>) as input, calculates <em>α</em> for all <em>hi</em> at timestep <em>t </em>via SoftMax on top of<em> </em>separate<em> </em><strong>ANN </strong>layer that is trained alongside the rest of the model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/837/1*SvEYCRJBY0QeEhNfYQR7XQ.png" /><figcaption>Figure 5</figcaption></figure><p>We observe how the RNNs/LSTMs can produce the translation while concentrating on a small portion of the input sentence, thanks to the attention mechanism. <em>alpha</em> weight heatmap (f<em>igure 5</em>). Observe how higher intensity <em>alpha (α)</em> make model understand the related portion of the English to predict French text.</p><h3>Pros and Cons</h3><p>Pros-</p><ol><li>Seq2seq models can handle input and output sequences of variable length, making them suitable for tasks such as machine translation and text summarization.</li><li>Seq2seq models can be trained using both <strong>supervised</strong> (<em>Machine translation, Text summarization</em>) and <strong>unsupervised</strong> learning (<em>Language modeling, Autoencoding</em>) techniques.</li><li>Seq2seq models can incorporate attention mechanisms, which allow the model to improve performance on long sequences.</li></ol><p>Cons-</p><ol><li>Seq2seq models can be <strong>slower to train</strong> than other types of models, such as transformer models, because they process the input and output sequences one element at a time.</li><li>Seq2seq models can <strong>struggle to maintain context over long sequences</strong>, especially when the input and output sequences are very different in length.</li><li>Seq2seq models are <strong>not as well suited to parallelization </strong>as other types of models, such as transformer models, because the output of each element in the sequence depends on the output of the previous element.</li></ol><p>For Mastering the Transformer Blocks: A Fast-Track Introduction, read the blog below.</p><p><a href="https://medium.com/@akhileshkapse/a-simplified-explanation-of-the-transformer-block-must-read-blog-for-nlp-enthusiasts-12ef240a62ac">A Simplified Explanation of the Transformer Block [Must-Read Blog for NLP Enthusiasts]</a></p><p>Thanks</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d42b69b3073" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/quick-intuition-why-attention-is-all-you-need-p1-7d42b69b3073">Quick intuition, why Attention is all you need ? [P1]</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[FINGER COUNT AI using Opencv  python]]></title>
            <link>https://medium.com/analytics-vidhya/finger-count-ai-using-opencv-python-b9090eb68928?source=rss-18fc04711604------2</link>
            <guid isPermaLink="false">https://medium.com/p/b9090eb68928</guid>
            <category><![CDATA[projects]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[inside-ai]]></category>
            <category><![CDATA[opencv]]></category>
            <dc:creator><![CDATA[Akhilesh Kapse]]></dc:creator>
            <pubDate>Mon, 25 May 2020 07:12:49 GMT</pubDate>
            <atom:updated>2020-06-22T13:43:06.398Z</atom:updated>
            <content:encoded><![CDATA[<h4><a href="https://medium.com/towards-data-science/inside-ai/home"><strong>Inside AI</strong></a></h4><h3>HAND DETECTION AND FINGER COUNTING AI using Opencv python</h3><h4>How I build Real-time finger counting model from scratch</h4><h3>Introduction :</h3><p>Hey you! If you are newborn family member of <strong><em>COMPUTER VISION</em></strong> and want to evolve and understand some cool opencv tools and stuffs. In this article we will be going from scratch to full understanding and implementation of opencv using python on finger counting project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rxRvQbRx6_trQYI5Wi-k2Q.jpeg" /></figure><blockquote>Code for this project can be found at my <a href="https://github.com/Adk2001tech/OpenCV-/blob/master/finger_count.py">Github</a></blockquote><blockquote>Basics of opencv python are also available at my <a href="https://github.com/Adk2001tech/OpenCV-">Github</a></blockquote><p>I will break this process in certain steps for better understanding as below:</p><p><strong>Step 1</strong>: Setting-up the avg. background values in region of interest.</p><p><strong>Step 2</strong>: Apply blurring and Thresholding on hand entered in ROI to find contours.</p><p><strong>Step 3</strong>:Use technique known as <em>Convex hull </em>to grab polygon around it along its vertices (<em>x,y</em>).</p><p><strong>Step 4</strong>: Using some mathematics to count no. of finger raised. I will be going to explain math related stuffs later on.</p><p><strong>Step 5</strong>: Put all stuff together to build our project</p><h3><strong>Step 1</strong>:</h3><p>In computer vision projects we are more concern about an object in an image or video of our interest.Background should not create noise or distract our machine to give wrong and unexpected results.In this project we are only concern about our hand entering in ROI. To get segmented out our hand we will turn all the pixels to 0(zero) except our hand pixels.This can be achieve by taking abs. difference of our calculated avg. background image with current frame/image.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d174b4944f75ef597600aad8198bfd04/href">https://medium.com/media/d174b4944f75ef597600aad8198bfd04/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rn2yEDiBnaKiu42clu9ZsQ.jpeg" /></figure><p>In above code we first grab a single frame to select our ROI using <strong><em>cv2.selectROI(image)</em></strong><em> w</em>hich returns <em>x,y,width,height</em> of our ROI. Then for next 60 frames we modify each pixels of <em>back </em>to become weighted average of each frame. This can done using <strong><em>cv2.accumulateWeighted(), </em></strong>which takes parameter like <em>current frame,backgound frame(back),learning rate.</em></p><h3>Part 2:</h3><p>This part deals with image pre-processing. As our hand is now get segmented, we should apply blurring and Thresholding. Doing this we can now easily find boundaries of hand.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed7abee2efe98c8636370bb5de998770/href">https://medium.com/media/ed7abee2efe98c8636370bb5de998770/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ht93g7h06o86nw0smwPfpA.jpeg" /></figure><p>After getting background image(<em>back</em>),we must apply <strong><em>cv2.convertScaleAbs()</em></strong> It generally Scales, calculates absolute values, and converts the result to 8-bit. Then convert background image(<em>back</em>) and current frame into Grayscale images.Take absolute difference of grayscale images .Apply Thresholding using <strong><em>cv2.threshold(</em></strong><em>image,min_thresh,max_thresh,method_of_thresholding</em>.<strong><em>). </em></strong>Now our<strong><em> </em></strong>image is prefect to get its external contours . It returns contour(list of points(co-ordinate) of boundary),their hierarchy. Take those list of points which covers maximum area(probably it must be our hand segment’s boundary co-ordinates).I’m creating a copy of <em>img ,you will get it in next step(it’s just for </em>visualization purpose.<em>)</em></p><h3>Part 3:</h3><p>Convex hull draws a polygon by connecting points around most external points in a frame. First we will calculate the most extreme points(top,bottom,left and right). Then we can calculate their intersection and that must be center of our hand. Next we will calculate the distance for the point furthest away from our calculated center.Then using some ratio(depends hand to hand) of that distance we create a circle. Any point outside the circle and far away enough from the bottom ,should be extended fingers. For more mathematics behind this check <a href="https://books.google.co.in/books?id=vkNfw8SsU3oC&amp;pg=PA707&amp;lpg=PA707&amp;dq=counting+finger+with+a+circle+of+radii+from+center+of+hand+to+exterme+finger+point&amp;source=bl&amp;ots=2Jfk-6ipz5&amp;sig=ACfU3U1nLEbtKG5Ql0AY9sC5OJsJ3uT8eQ&amp;hl=en&amp;sa=X&amp;ved=2ahUKEwjMoJW90MzpAhUBOSsKHfZfB1UQ6AEwAHoECAkQAQ#v=onepage&amp;q=counting%20finger%20with%20a%20circle%20of%20radii%20from%20center%20of%20hand%20to%20exterme%20finger%20point&amp;f=false">this</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/edcbf15b7222a115732e9191ce311a18/href">https://medium.com/media/edcbf15b7222a115732e9191ce311a18/href</a></iframe><p>In this code, first call a function <strong><em>cv2.convexHull(contour) </em></strong>and<strong><em> </em></strong>assign it to a variable name <em>conv_hull. </em>Then we grab the most extreme points(<em>top,bottom,left and right</em>).It’s just a simple co-ordinate geometry.With the help of this points, grab hand center(<em>cx,cy</em>).Now we can estimate the value of radius(<em>radi</em>). Then create <em>circular_roi</em> of shape same as <em>img</em> of all pixels of value zeros.Draw a circle of our desired radii on it.Then do <strong><em>bitwise_and()</em></strong> operation between <em>img2</em> and c<em>ircular_roi </em>and store it as<em> mask</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*Z347AvjQLcOPutMMuqmAjg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*HJ4c1DFy319QTlOsgzno5g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*vVVvpdjW-k9GgNjxoLoabQ.png" /></figure><h3>part 4:</h3><p>Now its time to count finger raised. For doing so, we first grab contours again of <em>mask</em> image and find co-ordinates of bounding box and apply some condition on each box to count weather it is a contour of finger or wrist or something else.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b9282ec9fb90fbe33a292912f489394/href">https://medium.com/media/3b9282ec9fb90fbe33a292912f489394/href</a></iframe><p>As shown above. We grab contours.Made a variable named <em>circumference. </em>Then we loop for each bounding box/rectangle found by contour<em>. </em>Calculate its orientation(<em>m_x,m_y,m_w,m_h</em>) and then apply two condition on it.That is <em>out_wrist_range </em>and<em> limit_pts. </em>We want to make sure that contour region is not at very bottom of the hand, if the person has lot of arm in<em> ROI</em> we may get some contour points at bottom and no useful for us. We can avoid this by simple math. We can say the boxes which are far bellow from center of hand it must be a contour of our arm and we can neglect it .Therefore the bounded box which are say 25% above center are part of finger raised. The second condition we can make sure of is that the no. of points along contour does not exceed 25% of the circumference of circular <em>ROI</em>. This is because machine can count certain points which are above center but not of fingers. This may because of some noise some external contours may pop up. So we define some limit(<em>limit_pts</em>) for this purpose.</p><h3>Part 5:</h3><p>Its time to combine all together what we have learned so far.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f862a530908ac442ae83a93810304778/href">https://medium.com/media/f862a530908ac442ae83a93810304778/href</a></iframe><p>In above code we grab first frame for selecting our <em>ROI</em>. After having our <em>ROI</em> we calculate weighted avg. of first 60 frames and then took absolute difference background image and current frame in every iterations while reading from webcam and assign it to new variable(<em>img</em>). Take threshold of grayscale <em>img</em>. Later we find extreme points(co-ordinate) of polygon using <em>conver hull</em> function by finding contours first. Tacking intersection of those points we get center points of our hand. Apply <em>bitwise_and()</em> operation between thresholded image and<em> circular_roi</em> having circle of some radii. If hand size is small make the radii small and vise-versa. Again grab the contour boxes and apply conditions for counting fingers raised. For visualization purpose we mark selected <em>ROI</em>’s rectangle on frame which <em>cap</em> object is reading. Also we show <em>mask</em> and <em>weighted</em> image to recheck our logic and code works properly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M9ybexY71ri4IMsa4p21xw.jpeg" /></figure><p>The final output should look like this . Hope you enjoy this project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*vVIqvZF-voj_yrM_UqW_uw.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9090eb68928" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/finger-count-ai-using-opencv-python-b9090eb68928">FINGER COUNT AI using Opencv  python</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[Mathematics and Vectorization behind Neural Network]]></title>
            <link>https://medium.com/analytics-vidhya/mathematics-and-vectorization-behind-neural-network-b6d491fa617d?source=rss-18fc04711604------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6d491fa617d</guid>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[vectorization]]></category>
            <category><![CDATA[mathematics]]></category>
            <dc:creator><![CDATA[Akhilesh Kapse]]></dc:creator>
            <pubDate>Tue, 12 May 2020 04:33:18 GMT</pubDate>
            <atom:updated>2020-05-26T15:02:22.168Z</atom:updated>
            <content:encoded><![CDATA[<p>In this era of having many high-level, specialized libraries and frameworks such as <strong><em>Keras</em></strong>, <strong><em>TensorFlow </em></strong>or <strong><em>PyTorch </em></strong>, we do not need to constantly worry about the size of our weights matrices or remembers formula for the derivative of activation function we decided to use.This post aims to discuss what a neural network is and how we represent it in a machine learning model. Subsequent posts will cover more advanced topics such as training and optimizing a model, but I’ve found it’s helpful to first have a solid understanding of what it is we’re actually building and a comfort with respect to the matrix representation we’ll use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9R71-SPtUiAfkwftOfN5sw.jpeg" /></figure><h3>A computational model of a neuron</h3><p>In first step we will understand how single neuron works as a logistic function and then move towards deeper side to compute more complex functions using multi/deep layer network framework.</p><p>In logistic regression, we composed a linear model <strong>z(x)</strong> with the logistic function <strong>g(z)</strong> to form our predictor. This linear model was a combination of feature inputs <strong>x</strong><em>i</em> and weights <strong>w</strong><em>i</em>.</p><p><strong>z(x)</strong>=<strong>w1x1+w2x2+w3x3+w4x4+b</strong>=<strong>wTx+b</strong></p><p>Let’s try to visualize it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z5WP-hMd_i7KWSpWCbp06g.png" /></figure><p>The first layer or final layer (in this case)contains a node for each value in our input feature vector. These values are scaled by their corresponding weight, <strong>w</strong><em>i</em>, and added together along with a bias term, <strong><em>b</em></strong>. The bias term allows us to build linear models that aren’t fixed at the origin.</p><p>After computing <strong>z(x) ,</strong>it then pass to some non-linear activation function having some threshold value<em>(θ).</em>If the linear combination of inputs and weights (<strong>z(x)</strong>) is higher than the threshold, the neuron fires, and if the combination (<strong>z(x)</strong>) is less than the threshold it doesn’t fire.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ykKnsiDnmfX0EZ3moPRVpw.png" /></figure><h3>Loss function</h3><p>The basic source of information on the progress of the learning process is the value of the loss function. Generally speaking, the loss function is designed to show how far we are from the ‘ideal’ solution. In our case we used binary crossentropy , but depending on the problem we are dealing with different functions can be applied.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/317/1*HopoKQrX-AbXo3bumhL9Xg.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*I4wvXBXl7Mh2sygG8MKd2w.png" /></figure><p>Main aim of Back Propagation is to modify <strong><em>Weights </em></strong>and <strong><em>Biases</em></strong> of Network which then gives local/global optimum value of <strong><em>Cost function </em></strong>of respective model.This is done with the help of <strong>Computational Graph</strong> Method as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vuuaRSG9fECczkcd2GWQbA.jpeg" /></figure><p>Lets see how the whole Process works to update the Weights and biases of neural network model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ag1P2uOkUYw1N3NQ5K4wQg.jpeg" /></figure><h3>Building a network of neurons</h3><p>The previous model is only capable of binary classification; however, recall that we can perform multi-class classification by building a collection of logistic regression models. Let’s extend our “network” to represent this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FlJ_ZPMSlpCdeuAYzC0gPw.png" /></figure><p>Here, we’ve built three distinct logistic regression models, each with their own set of parameters. Take a moment to make sure you understand this matrix representation. (This is why matrix multiplication is listed as a prerequisite.) It’s rather convenient that we can leverage matrix operations as it allows us to perform these calculations quickly and efficiently.</p><p>The above example displays the case for multi-class classification on a single example, but we can also extend our input matrix to classify a collection of examples. This is not simply useful, but necessary for our optimization algorithm (in a later post) to learn from all of the examples in an efficient manner when finding the best parameters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5p1XEvXVPcoqPi9BWeqJHQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CBrO60TSwnAdtXoIQPvq0g.png" /></figure><h3>Matrix representation</h3><p>Let <strong><em>n[l]</em></strong> represent the number of units in layer <strong><em>l</em></strong>. For a given layer, we’ll have a weights matrix <strong><em>W[l]</em></strong>of shape <strong><em>(n[l],n[l−1])</em></strong> and a bias vector of shape <strong><em>(n[l],1)</em></strong>.</p><p>The activations of a given layer will be a matrix of shape <strong><em>(n[l],m)</em></strong> where m represents the number of observations being fed through the network</p><p>Feeling like you’ve got a grasp?</p><p>Thank you for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6d491fa617d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/mathematics-and-vectorization-behind-neural-network-b6d491fa617d">Mathematics and Vectorization behind Neural Network</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>