<?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 Naresh Kumar Thiyagarajan on Medium]]></title>
        <description><![CDATA[Stories by Naresh Kumar Thiyagarajan on Medium]]></description>
        <link>https://medium.com/@tnknaresh123?source=rss-8a3404c48553------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-zNUl6H70ZDFhxJ1jhGaOg.jpeg</url>
            <title>Stories by Naresh Kumar Thiyagarajan on Medium</title>
            <link>https://medium.com/@tnknaresh123?source=rss-8a3404c48553------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 08:49:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tnknaresh123/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[Introduction to Heroes of String Matching Algorithms]]></title>
            <link>https://medium.com/@tnknaresh123/introduction-to-heroes-of-string-matching-algorithms-90c2e9c9a20b?source=rss-8a3404c48553------2</link>
            <guid isPermaLink="false">https://medium.com/p/90c2e9c9a20b</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[string-matching]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[genai]]></category>
            <dc:creator><![CDATA[Naresh Kumar Thiyagarajan]]></dc:creator>
            <pubDate>Fri, 16 Aug 2024 12:50:36 GMT</pubDate>
            <atom:updated>2024-08-28T11:22:58.657Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n4bzdUpIS43DQYj0vLILYw.jpeg" /></figure><p>String matching isn’t just a geeky puzzle — it’s the bread and butter of making sure your data doesn’t go rogue. Whether you’re trying to match customer names, find duplicates in your database, or ensure that no one sneaks into your system with a typo, string matching algorithms are your go-to weapons. Let’s dive into the trenches and explore some of these algorithms, with a bit of code to help you out.</p><p><strong>Meet the Heroes of String Matching Algorithms</strong></p><blockquote><strong>Jaccard Similarity: The Set Overlap Geek</strong></blockquote><ul><li><strong>What it does:</strong> Compares two names by checking how much their word sets overlap.</li><li><strong>How it works:</strong> The more words the two names share, the higher the score.</li></ul><p><em>Mathematical formula : </em>∣A∪B∣/∣A∩B∣​</p><p>Where A and B are the sets of words from each name.</p><pre>def jaccard_similarity(name1, name2):<br>    set1 = set(name1.lower().split())<br>    set2 = set(name2.lower().split())<br>    intersection = len(set1.intersection(set2))<br>    union = len(set1.union(set2))<br>    return intersection / union if union != 0 else 0.0Levenshtein Distance</pre><blockquote><strong>Sequence Similarity: The Sequence Nerd</strong></blockquote><ul><li><strong>What it does:</strong> Measures how closely two names’ sequences match.</li><li><strong>How it works:</strong> Think of it as a DNA test for strings.</li></ul><p><em>Mathematical formula : </em>​2×M​ / L1​+L2</p><p>Where M is the number of matching characters, and L1​ and L2 are the lengths of the two strings.</p><pre>from difflib import SequenceMatcher<br><br>def sequence_similarity(name1, name2):<br>    return SequenceMatcher(None, name1, name2).ratio()</pre><blockquote><strong>Levenshtein Distance: The Edit Distance Guru</strong></blockquote><ul><li><strong>What it does:</strong> Counts the number of changes needed to turn one name into the other.</li><li><strong>How it works:</strong> Fewer edits mean more similarity.</li></ul><p><em>Mathematical formula : </em>d(m,n)</p><p>Where m &amp; n are the lengths of the two strings.</p><pre>import Levenshtein<br><br>def levenshtein_similarity(name1, name2):<br>    max_len = max(len(name1), len(name2))<br>    if max_len == 0:<br>        return 1.0<br>    return 1 - Levenshtein.distance(name1, name2) / max_len</pre><blockquote><strong>Semantic Similarity: The Meaning Matcher</strong></blockquote><ul><li><strong>What it does:</strong> Looks at the meaning behind the names using fancy vector math.</li><li><strong>How it works:</strong> It’s like trying to match people based on vibes rather than just how they look.</li></ul><p><em>Mathematical formula : </em>A⋅B​ / ∥A∥∥B∥</p><p>W A&amp;B are vectors representing the names in a TF-IDF space.</p><p><em>P.S: If you don’t know TF-IDF refer to this article → </em><a href="https://medium.com/analytics-vidhya/tf-idf-term-frequency-technique-easiest-explanation-for-text-classification-in-nlp-with-code-8ca3912e58c3"><em>Click here!</em></a></p><pre>from sklearn.feature_extraction.text import TfidfVectorizer<br>from sklearn.metrics.pairwise import cosine_similarity<br><br>def semantic_similarity(name1, name2):<br>    vectorizer = TfidfVectorizer()<br>    tfidf_matrix = vectorizer.fit_transform([name1, name2])<br>    return cosine_similarity(tfidf_matrix)[0, 1]</pre><blockquote><strong>Jaro-Winkler Similarity: The Typo Tolerant</strong></blockquote><ul><li><strong>What it does:</strong> It’s like that teacher who gives grace marks even when you mess up slightly.</li><li><strong>How it works:</strong> Measures similarity by considering the number of matching characters and how far they are from each other.</li></ul><p><em>Mathematical formula : </em>Jaro Similarity+(P×L×(1−Jaro Similarity))</p><p>Where <strong>Jaro Similarity</strong> measures similarity based on matching characters and transpositions, P is the scaling factor (usually 0.1), and L is the length of the common prefix.</p><pre>import jellyfish<br><br>def jw_similarity(name1, name2):<br>    return jellyfish.jaro_winkler_similarity(name1, name2)</pre><blockquote><strong>The Final Call</strong></blockquote><p>Now that we’ve met our contenders, let’s put them all together in a weighted scoring system. After all, why settle for one opinion when you can get a committee’s verdict?</p><pre>ALGO_WEIGHTS = {<br>    &#39;jaccard&#39;: 0.05,<br>    &#39;sequence&#39;: 0.10,<br>    &#39;levenshtein&#39;: 0.15,<br>    &#39;semantic&#39;: 0.40,<br>    &#39;jaro_winkler&#39;: 0.30<br>}<br><br>def compare_strings(name1, name2):<br>    name1_filtered = remove_titles_and_stopwords(name1)<br>    name2_filtered = remove_titles_and_stopwords(name2)<br>    <br>    name1_parts = name1_filtered.split()<br>    name2_parts = name2_filtered.split()<br>    <br>    name1_permutations = [&#39; &#39;.join(p) for p in permutations(name1_parts)]<br>    name2_permutations = [&#39; &#39;.join(p) for p in permutations(name2_parts)]<br>    <br>    max_similarities = {<br>        &#39;jaccard&#39;: 0.0,<br>        &#39;sequence&#39;: 0.0,<br>        &#39;levenshtein&#39;: 0.0,<br>        &#39;semantic&#39;: 0.0,<br>        &#39;jaro_winkler&#39;: 0.0<br>    }<br>    <br>    for p1 in name1_permutations:<br>        for p2 in name2_permutations:<br>            max_similarities[&#39;jaccard&#39;] = max(max_similarities[&#39;jaccard&#39;], jaccard_similarity(p1, p2))<br>            max_similarities[&#39;sequence&#39;] = max(max_similarities[&#39;sequence&#39;], sequence_similarity(p1, p2))<br>            max_similarities[&#39;levenshtein&#39;] = max(max_similarities[&#39;levenshtein&#39;], levenshtein_similarity(p1, p2))<br>            max_similarities[&#39;semantic&#39;] = max(max_similarities[&#39;semantic&#39;], semantic_similarity(p1, p2))<br>            max_similarities[&#39;jaro_winkler&#39;] = max(max_similarities[&#39;jaro_winkler&#39;], jw_similarity(p1, p2))<br>    <br>    weighted_score = sum(max(0, max_similarities[key]) * ALGO_WEIGHTS[key] for key in max_similarities)<br>    return weighted_score</pre><p>It’s like a reality TV judge panel — it takes inputs from all our string matching algorithms, weighs them based on their importance, and spits out a final score. No drama, just pure logic.</p><p><strong>Conclusion</strong></p><p>String matching isn’t just about finding out if two names are the same — it’s about understanding how they might be similar even when they don’t look identical at first glance. Whether you’re using these algorithms individually or combining them like we did, you’ll have a solid toolkit to tackle those pesky name variations that try to sneak past your systems.</p><p>Keep in mind that this article only scratches the surface of popular string matching algorithms. There are many other techniques out there that weren’t covered here. If you have questions or want to discuss other algorithms, feel free to start a conversation in the comments section.</p><p>Now go ahead, give it a try, and let those names battle it out for the top spot in your data!</p><p>Happy coding : )</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=90c2e9c9a20b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Optimizers in PyTorch — Beginners version]]></title>
            <link>https://medium.com/@tnknaresh123/understanding-optimizers-in-pytorch-beginners-version-ff6b3f45c129?source=rss-8a3404c48553------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff6b3f45c129</guid>
            <category><![CDATA[mlops]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[pytorch]]></category>
            <dc:creator><![CDATA[Naresh Kumar Thiyagarajan]]></dc:creator>
            <pubDate>Sat, 20 Apr 2024 09:13:45 GMT</pubDate>
            <atom:updated>2024-04-20T09:23:58.507Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding Optimizers in PyTorch — Beginners version</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/1*JRGHk6to2fMQHeY_AhFc5w.png" /></figure><p>Hey there! before we explore optimizers in PyTorch. Let’s try to understand What is PyTorch and Why do we need it?</p><blockquote><strong>What &amp; Why</strong></blockquote><p>What is PyTorch?</p><p>PyTorch is an open-source machine learning library based on the Torch library, primarily developed by Facebook’s AI Research lab. It is a powerful and flexible framework for building and training deep neural networks and other machine learning models.</p><p>Why PyTorch?</p><p><strong>4/5 data scientists</strong> recommend PyTorch for it’s,</p><ol><li>Pythonic and intuitive design, closely following Python syntax, making it easy to learn and use.</li><li>Flexible and expressive, allowing dynamic computation graphs and on-the-fly modifications.</li><li>Strong GPU acceleration capabilities, leveraging CUDA and cuDNN for efficient tensor operations.</li><li>Dynamic computation graphs, enabling easier debugging and more natural control flow.</li><li>Automatic differentiation (autograd) for efficient backpropagation and gradient computations.</li><li>Large and active community, with a rich ecosystem of libraries and resources.</li><li>Interoperability with other popular Python libraries like NumPy and Pandas.</li><li>Deployment and production support, facilitating the integration of models into real-world applications.</li></ol><p><strong><em>P.S. The remaining 1? Well, let’s just say they’re still stuck in the Stone Age, trying to train their models with abacuses and carrier pigeons.</em></strong></p><p>Now you might have a surface level understanding of what is PyTorch and why do we use it. Now let’s dive deep into following topics,</p><blockquote><strong>What is Optimizer in PyTorch?</strong></blockquote><p>In PyTorch, an optimizer is a key component responsible for updating the weights and biases of a neural network during the training process. It plays a crucial role in minimizing the loss function and improving the model’s performance.</p><p>An optimizer is an algorithm that adjusts the model’s parameters (weights and biases) in the direction that minimizes the loss function. The loss function is a measure of the model’s error or the difference between the predicted output and the actual output. By minimizing the loss function, the optimizer helps the model learn from the training data and improve its accuracy.</p><blockquote><strong>Who do we need it?</strong></blockquote><p>We need optimizers in PyTorch because:</p><p>1. They update the large number of weights and biases in neural networks during training.</p><p>2. They use gradients from backpropagation to determine how to adjust the parameters.</p><p>3. Different optimizers have strategies to improve convergence speed, stability, and navigate complex loss landscapes.</p><p>4. Some optimizers incorporate regularization techniques to prevent overfitting.</p><p>5. Optimizers have hyperparameters that can be tuned for better performance.</p><p>So, optimizers are essential algorithms that enable efficient and effective training of deep neural networks by updating parameters based on gradients and employing techniques to improve convergence and generalization. Which can effectively protect the model from over or underfitting issues.</p><blockquote><strong>What are types of Optimizers?</strong></blockquote><p>Some commonly used optimizers in PyTorch include:</p><ol><li>Stochastic Gradient Descent (SGD)</li><li>Adam (Adaptive Moment Estimation)</li><li>RMSprop (Root Mean Square Propagation)</li><li>Adagrad (Adaptive Gradient Algorithm)</li><li>Adadelta (Adaptive Learning Rate Method)</li><li>AdamW (Adam with Weight Decay)</li></ol><blockquote><strong>Where to use what?</strong></blockquote><ol><li><strong>Stochastic Gradient Descent (SGD): </strong>SGD is like taking small steps downhill to find the lowest point in a valley. You start somewhere random and take steps in the direction that makes the slope steepest, gradually getting closer to the lowest point. It’s simple and reliable, but it might zigzag a bit on the way down.</li><li><strong>Adam (Adaptive Moment Estimation): </strong>Adam is like a smart traveler who adjusts their step size based on how steep the slope is and how fast they’re moving. It’s adaptive and efficient, ensuring smoother and faster descent down the valley. Think of it as finding the optimal path downhill while adjusting your pace along the way.</li><li><strong>RMSprop (Root Mean Square Propagation): </strong>RMSprop is like smoothing out the path downhill by averaging out the steepness of the slope over time. It prevents sudden jumps in step size, ensuring a more stable descent. It’s like walking downhill on a bumpy road but with fewer bumps along the way.</li><li><strong>Adagrad (Adaptive Gradient Algorithm): </strong>Adagrad is like keeping track of how steep the slope is at each step and adjusting your step size accordingly. It gives more weight to parameters with larger gradients, ensuring faster progress in the steeper parts of the valley. It’s like being more cautious on steep slopes and taking bigger steps on gentler slopes.</li><li><strong>Adadelta (Adaptive Learning Rate Method): </strong>Adadelta is like dynamically adjusting your step size based on not only the steepness of the slope but also how much progress you’ve made so far. It adapts to changing conditions and ensures a more consistent pace downhill. It’s like adjusting your pace based on both the slope and how far you’ve already descended.</li><li><strong>AdamW (Adam with Weight Decay): </strong>AdamW is like Adam, but with an added focus on preventing overgrowth of certain parameters. It applies a penalty to large parameter values, ensuring a more balanced and well-behaved model. It’s like trimming the bushes along your path downhill to keep them from growing too wild.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*gi67zkcofIDdIGNcdDe5Iw.png" /></figure><p><em>Graphical representation which represents how how does different optimizer perform at different epochs.</em></p><blockquote><strong>Conclusion</strong></blockquote><p>In sum, understanding optimizers in PyTorch is key for effective deep learning. We’ve learned what they are, why they’re important, and the different types. From SGD to AdamW, each has its strengths for making models better.</p><p>Knowing which optimizer to use helps train models faster and more accurately, avoiding common pitfalls like overfitting. With this knowledge, you can confidently tackle the challenges of deep learning and achieve your goals with ease.</p><p><strong><em>“First you learn and make machine learn!”</em></strong></p><p>Happy coding : )</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff6b3f45c129" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build your own Fine-Tuned LLM with LoRA]]></title>
            <link>https://medium.com/@tnknaresh123/build-your-own-fine-tuned-llm-with-lora-f2801895229b?source=rss-8a3404c48553------2</link>
            <guid isPermaLink="false">https://medium.com/p/f2801895229b</guid>
            <category><![CDATA[finetune-llm]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[mistral]]></category>
            <dc:creator><![CDATA[Naresh Kumar Thiyagarajan]]></dc:creator>
            <pubDate>Wed, 17 Apr 2024 12:29:08 GMT</pubDate>
            <atom:updated>2024-04-17T12:29:08.429Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey there!</p><p>Many of you might have used ChatGPT, Claude, and other impressive language models, but have you ever thought of building one for yourself?</p><p>If answer is yes, then this article is for you. Introducing LoRA (Low Rank Adaption technique for fine tuning Large Language Model to your specific use case.</p><blockquote><strong>Contents</strong></blockquote><ul><li>What is LoRA?</li><li>Where to use?</li><li>How to use?</li><li>Why to use?</li></ul><blockquote><strong>What is LoRA?</strong></blockquote><p>LoRA (Low-Rank Adaptation) is a revolutionary technique that empowers developers, researchers, and enthusiasts to efficiently adapt and specialize large pre-trained language models to their specific needs. Rather than starting from scratch or completely fine-tuning these massive models, LoRA allows you to build your own customized version by introducing a small set of trainable parameters, build for your desired task or domain.</p><blockquote><strong>Where it can be used?</strong></blockquote><ol><li><strong>Domain Adaptation for Specialized Fields</strong><br><strong>Legal Domain:</strong> Fine-tune language models on legal documents, contracts, and case laws to create models spec for legal text analysis, contract review, and legal research.<br><strong>Medical &amp; Insurance Domain: </strong>Adapt models using medical literature, clinical notes, and research papers to develop specialized language models for tasks like medical question answering, literature search, and patient report generation.<br><strong>Finance Domain:</strong> Fine-tune on financial data, reports, and news to create models suited for financial analysis, risk assessment, and investment advisory applications.<br><strong>Technical Domains:</strong> Adapt models to specific technical fields like engineering, computer science, or physics by fine-tuning on domain-specific literature and documentation.</li><li><strong>Task-Specific Fine-Tuning:</strong><br><strong>Text Summarization:</strong> Fine-tune language models using LoRA on datasets of document-summary pairs to create efficient summarization models.<br><strong>Question Answering:</strong> Adapt models to excel at question answering tasks by fine-tuning on question-answer datasets from various domains.<br><strong>Sentiment Analysis:</strong> Specialize language models for sentiment analysis by fine-tuning on sentiment-labeled data from product reviews, social media posts, or customer feedback.<br><strong>Named Entity Recognition (NER):</strong> Fine-tune models using LoRA on NER datasets to improve entity recognition performance for specific domains or entity types.</li><li><strong>Few-Shot Learning and Prompt Engineering:</strong><br> — LoRA can be used for efficient prompt exploration and prompt engineering, enabling quick adaptation of language models to new tasks or domains without full fine-tuning.<br> — This is particularly useful in few-shot learning scenarios where only a small amount of task-specific data is available.</li><li><strong>Personalization and Customization:</strong><br> — LoRA’s parameter-efficient nature makes it well-suited for personalizing and customizing language models to individual users, groups, or specific use cases.<br> — Applications include personalized virtual assistants, chatbots, recommendation systems, and user-specific language models.</li><li><strong>Multi-Task Learning:</strong><br> — With LoRA, multiple fine-tuned models can be combined into a single multi-task model, enabling efficient handling of various NLP tasks simultaneously.<br> — This can be valuable for applications that require diverse language capabilities, such as conversational AI systems or intelligent assistants.</li></ol><p>Across these applications, LoRA’s key advantage is its ability to efficiently adapt and specialize large language models while preserving their general knowledge and capabilities. By introducing a small set of trainable parameters, LoRA minimizes computational and memory requirements, making it a scalable and practical solution for fine-tuning and customizing large models for specific tasks, domains, or use cases.</p><blockquote><strong>How to use?</strong></blockquote><p>Let’s say you want to fine-tune a large language model like GPT-2 or BERT for the legal domain. With LoRA, you can achieve this by fine-tuning the model on a dataset of legal documents, while only updating the LoRA weights, leaving the vast majority of the pre-trained weights untouched.</p><pre>from transformers import AutoTokenizer, AutoModelForMaskedLM<br>import peft<br><br># Load pre-trained model and tokenizer<br>model = AutoModelForMaskedLM.from_pretrained(&quot;gpt2&quot;)<br>tokenizer = AutoTokenizer.from_pretrained(&quot;gpt2&quot;)<br><br># Load dataset of legal documents<br># ... (code for loading and preprocessing dataset)<br><br># Create LoRA config<br>lora_config = peft.LoraConfig(<br>    r=16,<br>    lora_alpha=32,<br>    target_modules=[&quot;q_proj&quot;, &quot;v_proj&quot;],<br>    lora_dropout=0.1,<br>)<br><br># Create LoRA model<br>lora_model = peft.get_peft_model(model, lora_config)<br><br># Fine-tune with LoRA<br>trainer = Trainer(<br>    model=lora_model,<br>    train_dataset=train_dataset,<br>    eval_dataset=val_dataset,<br>    # ... (other training arguments)<br>)<br>trainer.train()<br><br># Use the fine-tuned model for legal text generation<br>input_text = &quot;The defendant is accused of...&quot;<br>input_ids = tokenizer.encode(input_text, return_tensors=&quot;pt&quot;)<br>output_ids = lora_model.generate(input_ids, max_length=100, do_sample=True)<br>legal_text = tokenizer.decode(output_ids[0], skip_special_tokens=True)</pre><p>In this example, we fine-tune a pre-trained GPT-2 model on a legal document dataset using LoRA. The resulting lora_model can then be used for tasks like legal text generation, with the model&#39;s outputs specific to the legal domain. This can be replicated across multiple domains depending on the use case.</p><blockquote><strong>Why to use?</strong></blockquote><p>LoRA significantly reduces the computational and memory requirements compared to traditional fine-tuning methods. Instead of updating all model parameters, LoRA introduces a small set of trainable weights, called LoRA weights, which are combined with the pre-trained weights.</p><ol><li><strong>GPU Memory Usage:</strong> LoRA requires only a fraction of the GPU memory, scaling with the size of the LoRA weights rather than the full model size.</li><li><strong>Computational Requirements (FLOPs):</strong> LoRA reduces the number of floating-point operations required during fine-tuning, leading to faster training times.</li><li><strong>Training Time: </strong>Due to reduced computations and memory footprint, LoRA fine-tuning can be significantly faster than traditional fine-tuning, especially for large models.</li><li><strong>Hardware Requirements:</strong> LoRA’s efficiency makes it possible to fine-tune large models on consumer-grade hardware, such as high-end GPUs or even some consumer CPUs, depending on the model size and LoRA configuration.</li></ol><p>The actual resource usage depends on factors like the pre-trained model size, LoRA configuration, and the fine-tuning dataset size. However, LoRA consistently offers substantial resource savings, making it a more efficient and scalable solution for adapting large language models to specific tasks or domains, especially for individuals or organizations with limited computational resources.</p><blockquote><strong>Alternative for LoRA</strong></blockquote><p>Running low on computational resources for fine-tuning your LLM? No need to fret! Enter QLoRA, the quantized version of LoRA, offering efficient resource utilization. However, expect some trade-offs in accuracy. Choose the best fit for your needs wisely.</p><p><strong>Happy coding : )</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f2801895229b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Encoding Data for Machines: A Beginner’s Guide to Data Encoding in Machine Learning]]></title>
            <link>https://medium.com/@tnknaresh123/encoding-data-for-machines-a-beginners-guide-to-data-encoding-in-machine-learning-2a344bc6675a?source=rss-8a3404c48553------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a344bc6675a</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science-projects]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[encoding]]></category>
            <category><![CDATA[feature-engineering]]></category>
            <dc:creator><![CDATA[Naresh Kumar Thiyagarajan]]></dc:creator>
            <pubDate>Wed, 24 Jan 2024 09:14:26 GMT</pubDate>
            <atom:updated>2024-01-24T09:14:26.251Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello Data Enthusiasists out here! In this article we will be discussing about most important aspect of Machine Learning i.e, Encoding Data.</p><p>People might get confused on which encoding should be applied for what kind of data. So, here is a article which provides clear understanding on</p><p><strong><em>What to be used Where?</em></strong></p><p><strong>One-Hot Encoding:</strong></p><p>Each category gets its own column, and if the category is present, it gets a 1; otherwise, it gets a 0.</p><p><em>Example: Suppose you have a dataset with a “Color” column containing categories like “Red,” “Green,” and “Blue.” One-hot encoding would create separate binary columns for each color.</em></p><pre>import pandas as pd<br><br># Creating a sample DataFrame<br>data = {&#39;Category&#39;: [&#39;A&#39;, &#39;B&#39;, &#39;A&#39;, &#39;C&#39;, &#39;B&#39;, &#39;C&#39;]}<br>df = pd.DataFrame(data)<br><br>one_hot_encoded_df = pd.get_dummies(df, columns=[&#39;Category&#39;], prefix=&#39;Category&#39;)<br>print(one_hot_encoded_df)</pre><p><strong>Label Encoding:</strong></p><p>Assigning a unique number to each category, often based on their order or frequency.</p><p><em>Example: In a dataset of education levels, “High School,” “College,” and “Postgraduate” could be label-encoded as 1, 2, and 3, respectively.</em></p><pre>from sklearn.preprocessing import LabelEncoder<br><br>label_encoder = LabelEncoder()<br>df[&#39;Category_LabelEncoded&#39;] = label_encoder.fit_transform(df[&#39;Category&#39;])<br>print(df)</pre><p><strong>Ordinal Encoding:</strong></p><p>Similar to label encoding, but considers the order of categories.</p><p><em>Example: If you have a dataset with a “Size” column containing categories like “Small,” “Medium,” and “Large,” ordinal encoding would assign them numerical values based on their relative sizes, like 1, 2, and 3.</em></p><pre>ordinal_mapping = {&#39;A&#39;: 1, &#39;B&#39;: 2, &#39;C&#39;: 3}<br>df[&#39;Category_OrdinalEncoded&#39;] = df[&#39;Category&#39;].map(ordinal_mapping)<br>print(df)</pre><p><strong>Target Encoding (Mean Encoding):</strong></p><p>Encoding categories based on the average of the target variable for each category.</p><p><em>Example: In a binary classification task with a “Gender” column, target encoding would replace each gender category with the average of the target variable (e.g., the probability of belonging to a certain class for each gender).</em></p><pre>mean_encoded_mapping = df.groupby(&#39;Category&#39;)[&#39;Category&#39;].transform(&#39;count&#39;) / len(df)<br>df[&#39;Category_MeanEncoded&#39;] = df[&#39;Category&#39;].map(mean_encoded_mapping)<br>print(df)</pre><p><strong>Count Encoding:</strong></p><p>Representing categories by the number of times they appear in the dataset.</p><p><em>Example: Consider a dataset with a “City” column. Count encoding would replace each city with the number of times it appears in the dataset.</em></p><pre>count_encoded_mapping = df[&#39;Category&#39;].value_counts()<br>df[&#39;Category_CountEncoded&#39;] = df[&#39;Category&#39;].map(count_encoded_mapping)<br>print(df)</pre><p><strong>Embedding Layers:</strong></p><p>Creating a space where categorical variables can be represented as continuous vectors, often used in deep learning.</p><p><em>Example: In natural language processing, if you’re working with a text dataset, words could be embedded into continuous vectors using techniques like Word Embeddings (Word2Vec, GloVe).</em></p><pre>import tensorflow as tf<br>from tensorflow.keras.layers import Embedding<br><br># Assuming you have a vocabulary size and an input sequence (replace with your data)<br>vocabulary_size = 10000<br>input_sequence = [1, 2, 3, 4, 5]<br><br># Create an embedding layer<br>embedding_dim = 32<br>embedding_layer = Embedding(input_dim=vocabulary_size, output_dim=embedding_dim)<br><br># Apply the embedding layer to your input sequence<br>embedded_sequence = embedding_layer(tf.constant(input_sequence))<br><br>print(embedded_sequence)</pre><p><strong>Binary Encoding:</strong></p><p>Representing categories using binary code, suitable for dealing with a large number of categories.</p><p><em>Example: If you have a dataset with a “Country” column containing many countries, binary encoding would represent each country with a binary code.</em></p><pre>import category_encoders as ce<br><br># Assuming you have a DataFrame df with a categorical column &#39;Category&#39;<br>df = pd.DataFrame({&#39;Category&#39;: [&#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;A&#39;, &#39;B&#39;, &#39;C&#39;]})<br><br># Create a BinaryEncoder instance<br>binary_encoder = ce.BinaryEncoder(cols=[&#39;Category&#39;])<br><br># Fit and transform your DataFrame<br>df_binary_encoded = binary_encoder.fit_transform(df)<br><br>print(df_binary_encoded)</pre><p>Conclusion:</p><p>To sum it up, data encoding is like giving instructions to a computer so it can understand and learn from our information better. We talked about different ways to do this, like using numbers for categories or creating special codes. Each method has its own strengths — like one-hot encoding is good for categories without a clear order, and counting helps when we want to know how often something happens.</p><p>The key is to pick the right method based on what our data needs. It’s a bit like choosing the right tool for a job. Understanding these encoding tricks helps us make sure our computer buddy learns the right things from our data, making it smarter at solving problems. And that’s pretty cool!.</p><p>Thanks for reading, Happy coding!😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a344bc6675a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“VibeSense”- Ultimate Text Emotion Dashboard!]]></title>
            <link>https://medium.com/@tnknaresh123/vibesense-ultimate-text-emotion-dashboard-c00c6d181162?source=rss-8a3404c48553------2</link>
            <guid isPermaLink="false">https://medium.com/p/c00c6d181162</guid>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[sentimental-analysis]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Naresh Kumar Thiyagarajan]]></dc:creator>
            <pubDate>Thu, 27 Jul 2023 13:26:44 GMT</pubDate>
            <atom:updated>2023-07-27T13:26:44.841Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction</strong></p><p>Sentimental analysis is a language wizard that can read emotions from text better than any sound wave! Whether the text is dancing with excitement, screaming “YOLO,” or sighing with “Arrey Yaar…” in sadness, this magical tool can decode it all! So, who needs sound when you have this text-tastic emotion detective to uncover the feels hidden in those letters?. So in this article let’s deep dive into how to make use of transcripts generated in different meeting platforms and build a interactive dashboard out of it…🏊‍♂</p><p><strong>Technical Architecture</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m1QyAOEWaywW8Gcp0nsq0g.png" /></figure><p><strong>Data Collection</strong></p><p>Transcripts from various meetings held among different groups across the organization, discussing the same topic, have been collected and compiled.</p><p><strong>Data Processing</strong></p><p>- The collected transcripts undergo rigorous preprocessing using Python, streamlining the document for further analysis and insights.<br>- During the preprocessing stage, stop words removal is performed within the Processing layer, eliminating common words that do not contribute significantly to the sentiment analysis process.<br>- The refined data is then seamlessly fed into the powerful Natural Language Processing (NLP) Engine, which extracts sentiments for all the texts.</p><p><strong>Sentiment Analysis and Classification</strong></p><p>- Leveraging the capabilities of the NLP Engine, sentiment scores are obtained for each individual text in the transcripts.<br>- These sentiment scores are then effectively utilized to classify the sentiments of the texts into distinct categories such as positive, negative, or neutral.<br>- The sentiment classification results are recorded in the document, providing valuable insights into the overall sentiment trends across the meetings.</p><p><strong>Visualization Layer</strong></p><p>- To present these valuable insights in an engaging and user-friendly manner, an interactive dashboard is crafted using Power BI.<br>- The Power BI dashboard boasts multiple features that empower users to delve deeper into the data and extract meaningful details.<br>- Users can effortlessly explore the most frequently discussed content across groups or focus on specific individual groups to gain a comprehensive understanding.<br>- For every individual, the dashboard showcases the percentage distribution of positive, negative, and neutral responses received across different groups, enabling users to gauge sentiment variations effectively.</p><p>This tool is like a trusted detective for your meeting transcripts! 🕵️‍♂️✨ It carefully examines the notes, using smart tools to uncover essential information and grasp the sentiments expressed. The results are presented in a simple and interactive dashboard. With this powerful tool, you’ll become a data expert, effortlessly gaining valuable insights! 🧠🔎</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c00c6d181162" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python’s WOW-Factor: 4 Mind-Blowing Packages That Will Make You Go WOW]]></title>
            <link>https://medium.com/@tnknaresh123/pythons-wow-factor-4-mind-blowing-packages-that-will-make-you-go-wow-12178d0be23c?source=rss-8a3404c48553------2</link>
            <guid isPermaLink="false">https://medium.com/p/12178d0be23c</guid>
            <dc:creator><![CDATA[Naresh Kumar Thiyagarajan]]></dc:creator>
            <pubDate>Thu, 15 Jun 2023 10:41:17 GMT</pubDate>
            <atom:updated>2023-07-27T10:50:49.847Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello geeks,</p><p>After 4 mins read. I’m sure that this will help you in optimizing your coding and you’ll feel that you have learnt something new which you never knew before. So let’s dive deep into the topic 🏊‍♂️.</p><p><strong>Winsound 🎶</strong></p><p>Are you tired of running code in the background for hours, only to encounter errors and waste valuable time without even realizing it?</p><p>Then this feature is for you!</p><p>Make use of Python winsound module to save the day! With winsound, you can add real-time audio notifications to your loops, turning your code flows into a musical adventure. We’ll dive into the winsound module and discover how it brings harmony to your Python loops, ensuring smooth execution every time. Get ready to hear the code come to life!</p><pre># Loop example<br>for i in range(5):<br>    print(f&quot;Iteration executed Successfully ! {i+1}&quot;)<br>    winsound.Beep(1000, 500)  # Plays a beep sound with frequency 1000 Hz for 500 milliseconds</pre><p>Different types of tone can also be used based on requirements:</p><p><strong>SystemAsterisk:</strong> Because every programmer needs more asterisks in their lives! Make your code sparkle with this delightful sound.</p><p><strong>SystemExclamation:</strong> Attention, programmers! There is some emergency! Your code needs your help. Add a touch of urgency to your code with this exclamation sound.</p><p><strong>SystemExit:</strong> Bid farewell to boring code execution! Let your program make a stylish exit with this dramatic sound. Exit with flair, my fellow programmers!</p><p><strong>SystemHand: </strong>Need a helping hand in your code? Let this sound guide you through the intricacies of your program. Give your code a hand, quite literally.</p><p><strong>SystemQuestion:</strong> When in doubt, let your code ask the important questions! Inject a sense of curiosity with this questioning sound. Your code has queries, and it demands answers!</p><p><strong>Walrus operator</strong></p><p><strong><em>“Each line in code matters!”</em></strong></p><p>So don’t waste one line for assigning value to the variables instead make use of Unsung hero of Python “Walrus” he can also be called as “:=”<br>What does he do?</p><p>He is like a ninja assistant that lets you assign a value to a variable while also checking a condition. It’s like saying, <strong><em>“Hey, if you’re true, here’s your value, otherwise, go away!”</em></strong></p><pre># Traditional Method<br>keys = search_for_keys()<br>if keys:<br>    open_door()<br>else:<br>    keep_searching()<br>    if not keys:<br>        stay_outside()<br><br># Walrus Operator Method<br>if keys := search_for_keys():<br>    open_door()<br>else:<br>    keep_searching()<br>    if not keys:<br>        stay_outside()</pre><p>So, finally he saves one line of code for you.</p><p><strong>Underscore “_” Function</strong></p><p><strong><em>“Variables in Python are like little soldiers that hold information for you. And when you bring in the underscore function, it’s like giving those soldiers superpowers to hide, ignore, and make your code a hilarious masterpiece!”</em></strong></p><p>Imagine you’re working with a bunch of variables, but there’s this one useless value that you just don’t care about. Instead of giving it a name and cluttering your code, you can simply assign it to the underscore. This undercover agent is here for you to store values which you don’t want. It’s like saying, <strong><em>“Hey, I don’t care about you, but someone else might, so I’ll leave you here as underscore.”</em></strong></p><pre>def calculate_dragon_stats():<br>    # Imagine operations which gets how many heads, hands and how much fire power does that dragon have&quot;<br>    return heads,hands,firepower<br><br>def summon_dragon():<br>    # Ignoring the actual number of heads &amp; hands<br>    _, _, dragon_firepower = calculate_dragon_stats()<br>    if dragon_firepower &gt; 9000:<br>        tiger_attack()<br>    else:<br>        run_away_in_panic()</pre><p><strong>Tee module</strong></p><p><strong><em>Tired of using .copy()? Relax! have some TEE☕</em></strong></p><p>Say goodbye to data copy struggles and hello to the magic of TEE! It effortlessly duplicates your data, creating parallel universes of iteration. With TEE, you can bid farewell to copy headaches and embrace the enchanting power of effortless duplication.</p><pre># Lab rats details<br>lab_rats = [&#39;Jerry&#39; , &#39;Stuart&#39;]<br><br># Using Traditional method<br>test_rat1 = lab_rats.copy()<br>test_rat2 = lab_rats.copy()<br><br># Using Tee module<br>from itertools import tee<br>test_rat1, test_rat2 = tee(lab_rats)<br><br># Analyze test results independently<br>print(&quot;Medicine Tester 1:&quot;)<br>for rat in test_rat1:<br>    result = first_test_rat(rat) #Imagine that first_test_rat() is a function which has set of testing procedures<br>    print(result)<br><br>print(&quot;Medicine Tester 2:&quot;)<br>for rat in test_rat2:<br>    result = second_test_rat(rat) #Imagine that second_test_rat() is a function which has set of testing procedures<br>    print(result)</pre><p>In the realm of medicine testing, we had lab rats named Jerry and Stuart. Using the traditional method, we copied them twice, resulting in test_rat1 and test_rat2. But then, Tee module appeared, wielding its magical powers. With a flicker of its wand, it created twin copies effortlessly.</p><p>In conclusion, we’ve uncovered four Python tricks that will leave you both entertained and enlightened. From the mesmerizing sounds of Winsound to the parallel universes created by Tee, the hidden powers of Underscore, and the dramatic Walrus operator, Python never ceases to amaze. So go forth, embrace the quirkiness, and may your Python adventures be filled with laughter, surprise, and the occasional facepalm.</p><p><strong><em>Happy coding! 😊</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12178d0be23c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>