<?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 Vishnu Nandakumar on Medium]]></title>
        <description><![CDATA[Stories by Vishnu Nandakumar on Medium]]></description>
        <link>https://medium.com/@nkumarvishnu5?source=rss-da4c4665052f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Jz7I1OFYBbDkkLkPyssupg.jpeg</url>
            <title>Stories by Vishnu Nandakumar on Medium</title>
            <link>https://medium.com/@nkumarvishnu5?source=rss-da4c4665052f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 23:27:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nkumarvishnu5/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[CoverMe: Your Ultimate Tool for Personalized Cover Letters and LinkedIn Messages]]></title>
            <link>https://nkumarvishnu5.medium.com/coverme-your-ultimate-tool-for-personalized-cover-letters-and-linkedin-messages-f9edcdfaf219?source=rss-da4c4665052f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9edcdfaf219</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[llm-applications]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Vishnu Nandakumar]]></dc:creator>
            <pubDate>Fri, 11 Oct 2024 15:43:36 GMT</pubDate>
            <atom:updated>2024-10-11T15:43:36.925Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*jb7R6xa71t4sX9u7.jpg" /></figure><p>In today’s competitive job market, standing out is more important than ever. That’s where <strong>CoverMe</strong> comes in — a powerful Streamlit application designed to help you craft personalized cover letters and LinkedIn messages that you want to send to your recruiters. By leveraging advanced techniques like the <strong>Retrieval-Augmented Generation (RAG)</strong> approach, CoverMe ensures that your application materials are not only tailored to your unique qualifications but also highly relevant to the job at hand.</p><p><strong>What is CoverMe?</strong></p><p>CoverMe simplifies the job application process by generating customized cover letters and LinkedIn messages based on your resume and the job description. This means you can present yourself in the best light possible without spending hours crafting each document from scratch.</p><ul><li><strong>Cover Letter Generation</strong>: Using your resume and the specific job description, CoverMe creates a personalized cover letter that highlights your qualifications and aligns perfectly with the role you’re applying for.</li><li><strong>LinkedIn Message Generation</strong>: The app goes a step further by generating tailored LinkedIn messages aimed specifically at HR professionals. This feature is invaluable for networking and making a strong first impression.</li></ul><p><strong>What is RAG?</strong></p><p>So, what exactly is the <strong>Retrieval-Augmented Generation (RAG)</strong> framework? It’s an innovative AI technique that combines information retrieval with generative models to improve the quality of outputs. Here’s how it works:</p><ul><li><strong>Indexing Your Documents:</strong> When you upload your documents, CoverMe indexes it, creating a embedding of the encoded texts which makes it semantically searchable</li><li><strong>Semantic Search</strong>: When you input a job description, RAG performs a semantic search to identify relevant snippets from your indexed documents that match the query. Using the retreived information from the indexed documents, we can update the prompt to generate via LLM</li></ul><p><strong>Benefits of Using RAG</strong></p><ul><li>RAG improves the relevance and accuracy of generated content by accessing up-to-date information via the indexed documents.</li><li>It maintains coherence in responses, making them more context-aware and relevant to user queries.</li><li>By grounding outputs in verified sources, RAG minimizes inaccuracies often found in traditional generative models</li><li>RAG allows for easy updates without retraining the entire model, ensuring timely information delivery.</li><li>It provides a simpler and more economical way to customize models with current data without extensive retraining.</li></ul><p><strong>Getting Started with CoverMe</strong></p><ul><li>Start by cloning the CoverMe repository from GitHub:</li></ul><pre>git clone https://github.com/Vishnunkumar/CoverMe.git</pre><ul><li>Navigate into the project directory:</li></ul><pre>cd CoverMe</pre><ul><li>Install the necessary packages using pip:</li></ul><pre>pip install -r requirements.txt</pre><ul><li>To launch the application, use:</li></ul><pre>streamlit run app.py</pre><p>You can access it in your web browser at `<a href="http://localhost:8501`">http://localhost:8501`</a>. You can see a app like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*Q921K4Z1l6OoecmIVqu1YQ.png" /></figure><p><strong>Create Your Cover Letter and LinkedIn Message</strong><br>1. Start by uploading your resume.<br>2. Enter the job description for the position you’re interested in.<br>3. Select from the dropdown to select Cover letter or LinkedIn Message.<br>4. Copy your cover letter and LinkedIn message for easy sending!</p><p><strong>Also, we have deployed an application in the streamlit cloud where you can use it for free. Do try it out </strong><a href="https://coverme.streamlit.app/"><strong>here</strong></a></p><p><strong>Final Thoughts</strong></p><p>CoverMe is here to make your job search easier and more effective! By harnessing the power of RAG, this app provides you with personalized cover letters and LinkedIn messages that truly reflect your qualifications. So why wait? Give it a try, and take a confident step toward landing your dream job! Happy networking!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9edcdfaf219" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tuning with PEFT: LLMs are no-more a heavyweight.]]></title>
            <link>https://nkumarvishnu5.medium.com/tuning-with-peft-llms-are-no-more-a-heavyweight-81eab831c074?source=rss-da4c4665052f------2</link>
            <guid isPermaLink="false">https://medium.com/p/81eab831c074</guid>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[hugging-face]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[transformers]]></category>
            <category><![CDATA[ml-so-good]]></category>
            <dc:creator><![CDATA[Vishnu Nandakumar]]></dc:creator>
            <pubDate>Thu, 03 Aug 2023 13:11:09 GMT</pubDate>
            <atom:updated>2023-08-03T13:11:09.774Z</atom:updated>
            <content:encoded><![CDATA[<h3>Tuning with PEFT: LLMs are no more a heavyweight.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KdZCeXwmXQJX7ZAfj4qYuA.jpeg" /><figcaption>LLMs</figcaption></figure><p>The process of fine-tuning large language models (LLMs) can be a time-consuming and resource-intensive task. Traditionally, this requires significant computational power and storage capacity, making it difficult for individuals or organizations without access to high-end hardware to participate in this field. However, there is now a new approach that promises to change all that — PEFT. This innovative method allows users to achieve similar results as traditional fine-tuning techniques but with only a p100 GPU on Kaggle. In this article, we will explore how PEFT works and how it overcomes common challenges associated with fine-tuning LLMs.</p><p><strong>What is PEFT?</strong></p><p>PEFT stands for Parameter Efficient Fine-Tuning. As the name suggests, it freezes unwanted parameters and only trains the relevant ones — to create a powerful approach for fine-tuning LLMs with minimal resources. By leveraging these techniques together, PEFT enables users to significantly reduce the size of their models while maintaining efficiency.</p><p><strong>Overcoming Challenges in Dealing with LLMs</strong></p><p>One major challenge associated with fine-tuning LLMs is the sheer amount of computation required for training and inference. With PEFT, users can achieve similar results with just a p100 GPU on Kaggle. Additionally, PEFT addresses two other critical issues faced by LLMs — catastrophic forgetting and storage requirements.</p><p>Catastrophic forgetting occurs when an LLM is fine-tuned for multiple downstream tasks and begins to forget previous knowledge learned from earlier tasks. To address this issue, PEFT utilizes a technique called LoRA (<a href="https://arxiv.org/abs/2106.09685">Low-Rank Adaptation of Large Language Models</a>), which encourages the model to focus more on the current task rather than remembering past ones. This ensures that the model remains accurate across all tasks while still retaining its ability to learn new concepts quickly.</p><p>Another problem facing LLMs is the massive storage requirements necessary to store these models. Since PEFT reduces the size of the model drastically, it makes it easier to store and inferencing.</p><p>There are different ways to approach PEFT and they are listed below on a high level.</p><ul><li><strong>LoRA: </strong>Injection of trainable low-rank weights to each layer of transformers and freezing of the whole model.</li><li><strong>Prefix tuning: </strong>Rather than finetuning the whole model, we keep language model parameters frozen and optimize only a sequence of continuous task-specific vectors</li><li><strong>Prompt-tuning:</strong> Effective mechanism for learning “soft prompts” to condition frozen language models to perform specific downstream tasks, these soft prompts are learned through backpropagation and unlike the hard prompts used in fine-tuning models.</li></ul><p>Below I have shared links for the model and notebook that I have created for an NLI knowledge graph task, please have a try and provide your feedback.</p><p>Notebook: <a href="https://www.kaggle.com/code/vishnunkumar/peft-nligraph">https://www.kaggle.com/code/vishnunkumar/peft-nligraph</a><br>Model: <a href="https://huggingface.co/vishnun/lora-NLIGraph">https://huggingface.co/vishnun/lora-NLIGraph</a></p><p>For inference, please follow the below</p><pre><br>from transformers import AutoTokenizer, AutoModel<br>from peft import get_peft_config, PeftModel, PeftConfig, get_peft_model, LoraConfig, TaskType<br><br>peft_model_id = &quot;vishnun/lora-NLIGraph&quot;<br>config = PeftConfig.from_pretrained(peft_model_id)<br>inference_model = AutoModelForTokenClassification.from_pretrained(<br>    config.base_model_name_or_path, num_labels=4, id2label=id2lab, label2id=lab2id<br>)<br>tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)<br>model = PeftModel.from_pretrained(inference_model, peft_model_id)<br><br>text = &quot;Arsenal will win the Premier League&quot;<br>inputs = tokenizer(text, return_tensors=&quot;pt&quot;)<br><br>with torch.no_grad():<br>    logits = model(**inputs).logits<br><br>tokens = inputs.tokens()<br>predictions = torch.argmax(logits, dim=2)<br><br>for token, prediction in zip(tokens, predictions[0].numpy()):<br>    print((token, model.config.id2label[prediction]))<br><br>## results : (&#39;&lt;s&gt;&#39;, &#39;O&#39;)<br>(&#39;Arsenal&#39;, &#39;SRC&#39;)<br>(&#39;Ġwill&#39;, &#39;O&#39;)<br>(&#39;Ġwin&#39;, &#39;REL&#39;)<br>(&#39;Ġthe&#39;, &#39;O&#39;)<br>(&#39;ĠPremier&#39;, &#39;TGT&#39;)<br>(&#39;ĠLeague&#39;, &#39;O&#39;)<br>(&#39;&lt;/s&gt;&#39;, &#39;O&#39;)</pre><p>Until then, thanks and highly grateful to all the readers. :)</p><h4><a href="https://mlearning.substack.com/about">WRITER at MLearning.ai</a> // <a href="https://open.substack.com/pub/mlearning/p/ultimate-guide-fully-control-ai-video-generation?r=z7zu8&amp;utm_campaign=post&amp;utm_medium=web">Control AI Video</a> 🗿<a href="https://open.substack.com/pub/mlearning/p/image-to-3d-one-click-ai-tool-modeling-video-txt?r=z7zu8&amp;utm_campaign=post&amp;utm_medium=web">/imagine AI 3D Models</a></h4><p><a href="https://medium.com/mlearning-ai/mlearning-ai-submission-suggestions-b51e2b130bfb">Mlearning.ai Submission Suggestions</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81eab831c074" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Write to get the Video, yes that’s what Meta AI has given us!]]></title>
            <link>https://nkumarvishnu5.medium.com/write-to-get-the-video-yes-thats-what-meta-ai-has-given-us-af93d9a6d5d3?source=rss-da4c4665052f------2</link>
            <guid isPermaLink="false">https://medium.com/p/af93d9a6d5d3</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[meta]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[Vishnu Nandakumar]]></dc:creator>
            <pubDate>Tue, 04 Oct 2022 04:48:08 GMT</pubDate>
            <atom:updated>2022-10-04T06:24:19.801Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UWYkF-dmj0Ypo--_wCSQEg.jpeg" /></figure><p>Wow! Meta AI just dropped a huge nuclear bomb in the AI world, what if someone said we could make a video out of text a decade or more back we would have simply said “Yes and in our dreams”. Fast forward to a few years and now it&#39;s a reality. Jump into <a href="https://makeavideo.studio/">make-a-video</a> to see the unimaginable develop into reality before your eyes. Below you can see one of the examples from the website.</p><p>GANs and their variations created a huge impact and changed the way people started to see AI and its growth. It led a lot of researchers to think beyond the boundaries and achieve the potential that was out there. Another incredible creation was the diffusion models which made the internet go crazy and create threads and accounts on different social media platforms. DALL-E is essentially a text-to-image generation model with an underlying diffusion-based model. DALL-E makes use of GPT3 text- embeddings to interpret and generate corresponding images. Stable diffusion is another model that produces images using text prompts with underlying CLIP text embeddings to understand the text prompts and generates images using the diffusion model. There have been a lot of further models that have come into existence these days like Midjourney</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*unRIwGYjixBytmXvWYKe9Q.png" /><figcaption>Outputs from different diffusion based-models</figcaption></figure><p>Unlike diffusion models, Make a Video works in a different manner. It doesn’t need a text-video paired dataset but makes use of pre-trained text-to-image models. They have used temporal diffusion-based models which accelerate the training process by instantaneously transferring the knowledge from a pre-trained T2I network to a new T2V one. Also since the temporal information gets included in the model initiation stage, this adds to decreased training time. Attention modules in the extended spatial-temporal help in learning the temporal dynamics of videos. Finally, the integration of super-resolution models and frame interpolation models increases the visual quality of the generated videos. As I have given only the brief and my understanding could also be different, it would be really great if you could through the <a href="https://arxiv.org/pdf/2209.14792.pdf">research paper</a> published.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*H5JkQMtFiI5yAk6GhWUevw.gif" /><figcaption>Young couple walking in rain — prompt used in Meta AI example</figcaption></figure><p>Above is one of the examples that was provided by Meta-AI on their <a href="https://makeavideo.studio/">Make a Video</a> website. You could also sign-up to get access to try out by filling out the <a href="https://forms.gle/dZ4kudbydHPgfzQ48">form</a>, probably they could put you on the waiting list also :X</p><p>That’s all folks for now, to me this is a piece of huge news from Meta AI. I hope you also felt the same.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af93d9a6d5d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Crop and Segment images using OpenAI’s CLIP]]></title>
            <link>https://nkumarvishnu5.medium.com/crop-and-segment-images-using-openais-clip-8346139425fb?source=rss-da4c4665052f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8346139425fb</guid>
            <category><![CDATA[hugging-face]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ml-so-good]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[openai]]></category>
            <dc:creator><![CDATA[Vishnu Nandakumar]]></dc:creator>
            <pubDate>Tue, 14 Jun 2022 17:01:07 GMT</pubDate>
            <atom:updated>2022-06-14T17:01:07.202Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gAaNe0qEizwzu-jtpiUoOw.jpeg" /></figure><p>Ever wondered if we can crop out sections in an image depending upon our interest or segment out images based on our wishes by just using a word query, well there is a way that we can work out to achieve the same. Leveraging OpenAI’s CLIP and DeTr’s (any other can also be used) computer vision models we can segment and crop out sections of images using simple text queries. Cropping out sections can be achieved using a combination of object detection models and CLIP by deriving the probabilities of each detected section of images for the text that was queried for. While to get the segment we have to just replace the object detection model with the panoptic segmentation models.</p><p><strong>What is CLIP?</strong></p><p>Briefly, <strong>CLIP (Contrastive Language Image Pre-training)</strong> is a zero-shot learning method devised by the famous OpenAI for tackling multi-modal problems. A number of text-image pairs were chosen and their encodings were computed to create an <strong><em>(N-no of images*M-no of texts) </em></strong>matrix with each representing a similarity score between each text and image as a pre-training step. Assuming we want to perform zero-shot image classification, we should encode the image and the set of texts into embeddings using the pre-trained tensor. By sorting the computed similarity score we can determine the more relevant text to the image and vice-versa in case of finding out the perfect image from the set of images (image neural search).</p><p>In our scenario, we are extending the same principle to crop/segment out sections from the image. To make it easy I have created a simple python library <a href="https://pypi.org/project/clipcrop/">clipcrop</a> (still developing) to perform the same. To perform the object detection and image segmentation task I have used Facebook’s DeTr as it is faster and more accurate when compared to conventional single-stage or two-stage detectors. What&#39;s more, you can even leverage HuggingFace pipelines to accomplish the same. Below I have attached examples of both the features.</p><p><strong>Implementation</strong></p><ul><li>Install the library using <strong><em>pip install clipcrop</em></strong></li><li>Crop sections of objects from the image using</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gpLbGwPMbtJrFjxwoUmMRg.png" /></figure><ul><li>Extract segments from the image using</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5IhX61Nyiz2t4iq53rBn0A.png" /></figure><p>So from above, we see that we can either crop out sections or segments by leveraging OpenAI’s CLIP and Facebook’s DeTr models. I will continue upgrading with more options and functionalities to improve the library. For further info, please jump on to the below-mentioned repo.</p><p><strong>Sources:</strong></p><ul><li>Github: <a href="https://github.com/Vishnunkumar/clipcrop">https://github.com/Vishnunkumar/clipcrop</a></li><li>PyPi: <a href="https://pypi.org/project/clipcrop/">https://pypi.org/project/clipcrop/</a></li></ul><p>That’s a wrap thank you for the immense support that you have shown to me and let’s continue this journey. Let’s grow together and learn together. Until next time, bye and take care.</p><p><a href="https://medium.com/mlearning-ai/mlearning-ai-submission-suggestions-b51e2b130bfb">Mlearning.ai Submission Suggestions</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8346139425fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Skew correction in Documents using Deep learning.]]></title>
            <link>https://nkumarvishnu5.medium.com/skew-correction-in-documents-using-deep-learning-8e19609107b6?source=rss-da4c4665052f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e19609107b6</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[ml-so-good]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[document-processing]]></category>
            <category><![CDATA[computer-vision]]></category>
            <dc:creator><![CDATA[Vishnu Nandakumar]]></dc:creator>
            <pubDate>Mon, 07 Feb 2022 16:30:48 GMT</pubDate>
            <atom:updated>2022-02-07T16:30:48.091Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*maJwckO0NdnP23YUQ-5tTA.jpeg" /></figure><p>We all would have stumped on to a problem where the documents that we have will be misaligned, skewed and also could be warped. A lot of image scanners will ask us to rotate the images by ourselves or ask us to choose the four points for modification of perspective. Actually, I have to give credit to my <a href="https://twitter.com/kavinsharath">Twitter buddy</a> Kavin Sharath who came up with this problem of skewness in the documents and propelled me to look for a solution using machine learning. We also took different approaches like Hough lines transformation, binarizing to find only text regions and their contours, detection of contours and so on but most of them could not generalize in most cases. We are aware that a lot of these image processing techniques works well and one of the best in the retrieval of skewness is using the projectile profile method.</p><h3>Projectile Profile</h3><p><a href="http://www.cvc.uab.es/~bagdanov/pubs/ijdar98.pdf">PP</a> is a technique in which we will rotate a given image in different angles for a range and compute the maximum difference between the peaks of the histogram of pixels of that image at each angle. The difference between the angles for which we get the maximum difference is what will be our angle of rotation for skew correction.</p><p><strong>Pros:</strong></p><ul><li>No model training/building is required</li><li>Works on most of the real-world scenarios with documents of mild skewness</li><li>Can be easily integrated into any application</li></ul><p><strong>Cons:</strong></p><ul><li>If we increase the range of angles then processing would take a long time to complete</li><li>No generalized range of angle as each image might require a different set of ranges.</li></ul><h3><strong>Machine learning:</strong></h3><p>I have tried to build a CNN based regression model here to generate angles at which the skewness needs to rectify.</p><p><strong>Data Preparation:</strong></p><p>For a problem like this, we might have data available online yet we can try and build our own data for this task. First, download a set of document images using <a href="https://pypi.org/project/bing-image-downloader/">bing-image-downloader</a>, then iterate your images using the below snippet.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/430c35015994d5adc715fcdb724c9177/href">https://medium.com/media/430c35015994d5adc715fcdb724c9177/href</a></iframe><p>What essentially happens in the above snippet is:</p><ul><li>We are iterating through a set of images at different angles chosen randomly.</li><li>Angle range is [-45, 45]</li><li>White colour is filled for images after rotation to ensure consistency as similar to real-world scenarios.</li><li>A grayscale image is saved with proper naming with iteration and angle value.</li></ul><p><strong>Model building:</strong></p><p>I am using a simple CNN model for training the regressor here, before constructing the model we need to process the data in a way that the CNN model would learn in an optimized way. Below are the steps that I have implemented for preprocessing images.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d4ad6d05e9eef6dfa07f74cee4ffbd76/href">https://medium.com/media/d4ad6d05e9eef6dfa07f74cee4ffbd76/href</a></iframe><p>I haven’t used other augmentation steps like crops, rotation etc because that would sabotage the intention of this solution, so I have only scaled the angles and images as per the necessity. Feel free to try other augmentation methods which will not vandalize the orientation and spatial features.</p><p>Next is defining the model, I have built a relatively shallow model because of the intuition that our output is continuous value and we are not in for learning complicated features like if the texts are of slanting characters, do they have lines or even if they are handwritten or not etc. Below is the model summary.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e0cfe13042df1a2641e87db1f4fc90e/href">https://medium.com/media/8e0cfe13042df1a2641e87db1f4fc90e/href</a></iframe><p>Make sure that your last layer doesn’t have relu as the activation function as we also have negative values as output and the advantage of using Global MaxPooling is we can train the model faster and weights will smaller in size. This model is 9 MB in size we can also do much better than what I got here. That’s it go and define other training parameters like batch_size, epochs, tensorboard logging, early stopping etc and train the model. I have attached the results of the training of my model. The params that I have chosen are given in the notebook which I have attached at the end.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*uBk5w2v6kdLHIZrFCs4eTA.png" /></figure><ul><li><em>Also, you can find some of the results as followed.</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*ixJilhqrktaUUYz0EnTVSQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*zGh3OMFCz3L4KIhEfpdscQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*W6ZGH7k4JdXEFp0w1cn22Q.png" /></figure><p>Above we can see the results are quite satisfying and from here you can try out with varied data like handwritten documents for training, you can also try out a multi-task model by having the first task as classification whether you have to rotate clockwise or anticlockwise and second would be by how much you have to rotate the same. Another con of this model is it might not perform well if there is no skew in the document given, well again you can try a multi-task model with the third task of skew/no_skew or simply a single task learner with 0 as the output value for inputs with no skew. You can also have a look at the notebook provided at the end</p><ul><li><em>Experiment with non-English language (I believe it’s Arabic, Sorry if I am wrong) with handwritten text.</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*DJ6REOweZU5T0-_aUbrhBg.png" /></figure><ul><li><em>On a non-skew image</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*tKKyeLUzDwrwep2mK78UAA.png" /></figure><p>Just for the record, I am not bluffing on the above scenario. The model gave 0 as the output as we wanted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*NOIXyQGvt0BVWef8tHOSbA.png" /></figure><p>As much as the model seems to perform well on different scenarios, it could well be an exception, to be on the safer side it is better to build a model with varied and adequate data. But I will try to validate the model with more data and provide the metrics on my repo.</p><p>Okay, folks, I hope this is useful and helpful for you all. I will continue to contribute as much as I can. Until then bye you all and take care. Feel free to have a look at the following for more information</p><ul><li>Kaggle Notebook: <a href="https://www.kaggle.com/vishnunkumar/skew-detection">https://www.kaggle.com/vishnunkumar/skew-detection</a></li><li>Github Profile: <a href="https://github.com/Vishnunkumar">https://github.com/Vishnunkumar</a></li></ul><p>Thanks to you all who have given your valuable time on reading through this. Take care fellas. Bye until next time</p><p><a href="https://medium.com/mlearning-ai/mlearning-ai-submission-suggestions-b51e2b130bfb">Mlearning.ai Submission Suggestions</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e19609107b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AI in the real world — 3. Make your own Grammarly]]></title>
            <link>https://nkumarvishnu5.medium.com/ai-in-the-real-world-3-make-your-own-grammarly-36348d3f1c62?source=rss-da4c4665052f------2</link>
            <guid isPermaLink="false">https://medium.com/p/36348d3f1c62</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ml-so-good]]></category>
            <category><![CDATA[grammar]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[pytorch]]></category>
            <dc:creator><![CDATA[Vishnu Nandakumar]]></dc:creator>
            <pubDate>Sat, 18 Dec 2021 08:32:44 GMT</pubDate>
            <atom:updated>2021-12-18T08:32:44.432Z</atom:updated>
            <content:encoded><![CDATA[<h3>AI in the real world — 3. Make your own Grammarly</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*RGiOY0Du1eQ70CVWWR5u1g.jpeg" /></figure><p>Grammarly is one of the major breakthroughs that AI has made in this decade. I am presuming that most of us know what Grammarly is and how we are hugely benefited by such a tool. What if I tell you that you can make your own minimal spell corrector tool easily without expertise in coding using <a href="https://huggingface.co/docs/transformers/index">Transformers</a>. Well, let’s not wait and dive into the post.</p><p>To my understanding, the complimentary version of Grammarly does these three major tasks:</p><ul><li>Look for <strong>spelling errors</strong></li><li><strong>Paraphrase</strong> the sentences</li><li>Provides us with the <strong>emotion </strong>of the sentences</li></ul><p>So we will not be able to achieve performance similar to Grammarly but we can easily reach base accuracy by building a simple sequence to sequence model for spelling errors and zero-shot learner for the classification task.</p><h3>Prerequisites</h3><ul><li>A system with at least 2GB of GPU support</li><li>Transformers</li><li>Torch</li><li>Around 50k random sentences of data</li></ul><h3>Modelling</h3><p>For building any model we need data, if you can’t get enough data fear not, use any text generation models like GPT or even any text to text generation models that would work to generate around 50k to 100k sentences. Then use this simple piece of code to randomly impute spelling errors in the sentences so that now you’ll have a source as corrupted sentences and target as grammatically correct sentences.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ead52be11e713b8a4ac5e146f13eb57/href">https://medium.com/media/8ead52be11e713b8a4ac5e146f13eb57/href</a></iframe><p>The above code snippet would impute errors in randomly selected words of a sentence. The parameter <strong><em>n_words </em></strong>is how we can control how many words in a sentence do we need to impute the errors on.</p><p>I have taken T5 small and used around 50k sentences as the dataset for building the model. The main reasons for choosing a T5 model are because they are one of the best in seq-seq modelling tasks, and due to the attention mechanism in the transformers, they outclass LSTMs or RNNs with regards to efficiency and performance. For implementing the modelling part you can look into the official tutorial of <a href="https://github.com/huggingface/notebooks/blob/master/examples/summarization.ipynb">transformers</a>. The mentioned notebook explains fine-tuning a t5-small model for summarization task, but by changing the prefix for each sentence you can fine-tune it for a different task as your wish. If you want to skip all these and need a simple wrapper with configurable parameters feel free to try out <a href="https://www.kaggle.com/vishnunkumar/neuspell">this</a>. This is basically a simple wrapper that I wrote for fine-tuning NLP models currently, it supports only these three:</p><ul><li>bert-base-uncased for classification tasks</li><li>t5-small for seq-seq tasks.</li></ul><p>Once you have fine-tuned your model you try out yours or use the below code snippet to leverage the one which I have already fine-tuned on.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/383455b74a549d2e56565c21d3b9e99c/href">https://medium.com/media/383455b74a549d2e56565c21d3b9e99c/href</a></iframe><p>The above code instantiates two transformers models respectively for the spell correction and classification of emotion in the sentence given. For the latter kindly go through the documentation given by transformers on <a href="https://huggingface.co/docs/transformers/v4.14.1/en/main_classes/pipelines#transformers.ZeroShotClassificationPipeline">zero-shot</a> classification. Please find below a simple example of how the above code works</p><pre>input_text = input()<br>gram = Grammarly(input_text)<br>gram.grammarly()</pre><p><strong>Output:</strong></p><pre>input_text = I am happu to inform that w ehave won the competetio</pre><pre>{&#39;emotion&#39;: &#39;happy&#39;,<br> &#39;emotion_score&#39;: 0.5591591596603394,<br> &#39;modified_text&#39;: &#39;I am happy to inform that i have won the competition&#39;}</pre><pre><br>input_text = That is sad to har the passing away of hs grandfather</pre><pre>{&#39;emotion&#39;: &#39;sad&#39;,<br> &#39;emotion_score&#39;: 0.5666968822479248,<br> &#39;modified_text&#39;: &#39;That is sad to have the passing away of his grandfather&#39;}</pre><p>Well, we would not be completely satisfied with what we have seen above but at least there is a significant part where the spell corrector was able to rightly get the word that is incorrect and replaces it with words that would be semantically near to the context of the sentence. By using a bigger model i.e (t5-large or even T0 from BigScience which beat the GPT-3 from OpenAI for many tasks) or increasing the training data, tuning the parameters we can achieve better results. I fine-tuned the model with a max sequence length of 32 and the model used here would not work great on longer sentences. That said for smaller and simpler sentences this model would work as great as ever</p><p>Okay let’s wrap up as I feel like dragging on X), thank you all for your valuable time and support. Bye and take care until next time.</p><p><a href="https://medium.com/mlearning-ai/mlearning-ai-submission-suggestions-b51e2b130bfb">Mlearning.ai Submission Suggestions</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36348d3f1c62" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AI in the real world —2. Sentiment Analysis using spaCy pipelines]]></title>
            <link>https://nkumarvishnu5.medium.com/ai-in-the-real-world-2-sentiment-analysis-using-spacy-pipelines-b39a2618d7c1?source=rss-da4c4665052f------2</link>
            <guid isPermaLink="false">https://medium.com/p/b39a2618d7c1</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[sentiment-analysis]]></category>
            <category><![CDATA[spacy]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[Vishnu Nandakumar]]></dc:creator>
            <pubDate>Sun, 21 Nov 2021 14:39:44 GMT</pubDate>
            <atom:updated>2021-11-21T14:39:44.809Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*za-YVnjfmAFs1OgVrCA6vg.jpeg" /></figure><p>The way and tone in which people convey their thoughts highly set the world evolves, if everyone understands and practices humility towards each other then there will be nothing less than happiness and peace. Well, that makes us land on how sentiment analysis of simple sentences could have a greater impact in any domain. Sentiment analysis can be done in two learning methods:</p><ul><li><strong>Unsupervised learning:</strong> As we all have a fair idea of what is unsupervised learning is, so what we can do here is create an embedding for each group of words and find the semantic similarity of embedding of any sentence to get the group a particular sentence might belong to.</li><li><strong>Supervised learning: </strong>As the counterpart to the unsupervised learning method, here we will be using labelled data to be modelled for.</li></ul><p><strong>Spacy pipelines:</strong></p><p>If you haven’t heard of the word <a href="https://spacy.io/">spaCy</a> before then you should quickly jump to the link above, they are one of the pioneers of the NLP world. spaCy provides more robust, efficient pipelines and features when compared to others like TectBlob, NLTK etc. Now they have added the capability to incorporate transformers also into their module for training and inference purposes. Unfortunately spaCy doesn’t have an inbuilt sentiment analysis module, although fortunately, they have a text classification module that can be custom trained and be served as a model. All you need to do is pick a dataset, label and configure them as per spaCy’s format, pick a base model configuration and that’s all. I have trained and packaged a simple sentiment analysis module that can be easily installed in your machine via pip.</p><p><strong>Training:</strong></p><p>Training a spaCy pipeline is as easy now as ever, we need the data in the required format, select the base model configuration and train your pipeline. For the sentiment analysis model, I have used IMDB review comments of the <a href="https://archive.ics.uci.edu/ml/datasets/Sentiment+Labelled+Sentences">dataset</a> from the UCI ML repository. For training your own pipeline just look into the following <a href="https://github.com/Vishnunkumar/spacysentiment/blob/main/spacy-sentiment.ipynb">notebook</a>. Below given is a sample snippet from the notebook</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7e8b9e756678b5578e2e01739a551695/href">https://medium.com/media/7e8b9e756678b5578e2e01739a551695/href</a></iframe><p><strong>Packaging</strong></p><p>After training and saving the model you created using spaCy pipelines, you can package and server them as compiled and executable versions. For packaging your saved model use the following command as given in spaCy CLI.</p><pre>python -m spacy <a href="https://spacy.io/api/cli#package">package</a> <em>input_dir</em> <em>output_dir</em></pre><ul><li>input_dir: Directory which has your compiled model</li><li>output_dir: Directory which creates a distributable file that can be installed using pip</li></ul><p>For other parameters check the official website of spaCy <a href="https://spacy.io/api/cli#package">packages</a>. Post packaging you have to follow the conventional methods of uploading the dist/ folder to your PyPi repository to make it available for the community if you wish.</p><p><strong>eng_spacysentiment</strong></p><p>As we have seen how to train and package a spaCy pipeline, now let us see one in action, the following is a simple python library for sentiment analysis of English sentences. You can install the package using the <a href="https://pypi.org/project/eng-spacysentiment/">following</a></p><p>pip install eng-spacysentiment</p><ul><li>Simple implementation</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18fd5cefb704c0a7d0ff2a3bd0b239c4/href">https://medium.com/media/18fd5cefb704c0a7d0ff2a3bd0b239c4/href</a></iframe><p>Okay, that’s a wrap buddies, we now can easily train a pipeline using the spaCy, package and deploy it as an executable using python. As always ever, immensely grateful and glad for the support that you have been showing me. Until next time, take care fellas and clap for the article if you like it. Follow me for more and I will do the same so we can all learn everything mutually.</p><p><a href="https://medium.com/mlearning-ai/mlearning-ai-submission-suggestions-b51e2b130bfb">Mlearning.ai Submission Suggestions</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b39a2618d7c1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AI in the real world - Form Understanding]]></title>
            <link>https://nkumarvishnu5.medium.com/ai-in-the-real-world-form-understanding-653f8e8dd2a9?source=rss-da4c4665052f------2</link>
            <guid isPermaLink="false">https://medium.com/p/653f8e8dd2a9</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[forms]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Vishnu Nandakumar]]></dc:creator>
            <pubDate>Fri, 12 Nov 2021 07:50:03 GMT</pubDate>
            <atom:updated>2021-11-12T07:50:03.628Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*buEEYupRZmZUHvc9UmsvOA.png" /></figure><p>Machine learning is about making things easier by learning how any task can be efficiently performed, rather than changing rules for each and every parameter, the AI will learn to do things by itself. What’s more perfect than we see them in real action, that’s why I have planned a series of mini-articles that will try to bring in the areas AI could and have improved the performance tremendously. The first of the many to come is from the computer vision domain, CV has improved the way a lot sectors work from as simple as the processing of images to as complex as an automated driving vehicle and today we will be looking at how it can optimize form understanding by levering its another sister NLP to its aid.</p><h3>Motivation</h3><p>Not long ago one of the pioneers in the AI world <a href="https://huggingface.co/">HuggingFace</a> released the transformers version LayoutLM model open-sourced by <a href="https://huggingface.co/microsoft/layoutlmv2-base-uncased">Microsoft</a>. It uses a pre-training model for text, layout and image in a multi-modal framework, on a high level the model uses pre-training methods for text-alignment and matching tasks. On top of the previous version of this model where it used the same technique in the training, fine-tuning stages the latest v2 version achieves the same in the pre-training stage i.e visual embeddings for the multi-modal framework. Also, this model uses spatial-aware self-attention mechanisms which help in optimization of relation extraction between the texts. As we have seen on a high level how this model works we can jump onto how it’s implemented. You can learn more about the model <a href="https://arxiv.org/abs/2012.14740">here</a>.</p><h3>Implementation</h3><p>If you want to get your hands dirty and configure as you want you can visit this <a href="https://github.com/NielsRogge/Transformers-Tutorials/tree/master/LayoutLMv2">link </a>where HuggingFace have implemented the LayoutLM2 model in practice or if you want a simple wrapper for the implementation mentioned before, just jump on to this <a href="https://github.com/Vishnunkumar/doc_transformers">simple library</a> that I have created pre-dominantly aimed at non-developers to get started. Just follow the instructions as given in the readme and you are good to go.</p><h4>Install the required libraries</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5FyRDPP_O2MedLdUmlM6Ow.png" /></figure><h4>Implement the below code</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wd1Yt3wY3ZPao2O33FFp8A.png" /></figure><h4>View the results</h4><p>Let’s try different scenarios</p><ul><li><strong>Invoice:</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Db3-kpdOIX3bvrdnw68mXw.png" /></figure><ul><li><strong>ATM receipt:</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fFxmLNm9HeveyvWa4R-yoA.png" /></figure><ul><li><strong>Medical prescription :</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EHGEBSBram4NRbHiP_Xs0g.png" /></figure><p>Finally, you can download the results in the key-value pairs, for example, below I have given how the result for the ATM receipt would look like</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a07c5462317459ae0368efdbef88a38/href">https://medium.com/media/4a07c5462317459ae0368efdbef88a38/href</a></iframe><p><strong><em>Double Bingo!!! </em></strong>as we see here, got the visualizations and also the results in a consumable way. That’s all for this post, but don’t worry I’ll make sure I will come up with more engaging and interesting things as we move ahead, till then take care fellas!!</p><p>Wait, kindly do follow me on <a href="https://nkumarvishnu5.medium.com/">medium</a>, also you can head to my git <a href="https://github.com/Vishnunkumar">repo</a> for similar concepts and don’t ever hesitate to open a conversation on my <a href="https://twitter.com/vishnun_uchiha">social </a>on whatever you want to talk on. Thanks for the support you have shown me as that is what drives me to do this unconditionally.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=653f8e8dd2a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AI in the real world — Form processing]]></title>
            <link>https://nkumarvishnu5.medium.com/ai-in-the-real-world-form-processing-c96912d80ef2?source=rss-da4c4665052f------2</link>
            <guid isPermaLink="false">https://medium.com/p/c96912d80ef2</guid>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[forms]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[computer-vision]]></category>
            <dc:creator><![CDATA[Vishnu Nandakumar]]></dc:creator>
            <pubDate>Sat, 30 Oct 2021 07:01:13 GMT</pubDate>
            <atom:updated>2021-11-01T13:45:19.950Z</atom:updated>
            <content:encoded><![CDATA[<h3>AI in the real world-Form Understanding</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*buEEYupRZmZUHvc9UmsvOA.png" /></figure><p>Machine learning is about making things easier by learning how any task can be efficiently performed, rather than changing rules for each and every parameter, the AI will learn to do things by itself. What&#39;s more perfect than we see them in real action, that’s why I have planned a series of mini-articles that will try to bring in the areas AI could and have improved the performance tremendously. The first of the many to come is from the computer vision domain, CV has improved the way a lot sectors work from as simple as the processing of images to as complex as an automated driving vehicle and today we will be looking at how it can optimize form understanding by levering its another sister NLP to its aid.</p><h3><strong>Motivation</strong></h3><p>Not long ago one of the pioneers in the AI world <a href="https://huggingface.co/">HuggingFace</a> released the transformers version LayoutLM model open-sourced by <a href="https://huggingface.co/microsoft/layoutlmv2-base-uncased">Microsoft</a>. It uses a pre-training model for text, layout and image in a multi-modal framework, on a high level the model uses pre-training methods for text-alignment and matching tasks. On top of the previous version of this model where it used the same technique in the training, fine-tuning stages the latest v2 version achieves the same in the pre-training stage i.e visual embeddings for the multi-modal framework. Also, this model uses spatial-aware self-attention mechanisms which help in optimization of relation extraction between the texts. As we have seen on a high level how this model works we can jump onto how it’s implemented. You can learn more about the model <a href="https://arxiv.org/abs/2012.14740">here</a>.</p><h3><strong>Implementation</strong></h3><p>If you want to get your hands dirty and configure as you want you can visit this <a href="https://github.com/NielsRogge/Transformers-Tutorials/tree/master/LayoutLMv2">link </a>where HuggingFace have implemented the LayoutLM2 model in practice or if you want a simple wrapper for the implementation mentioned before, just jump on to this <a href="https://github.com/Vishnunkumar/doc_transformers">simple library</a> that I have created pre-dominantly aimed at non-developers to get started. Just follow the instructions as given in the readme and you are good to go.</p><h4><strong>Install the required libraries</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5FyRDPP_O2MedLdUmlM6Ow.png" /></figure><h4><strong>Implement the below code</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wd1Yt3wY3ZPao2O33FFp8A.png" /></figure><h4><strong>View the results</strong></h4><p>Let’s try different scenarios</p><ul><li><strong>Invoice:</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Db3-kpdOIX3bvrdnw68mXw.png" /></figure><ul><li><strong>ATM receipt:</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fFxmLNm9HeveyvWa4R-yoA.png" /></figure><ul><li><strong>Medical prescription :</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EHGEBSBram4NRbHiP_Xs0g.png" /></figure><p>Finally, you can download the results in the key-value pairs, for example, below I have given how the result for the ATM receipt would look like</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a07c5462317459ae0368efdbef88a38/href">https://medium.com/media/4a07c5462317459ae0368efdbef88a38/href</a></iframe><p><strong><em>Double Bingo!!! </em></strong>as we see here, got the visualizations and also the results in a consumable way. That’s all for this post, but don’t worry I’ll make sure I will come up with more engaging and interesting things as we move ahead, till then take care fellas!!</p><p>Wait, kindly do follow me on <a href="https://nkumarvishnu5.medium.com/">medium</a>, also you can head to my git <a href="https://github.com/Vishnunkumar">repo</a> for similar concepts and don’t ever hesitate to open a conversation on my <a href="https://twitter.com/vishnun_uchiha">social </a>on whatever you want to talk on. Thanks for the support you have shown me as that is what drives me to do this unconditionally.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c96912d80ef2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ScaNN: Faster vector similarity search]]></title>
            <link>https://medium.com/analytics-vidhya/scann-faster-vector-similarity-search-69af769ad474?source=rss-da4c4665052f------2</link>
            <guid isPermaLink="false">https://medium.com/p/69af769ad474</guid>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[search]]></category>
            <category><![CDATA[vector]]></category>
            <category><![CDATA[optmization]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Vishnu Nandakumar]]></dc:creator>
            <pubDate>Mon, 06 Sep 2021 06:22:20 GMT</pubDate>
            <atom:updated>2024-02-06T05:27:31.840Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SDGlOx00ZufqiOfg48G1mg.jpeg" /></figure><p>Search is always a part of a human’s life, whenever someone hits a block or a rock they always search for a solution. Nowadays computing has grown incredibly along with the world, but we will always look for efficient and optimized methods. Recently TensorFlow has released ScaNN, a fast and efficient <a href="https://www.analyticsvidhya.com/blog/2023/12/top-vector-databases/?utm_source=Backlink&amp;utm_medium=SEO">vector</a> similarity search library that can be hosted on your machine. It has proved to outperform most of the similarity search libraries by a factor of 2 for the same accuracy seen. Please do give a read on their blog about it</p><p><strong>Overview:</strong></p><p>ScaNN deals with the quantization of embeddings in the data with a different approach rather than the usual method of directly quantizing the data points in the dataset. For eg: assume<em> x1 </em>and <em>x2 </em>are two sets of embeddings in the database and we want to find the most similar vector to <em>q</em> from one of <em>x1</em> and <em>x2. </em>Conventional methods find <em>c1</em> and<em> c2 </em>as quantized versions of <em>x1</em> and <em>x2</em> by computing their projections (inner product) on <em>q,</em> but with <a href="https://pypi.org/project/scann/"><strong>ScaNN</strong> </a>it tries to compute their projections on the perpendicular vector to <em>q</em> such that it has proven to reduce both the latency and increase the accuracy of the similarity scores. The below image depicts the same on it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*l5Nb962XWzRBWEyRHBoRsg.png" /></figure><p>As you can see above with our left approach(conventional) we are actually going further from q, i.e (x2 is actually similar to q than x1 but it computes the opposite as q.c2 &gt; q.c1) while with our right side approach(<strong>ScaNN</strong>) we are computing faster and more precise, i.e (x2 is similar to q than x1 and so q.x2 &lt; q.x1). Please do read more on the above blog to get a better understanding of it.</p><p><strong>Points to remember:</strong></p><p>Let&#39;s try out some scenarios where we can use ScaNN to faster and optimize our search solutions and compare the same with other <a href="https://www.analyticsvidhya.com/blog/2023/12/top-vector-databases/?utm_source=Backlink&amp;utm_medium=SEO">libraries</a>.</p><p>Please remember the points while you are creating a searcher using the ScaNN library.</p><ul><li>If we have fewer data points we should try using the brute force scoring method rather than the asymmetric hashing method</li><li>The number of leaves to create is nearly the square root of the number of data points</li><li>Training sample size should always be greater than the number of leaves/clusters created</li></ul><p>More optimization pointers are available <a href="https://github.com/google-research/google-research/blob/master/scann/docs/algorithms.md"><em>here</em></a><em>.</em></p><p><strong>Implementation:</strong></p><p>For this example, I have taken the FIFA 20 dataset which is open sourced at Kaggle. The agenda of this example is to find sets of players who are similar to a particular player being queried for. I have done simple preprocessing like feature selection, text analytics and shrank the features set to a number that is relevant. Let us see how we can implement a similar player search solution in using both ScaNN and also with cosine similarity in sklearn metrics. The dataset looks like the one below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7df40b7b8f68585930b58a61a7cd9656/href">https://medium.com/media/7df40b7b8f68585930b58a61a7cd9656/href</a></iframe><ul><li>Normalize the dataset before using it in the searcher.</li><li>Build the searcher as per the parameters defined above</li></ul><p>In our case since the number of players is around 18000 the number of leaves will be around 135, leaves to search should be less than 135 and the training sample which will be in each leaves created should also be less than 18000. To put all into the searcher function we need to do the following:</p><p>Also, the below snippet covers the implementation using sklearn.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/490270c2143ae9ce23f64c25b7700570/href">https://medium.com/media/490270c2143ae9ce23f64c25b7700570/href</a></iframe><p><strong>Results:</strong></p><ul><li><strong>ScaNN results:</strong> Player name and similarity scores along with the time taken for the same.</li></ul><p>Bukayo Saka:</p><pre>Wall time: 803 µs</pre><pre>9896       bukayo saka  1.000000<br>14031      aitor lorea  0.997321<br>5872    héctor fertoli  0.997269<br>8875       jacob brown  0.997254<br>1622   justin kluivert  0.997196<br>5743   tomás chancalay  0.997161<br>10078      hilary gong  0.997085<br>13294    leo bengtsson  0.997068<br>13278  jerome sinclair  0.997060<br>999      matías vargas  0.996918</pre><p>John Stones:</p><pre>Wall time: 725 µs</pre><pre>172           john stones  1.000000<br>56      marcos marquinhos  0.998611<br>774           nico elvedi  0.998170<br>1305          rob holding  0.997904<br>246      presnel kimpembe  0.997853<br>4914        kévin n&#39;doram  0.997837<br>84        clément lenglet  0.997836<br>755           declan rice  0.997756<br>2268       alexander hack  0.997624<br>414   andreas christensen  0.997615</pre><p>Scott McTominay:</p><pre>Wall time: 434 µs</pre><pre>1028     scott mctominay  1.000000<br>1961  younousse sankharé  0.998196<br>601         tomáš souček  0.998192<br>1808       lukas lerager  0.998001<br>996         marko grujić  0.997909<br>2582      diego gonzález  0.997841<br>2286         lucas silva  0.997767<br>79         rodrigo rodri  0.997743<br>338             emre can  0.997738<br>818       soualiho meïté  0.997732</pre><ul><li><strong>Using Sklearn</strong></li></ul><p>Bukayo Saka</p><pre>Wall time: 4.4 s</pre><pre>2431       bojan jokič  0.842173<br>1724   tomasz kędziora  0.842173<br>1808     lukas lerager  0.842173<br>1802  nicolás castillo  0.842173<br>1799   nicolae stanciu  0.842173<br>1793     robin quaison  0.842173<br>1791  dimitrios pelkas  0.842173<br>1790         tom rogić  0.842173<br>7616      池忠国 zhongguo  0.842173<br>1761     ryan christie  0.842173</pre><p>John Stones</p><pre>Wall time: 4.36 s</pre><pre>2431       bojan jokič  0.842173<br>1724   tomasz kędziora  0.842173<br>1808     lukas lerager  0.842173<br>1802  nicolás castillo  0.842173<br>1799   nicolae stanciu  0.842173<br>1793     robin quaison  0.842173<br>1791  dimitrios pelkas  0.842173<br>1790         tom rogić  0.842173<br>7616      池忠国 zhongguo  0.842173<br>1761     ryan christie  0.842173</pre><p>As we can see from the comparisons of results from above that ScaNN is an efficient tool in terms of precision of result and low latency to get the desired result. The difference in both the methods is in the order of 10³, even the precision in the results seems to be in support of the ScaNN implementation. Do try out ScaNN in your tasks if needed as it is a great tool for vector similarity search. Kindly drop a clap if you liked it. Thanks for your valuable support, bye and take care until next time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69af769ad474" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/scann-faster-vector-similarity-search-69af769ad474">ScaNN: Faster vector similarity search</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>