<?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 Anish on Medium]]></title>
        <description><![CDATA[Stories by Anish on Medium]]></description>
        <link>https://medium.com/@joshanish?source=rss-c83d95871fa1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*vpBQRIofxfbtVo4BwA7wUg.jpeg</url>
            <title>Stories by Anish on Medium</title>
            <link>https://medium.com/@joshanish?source=rss-c83d95871fa1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 13:41:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@joshanish/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[ClipKit: Train Few-Shot CLIP Models with Plug-and-Play Vision & Text Encoders]]></title>
            <link>https://medium.com/@joshanish/clipkit-train-few-shot-clip-models-with-plug-and-play-vision-text-encoders-96ddbd2055df?source=rss-c83d95871fa1------2</link>
            <guid isPermaLink="false">https://medium.com/p/96ddbd2055df</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[multimodal]]></category>
            <dc:creator><![CDATA[Anish]]></dc:creator>
            <pubDate>Fri, 16 May 2025 10:25:04 GMT</pubDate>
            <atom:updated>2025-05-16T10:25:04.987Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jihMXiCjUrDO0LUu0vECcg.png" /></figure><p>In today’s deep learning world, large-scale models like CLIP (Contrastive Language–Image Pre-training) have shown remarkable capabilities in connecting vision and language. But they often require mountains of data and compute.</p><p>What if you want to build a smaller, faster, more focused version of CLIP on <strong>your own dataset</strong>, possibly with just <strong>a few hundred examples</strong>?</p><p>That’s where <a href="https://github.com/anish9/ClipKit"><strong>ClipKit</strong></a> comes in.</p><h3>🎯 The Goal</h3><p>ClipKit is built with the idea that:</p><blockquote><em>“You don’t need a chainsaw to cut a small plant.”</em></blockquote><p>In ML terms: You don’t need massive models or datasets to solve every vision-language task. With <strong>ClipKit</strong>, you can train a CLIP-style model using:</p><ul><li>Just <strong>a few hundred samples</strong></li><li>Your choice of <strong>vision encoder</strong> (like ResNet, MobileNet, EfficientNet)</li><li>Your choice of <strong>text encoder</strong> (any HuggingFace BERT-like model)</li></ul><p>It’s a plug-and-play, customizable toolkit for anyone who want to <strong>train CLIP-like models fast</strong> and <strong>with fewer resources</strong>.</p><h3>Core Features</h3><p>✅ <strong>Few-Shot Learning Focus</strong><br> Optimized training flow that works well even with limited data, making it ideal for quick experiments and proof-of-concepts.</p><p>✅ <strong>Plug-and-Play Encoders</strong><br> Use any combination of TensorFlow vision models and HuggingFace BERT models. You choose the complexity and size.</p><p>✅ <strong>End-to-End Training Support</strong><br> From data loading to training and evaluation, everything is covered. Just plug in your data.</p><p>✅ <strong>Custom Projection Layer</strong><br> Bridges the gap between text and image embeddings into a common space — learned during training.</p><h3>🧪 How It Works — Step by Step</h3><h3>1. 🔧 Clone the Repo &amp; Install Dependenciesdi</h3><pre>git clone https://github.com/anish9/ClipKit.git<br>cd ClipKit<br>pip install -r requirements.txt</pre><h3>2. 🧹 Prepare Your Data (Few-Shot Style)</h3><p>Prepare a CSV with image paths and their corresponding short captions. Even 200–300 pairs are enough to start. Organize your data like:</p><p>Refer : <a href="https://github.com/anish9/ClipKit/blob/main/assets/demo_train_sample.csv">https://github.com/anish9/ClipKit/blob/main/assets/demo_train_sample.csv</a></p><h3>3. 🏗️ Customize the Models (Flexible)</h3><p>In train.py, choose any combination of image and text encoders. For example:</p><pre>#vision model<br>image_model = get_image_model(model=EfficientNetV2B0, active_layers_image_model=10)<br><br>#text model<br>text_model_id = &quot;huawei-noah/TinyBERT_General_4L_312D&quot;  # &quot;distilbert-base-uncased&quot;<br>text_model, tokenizer = get_text_model(model_id=text_model_id, trainable=True)</pre><p>You can replace these with lightweight models like MobileNet or TinyBERT for edge use cases.</p><h3>4. 🚀 Train the Model (Even on CPU)</h3><pre>python train.py</pre><p>This script takes care of:</p><ul><li>Reading your data</li><li>Encoding text and images</li><li>Applying augmentations (for vision)</li><li>Computing contrastive loss</li><li>Saving checkpoints</li></ul><p>Since ClipKit is designed for low-data regimes, training is <strong>fast</strong> and often <strong>CPU-friendly</strong>.</p><h3>5. 🔍 Test &amp; Evaluate</h3><p>Open test.ipynb to:</p><ul><li>Load your trained model</li><li>Embed new image and text pairs</li><li>Compute similarity</li><li>Visualize retrieval or classification results</li></ul><p>You’ll be surprised how well the model performs — even with minimal data.</p><h3>✨ Use Cases</h3><ul><li>🏷️ Domain-specific image tagging (medical, fashion, etc.)</li><li>📱 On-device inference with small models</li><li>🧪 Startup MVPs needing fast, adaptable AI</li></ul><h3>🚧 Work in Progress</h3><p>ClipKit is a growing project with a clear mission:</p><blockquote><em>Democratize contrastive vision-language learning for small teams and minimal resources. </em>If you have feature ideas, model integrations, or improvements — contributions are welcome!</blockquote><p>It can be done much better if we can adapt FP16 training, will be implemented soon.</p><h3>Final Thoughts</h3><p>Building large models is expensive. But building <strong>relevant</strong> models is powerful.</p><p>With ClipKit, you can train a CLIP-style model that’s:</p><ul><li>Customized to your data</li><li>Trained in Minutes (not even hours for less than 10k samples or weeks)</li><li>Lightweight enough for real-world use</li></ul><p>Project Link : <a href="https://github.com/anish9/ClipKit/tree/main">https://github.com/anish9/ClipKit/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96ddbd2055df" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LLM Series: Understanding GPU Memory from First Principles]]></title>
            <link>https://medium.com/@joshanish/llm-series-understanding-gpu-memory-from-first-principles-d0b3e4666070?source=rss-c83d95871fa1------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0b3e4666070</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[llmops]]></category>
            <category><![CDATA[mlops]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Anish]]></dc:creator>
            <pubDate>Mon, 17 Mar 2025 02:40:17 GMT</pubDate>
            <atom:updated>2025-03-17T02:40:37.303Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oTyHmj5qnW-XAlWQ" /><figcaption>Photo by <a href="https://unsplash.com/@lime517?utm_source=medium&amp;utm_medium=referral">Joseph Greve</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Understanding GPU Memory Usage in LLM Training: LLAMA-3B Example</h4><p>When training large language models (LLMs), understanding how parameters are stored and processed in GPU memory is crucial. I would strongly recommend knowing Bits and Bytes level details as a prerequisite — it truly helps in grasping these concepts clearly. Let’s briefly unpack this using LLAMA-3B (a model with 3 billion parameters) as an example.</p><h4>Parameter Precision and Memory</h4><p>Parameters can be stored in various precisions, directly influencing GPU memory consumption:</p><ul><li><strong>FP32 (32-bit Floating Point)</strong>: Each parameter takes 4 bytes.</li><li><strong>FP16 (16-bit Floating Point)</strong>: Each parameter takes 2 bytes (commonly used during training).</li><li><strong>INT8 (8-bit Integer)</strong>: Each parameter takes 1 byte (often used for inference to reduce memory and increase speed).</li></ul><h3>Quick Memory Calculations for LLAMA-3B</h3><p>Here’s how quickly memory consumption adds up for 3 billion parameters:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*K-dqKz29-VZFw17Ad0v82g.png" /></figure><h4>Gradients and Optimizer States</h4><p>Training isn’t just parameters. Gradients (same size as parameters) and optimizer states (typically double the parameter size for optimizers like Adam) significantly add to GPU memory usage:</p><ul><li><strong>Weights (FP16)</strong>: ~6 GB</li><li><strong>Gradients (FP16)</strong>: ~6 GB</li><li><strong>Optimizer states (Adam)</strong>: ~12 GB</li></ul><p>Thus, training LLAMA-3B practically requires at least <strong>~24 GB of GPU memory</strong>, excluding temporary activations.</p><h4>Takeaway</h4><p>GPU memory usage isn’t only about parameters. Gradients, optimizer states, and temporary activations multiply memory requirements significantly. Understanding this clearly helps optimize training setups, ensuring efficient utilization of GPU resources.</p><p>Next part is about discussing the metric MFU(Model flop utilization) which is a metric to track our training infrastructure performance.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0b3e4666070" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Embeddings is all you need — Experiment with SimCLR]]></title>
            <link>https://medium.com/@joshanish/embeddings-is-all-you-need-experiment-with-simclr-3397e4b01ea3?source=rss-c83d95871fa1------2</link>
            <guid isPermaLink="false">https://medium.com/p/3397e4b01ea3</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[unsupervised-learning]]></category>
            <dc:creator><![CDATA[Anish]]></dc:creator>
            <pubDate>Sat, 16 Nov 2024 04:02:48 GMT</pubDate>
            <atom:updated>2024-11-16T04:02:48.788Z</atom:updated>
            <content:encoded><![CDATA[<h3>Embeddings is all you need — Experiment with SimCLR</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*NdeTfywqduiHPw6kNKbTjA.png" /></figure><p>In machine learning, we work with different types of data, like images, text, and audio. When the data is well-organized, it’s easier to train or fine-tune models. However, when data isn’t labeled, we often use a technique called Unsupervised learning (learn patterns from the noise) to help our models understand the data’s underlying structure.</p><p>While it’s rare to get a perfect model on the first try, with the right tricks and careful problem setup, we can build strong foundational models. No matter what type of data we’re working with, everything eventually gets represented in a vector space. The key is how we design the representation learning process and choose the metrics that guide the model’s learning.</p><p>An example for images – how can a model learn a pattern from a noisy data. In text its pretty much straightforward, we can train a model to predict next words unleashing model to learn meaningful patterns. In image the problem of predicting next pixels doesn’t seem a plausible task though it can be attained. so, here we take a single image and create two version of it. Two image undergo different set of data augmentation but we know they represent same content. we use pre-trained (ResNet, Efficient-net …) to extract feature vectors (example : dimension of 2048) and project it to vector of some dimension, here it is 128. the objective is to minimize the distance of projected vectors of same image and maximizing distance in vector space of different images.</p><p>Understanding <strong>vector norms</strong> and <strong>transformations</strong> is important for experimenting with different models. Additionally, make sure your way of distorting original to its augmented version doesn’t corrupt the learnable information. For example, in images, consider what kind of information the model is trying to pick up (Geometrical or Pixel ) level details. and for text, think about whether you’re using methods like cross-encoders or semantic search. Small details like these can significantly impact your experiment’s success.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7O5f7-9geTlqejOm_uKRhg.png" /><figcaption>Learning from cluttered data</figcaption></figure><p>The image above illustrates the process of representation learning. The trained model captures valuable features that can be applied to various higher-level tasks. The resulting base model can also be referred to as a foundational model.</p><p>In essence, the images are mapped into a vector space, and the model attempts to identify similar patterns within this space by employing various similarity metrics, such as cosine similarity and Euclidean distance.</p><p>The model is trained to minimize <strong>NT-Xent loss (Normalized Temperature-Scaled Cross entropy loss).</strong> Its not hard as the name sounds. it simply looks like softmax with temperature. This loss function aims to minimize the distance between positive example pairs (similar inputs) while maximizing the distance between negative example pairs (dissimilar inputs).</p><p>The key aspects are:</p><ul><li>The model is trained to optimize this loss function</li><li>It applies temperature scaling to the softmax, controlling the sharpness of the probability distribution</li><li>The goal is to learn embeddings where positive pairs are close together and negative pairs are far apart</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*f8aHXt-VXAwHqM8EzzqKzA.jpeg" /><figcaption>NT-Xent loss function</figcaption></figure><p>A positive pair for training the deep learning model is generated from a single image and its augmented version. It emphasizes that the <strong>image</strong> <strong>augmentation</strong> process plays a key role in the model’s learning capability. since we are associating positive and negative directly from the batch it is good to train with large batch size. The below image depicts this concept.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IsaTHv-AG5muw-UhgyqPNw.png" /><figcaption>Batch of positives and negatives</figcaption></figure><p>The above tricks worked for me with a little bit of experimentation’s. Refer the tutorial notebook below on how it is done.</p><p>Let’s dive into a real-world implementation of a similarity learning model, aka unsupervised learning. We will implement it from scratch for educational purpose and try to investigate how to make things work for anyone.</p><p>The below tutorial implements the idea of SimCLR from scratch exploring the model, loss and unsupervised metrics (clustering)…</p><p><a href="https://github.com/anish9/Deep-Learning-Notes/blob/main/computer_vision/Unsupervised/simCLR_Tensorflow-tutorial.ipynb">Deep-Learning-Notes/computer_vision/Unsupervised/simCLR_Tensorflow-tutorial.ipynb at main · anish9/Deep-Learning-Notes</a></p><p>I would recommend to go through the code for more clarity towards the experiment. The above experiment is done on CIFAR10 unsupervised version.</p><p>Getting started with unsupervised learning models can be a bit intriguing, especially as the mathematical complexity increases. But I believe that’s okay — after all, we’re ultimately trying to uncover patterns within noise, almost like “hacking” a way for the model to learn on its own.</p><p>Another way to look at it is to validate the concepts from a human perspective — ask yourself if the mathematical function and objective actually make sense, kind of like how a baby would learn. If it feels too complex for a baby to grasp, maybe we should rethink it! After all, if a baby can’t make sense of it, who can? Just kidding! Sometimes it works …</p><p>The trained model was directly integrated with T-SNE to reduce the dimensionality of our embedding for visualization, resulting in a representation model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*6H1tMV80Bd1OVIAsMh_q7g.png" /></figure><p>The above cluster explains how good our representation model has learned to represent an image in vector space. This representation model can be leveraged as a backbone for other higher level tasks object detection, image segmentation, key point detection etc…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3397e4b01ea3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AI in Fashion Industry]]></title>
            <link>https://medium.com/@joshanish/ai-in-fashion-industry-i-5bad34c18704?source=rss-c83d95871fa1------2</link>
            <guid isPermaLink="false">https://medium.com/p/5bad34c18704</guid>
            <category><![CDATA[ecommerce]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[business-intelligence]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Anish]]></dc:creator>
            <pubDate>Sat, 01 Oct 2022 19:50:20 GMT</pubDate>
            <atom:updated>2022-10-02T16:41:15.406Z</atom:updated>
            <content:encoded><![CDATA[<p>This blog implies possible applications of AI in the E-Commerce domain and how AI can eliminate several bottlenecks and mundane tasks with respect to product catalog curating and embellishing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eCTx9XAacJCYzb3q37P1UQ.jpeg" /></figure><p>Every product sold in E-Commerce needs a description, we can use AI to generate descriptions which will save plenty of time in product onboarding and cataloging. as an example we have got an AI model which can generate captions given product images that too in seconds!</p><p>The model is a simple <em>Transformer Encoder Decoder</em> that is trained using open-source caption datasets. Below is an example result of what the model is capable of!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*w0QcTpR1vqhOO60KBKOhpg.png" /><figcaption>Example caption generated using AI</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*4yP1fjvm4_WuLrfJMXj8VA.png" /><figcaption>Example caption generated using AI</figcaption></figure><p>The model can pretty much save hours of work and also be accurate enough to accelerate the whole product enrichment pipeline.</p><p>The codes for testing the model can be found here.</p><p><a href="https://github.com/anish9/deep-fashion-captions">https://github.com/anish9/deep-fashion-captions</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5bad34c18704" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Model Interpretation using GradCAM]]></title>
            <link>https://medium.com/@joshanish/model-interpretation-using-gradcam-4d7bcde316a2?source=rss-c83d95871fa1------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d7bcde316a2</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[pytorch]]></category>
            <dc:creator><![CDATA[Anish]]></dc:creator>
            <pubDate>Tue, 03 May 2022 08:03:18 GMT</pubDate>
            <atom:updated>2022-05-03T08:05:26.614Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*prRulpOLv8ef_mlJ9fJeFw.jpeg" /><figcaption>Test Image</figcaption></figure><p>One of the most important tools to have as a deep learning developer is <strong>model debugging</strong> and <strong>model interpretation</strong> tools. The post assumes readers to have some understanding of pre-trained image models, Convolution Neural Network, and Backpropagation algorithm. We will use the above image to emphasize how this tool can be useful.</p><p>In this tutorial, we will practically discuss a simple tool developed for model interpretation using GradCAM( Gradient Class Activation Maps). The following examples are demonstrated with pre-trained I<strong>magenet</strong> weights. The tool is built on top of TensorFlow Keras API.</p><p>Ther interpretations always started with CAM(Class Activation Maps) which had its pros and cons but this post is about GradCAM which had overcome those flaws. A simple description to understand GradCAM is to use the gradients to find which areas of the images are activated for a particular prediction. we can otherwise call it as controlled backpropagation.</p><p>I have curated a few simple points which make it succinct and intuitive for readers to understand the tool in depth.</p><p>Steps followed in GradCAM:</p><ul><li>Load the model and its preprocessors.</li><li>Find the last feature map’s layer name.</li><li>Remove the final activation layers if needed. (usually softmax)</li><li>Use any predicted class indices (tiger, cat, lion) to get the gradient matrix in the final feature map.</li><li>Convert gradient matrix to a vector and multiply it with a feature map. we end up with NrxNcx1(example: 10x10x1) based on the feature map intensity matrix which signifies the important areas model is focusing on.</li><li>we resize the intensity matrix to the original image size for visualization purposes.</li></ul><p>Results Interpretation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*ivGfJp86XwqQLtVv0mEVvQ.png" /><figcaption>result — top predicted label — tiger</figcaption></figure><blockquote>Top1 prediction for the above image was<strong> tiger</strong> and using the tool we are able to reason why the tiger was predicted</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*rSvczrUf6drJ7H3M5k2JEQ.png" /><figcaption>result — top-second predicted label — rock python</figcaption></figure><blockquote>Top2nd prediction for the above image was rock python and using the tool we are able to reason why it was predicted</blockquote><p>This is a simple tool but can be very helpful to know whether the problem is within the dataset or any other model parameter issues. Hope it is useful to anyone who is new to this field.</p><p>Find the codes here : <a href="https://github.com/anish9/Deep-Learning-Notes/tree/main/gradcam_tool">https://github.com/anish9/Deep-Learning-Notes/tree/main/gradcam_tool</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d7bcde316a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dissecting Transformers — Part1]]></title>
            <link>https://medium.com/@joshanish/dissecting-transformers-part1-2df55e234b9a?source=rss-c83d95871fa1------2</link>
            <guid isPermaLink="false">https://medium.com/p/2df55e234b9a</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[transformers]]></category>
            <dc:creator><![CDATA[Anish]]></dc:creator>
            <pubDate>Thu, 17 Feb 2022 19:15:43 GMT</pubDate>
            <atom:updated>2022-02-18T02:10:09.730Z</atom:updated>
            <content:encoded><![CDATA[<h3>Dissecting Transformers — Part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bQrofHKkXJAzsIRc" /><figcaption>Photo by <a href="https://unsplash.com/@hnhmarketing?utm_source=medium&amp;utm_medium=referral">Hunter Haley</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This blog post is about building an intuition on Transformers architecture; we will discuss each component in separate parts. I assume breaking the components into pieces will help us to build a better larger picture of whole transformers. Pre-requisites for understanding these posts include basic knowledge of deep learning and some basic NLP. We will be using TensorFlow, Numpy, to code the components.</p><p>In this part, we will just discuss the <strong>‘self-attention’</strong> which forms the core of any Transformers architecture.</p><p>A simple analogy to get started is in self-attention the whole sequence gets some treatment within them without any external factors. Before that, we will dive into how a raw text is processed before passing it to our self-attention block.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4FgkFRwOU4ddaIvFvrScHA.png" /><figcaption>Figure 1</figcaption></figure><p>Deep Learning models can never process raw text directly. Any model requires an ideal representation of their inputs as vectors; in a naive way, we can call them numbers. In figure 1 we can see the texts are converted to a sequence of numbers named as embedding vector, since we are working on the realm of Natural Language Processing the order of the words matter, we add a positional encoding vector to make sense to those vectors representation and finally, we end at Transformer Input. The above image explains that, but it is always great to see in code to grip it intuitively.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3208797778a35182c8397192bec42547/href">https://medium.com/media/3208797778a35182c8397192bec42547/href</a></iframe><p>Running the above code can generate your transformer input sequence but we actually don’t have a Transformer Encoder, Let&#39;s hold our patience and look at <em>figure2</em> the components of the Transformer block and we will delve into building them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p4sF4mP_z8DCh8-wym1I_Q.png" /><figcaption>Figure 2</figcaption></figure><p>Looking at them as a whole block is intimidating, but that’s why I am writing this post to dissect them, the objective is more intensified where we will understand each of the components and also build them in a plug-and-play manner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/199/1*6pjldxARGOiHbDI5X6pPYQ.png" /><figcaption>Figure 3</figcaption></figure><p>As told earlier we will get back to the term<strong> ‘self-attention’ </strong>which also can be called simple <strong>matrix multiplication(MatMul)</strong> as seen in <em>figure 3</em>. We can see some terms Q, K, and V. They can be called Query, Key, and Value inspired from database systems I assume. These query, key, and value are matrices that are generated from our <strong>Transformer Input.</strong></p><p>Now we have to reason why we do matrix multiplication between query and key matrices, essentially it boils down to finding the relationship between every single word in the sentence to other words. See the below image for reference.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*pGXVvHgEFa7OljnBnMAqUg.png" /><figcaption>Figure 4</figcaption></figure><p>It is now clear we have to understand the relationship between each word to other words in the sentence, this is called self-attention. The picture above <em>Figure 4 </em>explains with texts directly instead of matrices just for understanding. <em>Figure 5 </em>explains it more mathematically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*pXMbujwTnOhN985OtmLwLg.png" /><figcaption>Figure 5</figcaption></figure><p><em>figure 5 </em>is more intuitive when we are able to recollect details of <em>figure1, </em>the only piece we are missing right now is how we reached to query, key, and value matrics from our embedding vector. The query, key, and value are actually are trainable variables so we use a simple dense layer to create their projections. The code should make it clearer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/216/1*P1DTxy4uHHyiHr2ResRGZw.png" /><figcaption>Figure 6</figcaption></figure><p>After MatMul we also see a variable <strong>scale </strong>in <em>figure 6.</em> It is used because when we perform our matrix multiplication based on the sequence length the magnitude of the output will be large which can create problems like gradient explosion, etc… so we will scale by dividing it and applying softmax to weigh the attention scores.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*6EIHZKgJxfS-VeJJE0rMmQ.png" /></figure><p>Now let&#39;s delve into the code of the above pieces, first, we will create a function for ‘scaled dot product’.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9125050c87ab4e790abee101d5764ed6/href">https://medium.com/media/9125050c87ab4e790abee101d5764ed6/href</a></iframe><p>Now let&#39;s create Query, Key, and Value vectors from our previous Transformer Input and pass it to our <strong>scaled_dot_product</strong> function</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/647a8283f756b3ac7da686effdbb2d1c/href">https://medium.com/media/647a8283f756b3ac7da686effdbb2d1c/href</a></iframe><p>Yes, we have covered a small piece but a core component in building transformers, In the next part we will study how to build them as a TensorFlow layer and connect the pieces to train the model.</p><p>Stay Tuned !!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2df55e234b9a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Normality Test’s-part1]]></title>
            <link>https://medium.com/@joshanish/understanding-normality-tests-part1-edc8d54564fc?source=rss-c83d95871fa1------2</link>
            <guid isPermaLink="false">https://medium.com/p/edc8d54564fc</guid>
            <category><![CDATA[hypothesis-testing]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Anish]]></dc:creator>
            <pubDate>Fri, 06 Aug 2021 16:10:21 GMT</pubDate>
            <atom:updated>2021-08-06T16:10:21.148Z</atom:updated>
            <content:encoded><![CDATA[<p>This post assumes the reader to have some knowledge on statistical hypothesis testings, also to know keywords like test statistics, <em>P-value, Critical values,</em> if you are not sure you can read about them which are easy to grasp.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ENpxshUaUApRsDQ9L20bFg.jpeg" /><figcaption>a real-life normal distribution image</figcaption></figure><p>The core reason behind the blog is if you are a data scientist and you are presented with a regression task, the model performs better when values are normally distributed. so will explore how we conduct different normality tests and transform them into a gaussian family.</p><p>why we need a transformation? the answer is <a href="https://scikit-learn.org/stable/auto_examples/compose/plot_transformed_target.html#sphx-glr-auto-examples-compose-plot-transformed-target-py">here</a></p><h4>we can interpret the data as normally distributed or not in two ways.</h4><h4>1. visual interpretation.</h4><blockquote>hist plot</blockquote><blockquote>qq-plot</blockquote><h4>2. statistical interpretation</h4><blockquote>D’Agostino-Pearson Test</blockquote><blockquote>Shapiro-Wilk Test</blockquote><blockquote>Anderson-Darling Test</blockquote><p>let&#39;s discuss these topics in a brief</p><h4>Hist plot</h4><p>hist plot(histogram) helps us visually understand Gaussian distribution, a simple illustration is it follows a bell shape like below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*bI90SiCVkpEofFfJV9ujQA.png" /></figure><p><strong>qq-plot</strong></p><p>Before testing qq-plot, there are two assumptions,<br>we need to have:<br>1) theoretical distribution<br>2) sample distribution</p><p>what is theoretical distribution?<br>This is the distribution which we want to compare our sample distribution.<br>theoretical distributions can be (uniform, gaussian, etc…), it is not limited to Gaussian.</p><p>what is sample distribution?<br>Sample distribution is nothing but our test data. here we compare sample distribution to theoretical distribution using a quantile plot.</p><blockquote>so, the end assumption is if sample distribution matches our theoretical distribution we would find a linear relationship else our sample distribution is different from the theoretical distribution.</blockquote><p>the below plots help us understand more clearly. fig1 shows a linear relationship and fig2 shows a non-linear relationship.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*dwfi9CfhjJSSWm8h-CbhWQ.png" /></figure><p>In the next part, we will discuss statistical normality tests.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=edc8d54564fc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Natural language processing pipelines, working with tokenizers —]]></title>
            <link>https://medium.com/@joshanish/building-natural-language-processing-pipelines-working-with-tokenizers-e03f9925a35c?source=rss-c83d95871fa1------2</link>
            <guid isPermaLink="false">https://medium.com/p/e03f9925a35c</guid>
            <category><![CDATA[machie-learning]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Anish]]></dc:creator>
            <pubDate>Thu, 29 Jul 2021 13:15:27 GMT</pubDate>
            <atom:updated>2021-07-29T13:15:27.273Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*ULVALRI67xd8yGLdnOqX9Q.jpeg" /></figure><p>This excerpt assumes you have some basic knowledge of NLP(natural language processing) and emphasize the codes are based on Tensorflow, though the concept is kept crude.</p><p>As humans, we are enlightened with a gift of reading and understanding a specific language with its nuances auto inclined to our understanding but computers need much more than that, the below picture should help you understand how computers understand Natural Texts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QI_nGVckymAQaTse6dSbZg.png" /></figure><p>YES! They encode each text to a number and sequentially from here, we traverse to mathematical vector space which computers make sense of. To make a transition from words to numbers there are enormous researches that are focusing on the best representation of texts. but today we are not diving into them, we will focus on code first approach where how the NLP pipeline is started.</p><p>The main motivation is when a language model is trained with a set of preprocessing the same setting should be recaptured during inference as well. TensorFlow has a tokenizer API that is powerful enough to do these tasks. also, it can be saved and restored with the same parameters in a new session.</p><p>Below is the code for saving our tokenizer object in a JSON form</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d22a5e11e38cc2865c1de87e7ca639c2/href">https://medium.com/media/d22a5e11e38cc2865c1de87e7ca639c2/href</a></iframe><p>Now, a JSON file will be created encapsulating the settings you prepared for your model, this is somewhat similar to saving checkpoints of a machine learning model.</p><blockquote>so, assume you want to load this saved tokenizer back, the purpose is straightforward either to retrain or push for deployment. the below snippet will help !</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d1f583aef61886cf4d565234be27b59/href">https://medium.com/media/4d1f583aef61886cf4d565234be27b59/href</a></iframe><p>These are very fundamentals but very core concepts when you dive into building model pipelines, from here we will explore building language models using SOTA NLP techniques in different series.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e03f9925a35c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Activation Map Visualization Using GRAD-CAM]]></title>
            <link>https://medium.com/@joshanish/activation-map-visualization-using-grad-cam-196c91f1ecea?source=rss-c83d95871fa1------2</link>
            <guid isPermaLink="false">https://medium.com/p/196c91f1ecea</guid>
            <category><![CDATA[convolutional-network]]></category>
            <category><![CDATA[convolution-neural-net]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Anish]]></dc:creator>
            <pubDate>Wed, 27 Feb 2019 16:30:08 GMT</pubDate>
            <atom:updated>2019-02-27T16:30:08.206Z</atom:updated>
            <content:encoded><![CDATA[<h3>Let&#39;s dig onto what our CNN learns</h3><p>This post assumes that readers have fundamental experience with building Convolution neural networks. we will discuss on what the model is actually focusing towards when the prediction is made. so by knowing this, we can troubleshoot our model and also it helps us on finding which erroneous data caused the trouble. apparently, we can also build confidence that the model is well generalized to do its duty.</p><p>let&#39;s start the post with an example, assume we train a model to recognize dog and ox. assume we have isolated test samples like individual dogs, individual ox, and both ox and dog combined in one single image. The pictorial example is below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*zEEv7xEIAReSoaWHmeOLtQ.jpeg" /><figcaption>GROUND TRUTH: DOG, MODEL PREDICTION: DOG</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*oMX4K0uQx_AxQYIt8znpgQ.jpeg" /><figcaption>GROUND TRUTH: OX, MODEL PREDICTION: OX</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*7FC3EP5DMH3FAsSXFDhG8A.jpeg" /><figcaption>GROUND TRUTH: OX, MODEL PREDICTION:???</figcaption></figure><blockquote><strong><em>confused about the third image??? we will visualize what model will respond below.</em></strong></blockquote><p>we are actually happy because our model classified the top two images well, now imagine we have a powerful security system which threatens when any cow enters our premises and also we have our own dog roaming around our premise the security system relies on our model prediction, the situation is so strict where we cannot give way to errors. so here comes the requirement to know how much we can trust our model though it has proven accuracy on test or validation data.</p><p>For the rescue, we can use the activation map which will provide with some insights representation in form of a heat map. so small math goes behind this.</p><p>When we apply convolution we are actually extracting some features and more the network depth more the features are extracted, and we do not only use convolutional operation but also apply max-pooling and some operations like dropout, batch normalization based on the model requirements.</p><p>But we should break the concept of this network being a black box but how can we do this, knowing what each layer learns can help us to know about certain specific features the model has picked on but in-depth visualizing the activation map helps us to uncover where the model is actually focusing on the image, so how do we do this?</p><p>we need a few pieces of information about our network and they are:</p><p><strong><em>1 ) Final layer weights with respect to the predicted label.</em></strong></p><p><strong><em>2 ) Last convolutional layer feature maps.</em></strong></p><p>Final layer weights will be a vector with one row and <em>n</em> columns</p><p>Last Convolutional feature maps depend on the number of filters you have on final conv layers with weights dimension(filter dims)</p><p>when we perform dot product on the following pieces with respective shape structuring we end up on our heat map, activation visualization</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*8KerMbHx9-xB3al6-uVjKA.gif" /></figure><p>Below is the solution on which features our built model focused. it&#39;s very clear there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/261/1*GDEl8Ro04zSFYJrukQuGcA.png" /><figcaption>activations</figcaption></figure><p>the model focuses on ox as well as on the dog but we have softmax which will vote for the final winner and that was taken by</p><p>NOTE: THE WEIGHTS USED HERE ARE IMAGENET WEIGHTS AND ARCHITECTURE IS RESNET50</p><blockquote>‘Ibizan_hound’, 0.44107217),<br> ‘oxcart’, 0.31538963),<br> ‘whippet’, 0.05961798),<br> ‘Chihuahua’, 0.042450495),<br>‘English_foxhound’, 0.041694112),<br> ‘ox’, 0.04060103),<br> ‘bighorn’, 0.019826991),<br> ‘malinois’, 0.007009227),<br> ‘Labrador_retriever’, 0.005062857),<br> ‘dingo’, 0.004050529)]]</blockquote><p>I hope comparing the predicted output with an activation map shows some intense connections and reveals some useful insights. let&#39;s have some more activation maps below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/261/1*f0FtrwUf7XkwQjcwU3rtAw.png" /><figcaption>activation for dog image</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/261/1*2YiBN4YU_Z39WH1BVmNELg.png" /><figcaption>activation for ox image</figcaption></figure><p>it shows that the model really focuses on ox and dog even though the model has additional noise factors. I hope this post helped you with understanding a small portion on how to troubleshoot your network and know whether the model has really learnt something. I will share the function which does this calculation for you on the future post.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=196c91f1ecea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating object detection system using Tensorflow API explained]]></title>
            <link>https://medium.com/@joshanish/creating-object-detection-system-using-tensorflow-api-explained-1037a406cc22?source=rss-c83d95871fa1------2</link>
            <guid isPermaLink="false">https://medium.com/p/1037a406cc22</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[object-detection]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Anish]]></dc:creator>
            <pubDate>Wed, 28 Nov 2018 17:43:14 GMT</pubDate>
            <atom:updated>2018-11-28T17:43:14.994Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ABi6irBxDXeOECQUfYRZGQ.jpeg" /></figure><p>Machine learning and deep learning has created wonders and precisely they have done the job only because tons of data. Today we will be building our object detection system using tensorflow object detection API .</p><p><a href="https://github.com/tensorflow/models/tree/master/research/object_detection">models/research/object_detection at master · tensorflow/models</a></p><p>STEP1 :</p><p>Installation of dependencies (follow the below link to install)</p><p><a href="https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md">tensorflow/models</a></p><p>STEP2 :</p><p>In tensorflow object detection API the data is fed in the form of TFRecord (tensorflow native file format) so, we are supposed to convert our object detection data into TFRecord format.</p><p>I will explain what is this TFRecord in short, it is a binary data format for which interacts with tensorflow API in an advanced way improving data processing format and optimising performance and saving memory.</p><p>the documentation for tensorflow protobuf creation is given below.</p><p>TO MAKE IT EASY FOLLOW</p><p><a href="https://github.com/tensorflow/tensorflow/blob/r1.12/tensorflow/core/example/example.proto">tensorflow/tensorflow</a></p><p>once TFRecord files are created we are on the stage for building our object detection model and before training we are required to configure the config file.</p><p>a sample config file can be viewed in the below link</p><p><a href="https://github.com/anish9/Python-Codes/blob/master/sample_config_faster%20rcnn">anish9/Python-Codes</a></p><p>PARAMETER 1:(Note: this is a sample config for Faster R-CNN and users can chooses different configs like SSD.</p><h4><strong><em>model config:</em></strong></h4><blockquote><strong>model {<br> faster_rcnn {<br> num_classes: 90 </strong>NOTE:COCO DATASET CONTAINS 90 CLASSES<strong><br> image_resizer {<br> keep_aspect_ratio_resizer {<br> min_dimension: 600 <br> max_dimension: 1024<br> }<br> }</strong></blockquote><h4><strong><em>CHANGES TO BE MADE:</em></strong></h4><blockquote><em>CHANGE THE NUM_CLASSES AS PER YOUR DATASET</em></blockquote><h4>TRAINING CONFIG:</h4><blockquote><strong><em>train_config {<br> batch_size: 1<br> data_augmentation_options {<br> random_horizontal_flip {<br> }<br> }<br> optimizer {<br> momentum_optimizer {<br> learning_rate {<br> manual_step_learning_rate {<br> initial_learning_rate: 0.000300000014249<br> schedule {<br> step: 0<br> learning_rate: 0.000300000014249<br> }<br> schedule {<br> step: 900000<br> learning_rate: 2.99999992421e-05<br> }<br> schedule {<br> step: 1200000<br> learning_rate: 3.00000010611e-06<br> }<br> }<br> }<br> momentum_optimizer_value: 0.899999976158<br> }<br> use_moving_average: false<br> }</em></strong></blockquote><p>CHANGES TO BE MADE:</p><p>adjust the training parameters such as learning rate and also schedule it based on time steps.</p><p>Final changes:</p><blockquote><strong><em>train_input_reader {<br> label_map_path: “PATH_TO_BE_CONFIGURED/mscoco_label_map.pbtxt”<br> tf_record_input_reader {<br> input_path: “PATH_TO_BE_CONFIGURED/mscoco_train.record”<br> }<br>}<br>eval_config {<br> num_examples: 8000<br> max_evals: 10<br> use_moving_averages: false<br>}<br>eval_input_reader {<br> label_map_path: “PATH_TO_BE_CONFIGURED/mscoco_label_map.pbtxt”<br> shuffle: false<br> num_readers: 1<br> tf_record_input_reader {<br> input_path: “PATH_TO_BE_CONFIGURED/mscoco_val.record”<br> }<br>}</em></strong></blockquote><p><strong><em>THE FILE</em> </strong>“<strong><em>mscoco_label_map.pbtxt” SHOULD BE CREATED ON THE BELOW FORMAT</em></strong></p><p>item {<br> id: 1<br> name: ‘car’<br>}</p><p>item {<br> id: 2<br> name: ‘truck’<br>}</p><p>item {<br> id: 3<br> name: ‘pedestrian’<br>}</p><p><strong><em>NOTE</em></strong>: when creating <strong>.pbtxt</strong> file always start with 1 because 0 is represented as background.</p><p><em>eval configs</em>: it emphasis test data or validation data</p><p><em>input_path</em> : the folder path for created train.record and val.record(TFRecord file) the above config file is created for training on ms coco dataset.</p><p>once the config file is configured next step is to start the training. as told we have to clone the tensorflow models repo. once it is done go to object_detection folder and run the following code to start training.</p><blockquote><strong>python train.py — logtostderr — train_dir=/home/josh/odet/coco/config_files — pipeline_config_path=/home/josh/odet/coco/config_files/config_files/faster_rcnn_resnet101_logo.config</strong></blockquote><p>In my next blog Iwill release the automated procedure for creating TFRecord format where you can use it to create your own training data and train your personal object detector, also Iwill explain tensorflow zoo and utilising pre-trained models .</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1037a406cc22" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>