<?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 Kavach Dheer on Medium]]></title>
        <description><![CDATA[Stories by Kavach Dheer on Medium]]></description>
        <link>https://medium.com/@22kavachdheer?source=rss-d651c9d9089b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ecPVG3ElV3Ufi4Ys</url>
            <title>Stories by Kavach Dheer on Medium</title>
            <link>https://medium.com/@22kavachdheer?source=rss-d651c9d9089b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 21 May 2026 10:26:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@22kavachdheer/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[Detecting Pre-Training Data Leakage with Membership Inference]]></title>
            <link>https://medium.com/@22kavachdheer/detecting-pre-training-data-leakage-with-membership-inference-ec76ccdc73d8?source=rss-d651c9d9089b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec76ccdc73d8</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[hugging-face]]></category>
            <dc:creator><![CDATA[Kavach Dheer]]></dc:creator>
            <pubDate>Sat, 07 Jun 2025 18:33:20 GMT</pubDate>
            <atom:updated>2025-06-07T18:33:20.973Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to tell if your target LLM was secretly trained on your test set</h3><h3>Introduction</h3><p>In evaluating large language models (LLMs), a critical concern is whether a model has been inadvertently exposed to the very data we use for testing or benchmarking. If a model has memorized specific examples from its pre-training corpus, its test-time performance may overstate its true generalization ability. In this post, we’ll walk through a lightweight <strong>membership inference</strong> technique that flags whether a “target” LLM has seen a given dataset during pre-training, by comparing it against a “reference” model guaranteed <em>not</em> to have seen that data.</p><p>We’ll demonstrate this on the <strong>Amazon Review — Luxury Beauty</strong> dataset, using:</p><ul><li><strong>Target model</strong>: google/gemma-7b</li><li><strong>Reference model</strong>: EleutherAI/pythia-6.9b-deduped (trained <em>only</em> on the Pile, which contains no Amazon reviews)</li></ul><p>Because our reference model has never seen the Luxury Beauty reviews, any unusually high confidence that the target model shows — relative to the reference — signals possible memorization.</p><h3>1. Core Idea: Likelihood Differential</h3><p>At the heart of our approach is a simple premise:</p><blockquote><strong><em>If</em></strong><em> the target model was trained on a review text </em><strong><em>then</em></strong><em> it will assign that text a significantly higher probability (i.e., lower surprisal) than a model that never saw it.</em></blockquote><p>We operate this via a <strong>normalized log-likelihood</strong> metric:</p><p>For each review text x, compute the <strong>sum of token log-probabilities</strong> under each model:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*wfDLq-n02rDvMiha0cMflw.png" /></figure><p>Measure each review’s “information content” by compressing x with zlib and taking the compressed length z(x), which approximates its entropy.</p><p>Define a <strong>normalized score</strong> per model:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*b_eaa5WHRRqbrYXiDOod0g.png" /></figure><p>The <strong>membership signal</strong> is the difference:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*l9gDMsi-Onun6Cdg1mhzFg.png" /></figure><p>A large positive Δ\DeltaΔ suggests that the target model “knows” x much better than an unexposed model.</p><h3>File One: Computing and Saving Δ Scores</h3><p>Below is a Python script that scans through your gzipped JSON reviews, computes Δ\DeltaΔ for each one, and writes the results to a timestamped .txt file.</p><pre>#!/usr/bin/env python3<br>import argparse, gzip, json, zlib, os<br>from datetime import datetime<br>import torch<br>import torch.nn.functional as F<br>from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig<br>from tqdm import tqdm<br><br>def compute_sum_logprob(model, tokenizer, text, device, max_length=2048):<br>    inputs = tokenizer(text, return_tensors=&quot;pt&quot;,<br>                       truncation=True, max_length=max_length).to(device)<br>    with torch.no_grad():<br>        logits = model(**inputs).logits<br>    # shift for next-token log-probabilities<br>    shift_logits = logits[..., :-1, :].contiguous()<br>    shift_labels = inputs[&quot;input_ids&quot;][..., 1:].contiguous()<br>    log_probs = F.log_softmax(shift_logits, dim=-1)<br>    token_log_probs = log_probs.gather(-1, shift_labels.unsqueeze(-1)).squeeze(-1)<br>    return token_log_probs.sum().item()<br><br>def main():<br>    parser = argparse.ArgumentParser(<br>        description=&quot;Membership inference via Δ = logp / zlib_len&quot;<br>    )<br>    parser.add_argument(&quot;--data&quot;,   type=str, default=&quot;Luxury_Beauty.json.gz&quot;)<br>    parser.add_argument(&quot;--limit&quot;,  type=int, default=0)<br>    parser.add_argument(&quot;--output&quot;, type=str, default=&quot;membership_results.csv&quot;)<br>    args = parser.parse_args()<br><br>    device = torch.device(&quot;cuda:1&quot; if torch.cuda.is_available() else &quot;cpu&quot;)<br><br>    # --- Load target and reference models ---<br>    target_name = &quot;google/gemma-7b&quot;<br>    ref_name    = &quot;EleutherAI/pythia-6.9b-deduped&quot;<br>    quant_cfg = BitsAndBytesConfig(load_in_4bit=True,<br>                                   bnb_4bit_compute_dtype=torch.bfloat16)<br><br>    print(f&quot;Loading target model ({target_name})…&quot;)<br>    tgt_tok = AutoTokenizer.from_pretrained(target_name)<br>    tgt_mdl = AutoModelForCausalLM.from_pretrained(<br>        target_name, quantization_config=quant_cfg, device_map={&quot;&quot;: 1})<br><br>    print(f&quot;Loading reference model ({ref_name})…&quot;)<br>    ref_tok = AutoTokenizer.from_pretrained(ref_name)<br>    ref_mdl = AutoModelForCausalLM.from_pretrained(<br>        ref_name,  quantization_config=quant_cfg, device_map={&quot;&quot;: 1})<br><br>    # --- Read dataset ---<br>    print(f&quot;Reading records from {args.data}…&quot;)<br>    with gzip.open(args.data, &quot;rt&quot;, encoding=&quot;utf-8&quot;) as f:<br>        records = [json.loads(line) for line in f]<br>    if args.limit &gt; 0:<br>        records = records[:args.limit]<br>    print(f&quot;→ Will process {len(records)} reviews&quot;)<br><br>    # --- Compute Δ for each review ---<br>    results = []<br>    for rec in tqdm(records, desc=&quot;Processing reviews&quot;):<br>        text = rec.get(&quot;reviewText&quot;, &quot;&quot;).strip()<br>        if not text:<br>            continue<br><br>        zlen = len(zlib.compress(text.encode(&quot;utf-8&quot;)))<br>        sum_lp_tgt = compute_sum_logprob(tgt_mdl, tgt_tok, text, device)<br>        sum_lp_ref = compute_sum_logprob(ref_mdl, ref_tok, text, device)<br><br>        delta_tgt = sum_lp_tgt / zlen<br>        delta_ref = sum_lp_ref / zlen<br>        delta_diff = delta_tgt - delta_ref<br><br>        results.append({<br>            &quot;reviewID&quot;:   rec.get(&quot;reviewerID&quot;),<br>            &quot;zlib_len&quot;:   zlen,<br>            &quot;sum_logp_tgt&quot;: sum_lp_tgt,<br>            &quot;sum_logp_ref&quot;: sum_lp_ref,<br>            &quot;delta_tgt&quot;:  delta_tgt,<br>            &quot;delta_ref&quot;:  delta_ref,<br>            &quot;delta_diff&quot;: delta_diff,<br>        })<br><br>    # --- Save results with timestamp ---<br>    output_dir = &#39;/home/kavach_d/.../results&#39;<br>    os.makedirs(output_dir, exist_ok=True)<br>    timestamp = datetime.now().strftime(&quot;%Y:%m:%d_%H:%M&quot;)<br>    filename  = f&quot;{timestamp}.txt&quot;<br>    filepath  = os.path.join(output_dir, filename)<br>    with open(filepath, &quot;w&quot;) as f:<br>        json.dump(results, f, indent=2)<br><br>    print(f&quot;Wrote {len(results)} items to {filepath}&quot;)<br><br>if __name__ == &quot;__main__&quot;:<br>    main()</pre><h3>Key Points</h3><ul><li><strong>Normalization</strong>: Dividing log-probability by zlib-compressed length ensures fairness across text lengths and complexities.</li><li><strong>Reference model requirement</strong>:<br> <em>It is essential that the reference model </em><strong><em>never</em></strong><em> saw your dataset during pre-training</em>. Here, we use <strong>EleutherAI’s Pythia-6.9B-deduped</strong>, trained solely on the Pile (which contains zero Amazon reviews), ensuring a clean baseline.</li><li><strong>4-bit quantization</strong> via BitsAndBytes keeps memory and compute efficient.</li></ul><h3>Thresholding for Membership</h3><p>Once you’ve computed Δ\DeltaΔ for each review, we can simply flag those with Δ\DeltaΔ above a chosen threshold as “members.”</p><pre>import json<br>import pandas as pd<br><br># 1. Load the JSON results<br>json_path = &#39;.../results/gemma.txt&#39;  # replace with your path<br>with open(json_path, &#39;r&#39;, encoding=&#39;utf-8&#39;) as f:<br>    data = json.load(f)<br><br># 2. Create a DataFrame<br>df = pd.DataFrame(data)<br><br># 3. Set your threshold<br>threshold = 0.01<br><br># 4. Flag membership<br>df[&#39;is_member&#39;] = df[&#39;delta_diff&#39;] &gt;= threshold<br><br># 5. Print a summary with percentages<br>total       = len(df)<br>num_members = df[&#39;is_member&#39;].sum()<br>pct_members = num_members / total * 100<br>pct_non     = 100 - pct_members<br><br>print(f&quot;Threshold set at: {threshold}&quot;)<br>print(f&quot;Total samples:      {total}&quot;)<br>print(f&quot;Flagged as member:  {num_members} ({pct_members:.2f}%)&quot;)<br>print(f&quot;Flagged as non-member: {total - num_members} ({pct_non:.2f}%)&quot;)</pre><ul><li><strong>Threshold choice</strong> (0.01 here) may be tuned based on your desired false-positive/false-negative trade-off.</li><li>Change the threshold to 0.05, 0.001 and also see how they vary.</li><li>You could also plot graphs and find an optimal value of the Threshold</li><li>The final summary tells you what fraction of reviews appear memorized by the target model.</li></ul><h3>Conclusion</h3><p>Membership inference based on <strong>likelihood differentials</strong> offers a straightforward, interpretable way to audit LLM pre-training. By comparing a suspect target model against a carefully chosen reference that <em>cannot</em> have seen the dataset, we obtain a clear signal of memorization. This methodology helps ensure robust, honest evaluations of model generalization — vital in both research and real-world deployments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec76ccdc73d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Fine-Tune Language Models with TensorFlow and Hugging Face]]></title>
            <link>https://medium.com/@22kavachdheer/how-to-fine-tune-language-models-with-tensorflow-and-hugging-face-bf179130a412?source=rss-d651c9d9089b------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf179130a412</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[fine-tuning]]></category>
            <dc:creator><![CDATA[Kavach Dheer]]></dc:creator>
            <pubDate>Sat, 07 Jun 2025 17:54:15 GMT</pubDate>
            <atom:updated>2025-06-07T17:54:15.432Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Fine-Tune Language Models</h3><p>In this article, we’ll walk through fine-tuning BERT on the MRPC (Microsoft Research Paraphrase Corpus) task using TensorFlow and Hugging Face’s Transformers library.</p><h3>Why Fine-Tune?</h3><p>Fine-tuning adjusts the model’s parameters with task-specific data, giving you a model that truly understands your application domain.</p><h3>1. Setup and Imports</h3><p>First, install the necessary libraries:</p><pre>pip install transformers datasets tensorflow scikit-learn</pre><p>Then, import the Python modules you’ll need:</p><pre>import tensorflow as tf<br>import numpy as np<br>from transformers import AutoTokenizer, TFAutoModelForSequenceClassification, DataCollatorWithPadding<br>from tensorflow.keras.losses import SparseCategoricalCrossentropy<br>from sklearn.metrics import accuracy_score, f1_score<br>from datasets import load_dataset</pre><h3>2. Load the Dataset</h3><p>We’ll use the GLUE benchmark’s MRPC split, which contains pairs of sentences labeled as paraphrase or not.</p><pre>raw_dataset = load_dataset(&#39;glue&#39;, &#39;mrpc&#39;)</pre><h3>3. Tokenization</h3><p>BERT requires token IDs, attention masks, and token type IDs. We’ll use the bert-base-uncased checkpoint’s tokenizer to process both sentences in each example.</p><p>By using .map(), each batch of raw examples is passed through the tokenizer and the resulting token IDs, attention masks, and token type IDs are appended directly to the dataset without duplicating all other fields.</p><pre>checkpoint = &#39;bert-base-uncased&#39;<br>tokenizer  = AutoTokenizer.from_pretrained(checkpoint)</pre><pre>def tokenize_function(example):<br>    return tokenizer(<br>        example[&#39;sentence1&#39;],<br>        example[&#39;sentence2&#39;],<br>        truncation=True<br>    )</pre><pre>tokenized_dataset = raw_dataset.map(tokenize_function, batched=True)</pre><h3>4. Padding and Batching</h3><p>To feed data into TensorFlow, we need uniform sequence lengths per batch. The DataCollatorWithPadding will pad on the fly.</p><p>Using a collator means padding is applied per batch at runtime, rather than padding every example in advance to the same length. This dynamic padding further reduces memory overhead by ensuring sequences are only as long as the longest example in each batch.</p><pre>data_collator = DataCollatorWithPadding(tokenizer=tokenizer, return_tensors=&#39;tf&#39;)</pre><pre>tf_train_dataset = tokenized_dataset[&#39;train&#39;].to_tf_dataset(<br>    columns=[&#39;input_ids&#39;, &#39;attention_mask&#39;, &#39;token_type_ids&#39;],<br>    label_cols=[&#39;label&#39;],<br>    shuffle=False,<br>    collate_fn=data_collator,<br>    batch_size=8,<br>)</pre><pre>tf_validation_dataset = tokenized_dataset[&#39;validation&#39;].to_tf_dataset(<br>    columns=[&#39;input_ids&#39;, &#39;attention_mask&#39;, &#39;token_type_ids&#39;],<br>    label_cols=[&#39;label&#39;],<br>    shuffle=True,<br>    collate_fn=data_collator,<br>    batch_size=8,<br>)</pre><h3>5. Model Initialization</h3><p>We load TFAutoModelForSequenceClassification with two output labels (paraphrase vs. non-paraphrase).</p><pre>model = TFAutoModelForSequenceClassification.from_pretrained(<br>    checkpoint,<br>    num_labels=2<br>)</pre><h3>6. Compile and Train</h3><p>Choosing the right optimizer and learning rate is crucial. Here we use the default Adam with a sparse categorical cross-entropy loss (since labels are integer IDs).</p><pre>model.compile(<br>    optimizer=&#39;adam&#39;,<br>    loss=SparseCategoricalCrossentropy(from_logits=True),<br>    metrics=[&#39;accuracy&#39;],<br>)</pre><pre>model.fit(<br>    tf_train_dataset,<br>    validation_data=tf_validation_dataset,<br>    epochs=5,<br>)</pre><blockquote><strong><em>Tip:</em></strong><em> Start with a small learning rate (e.g., 2e-5) and consider using learning rate schedules or warm-up — this often improves stability and final performance.</em></blockquote><h3>7. Evaluation</h3><p>After training, we evaluate on the validation set:</p><pre># 1. Get raw logits<br>logits = model.predict(tf_validation_dataset).logits</pre><pre># 2. Convert to predicted class IDs<br>class_preds = np.argmax(logits, axis=-1)</pre><pre># 3. Compute metrics<br>refs = raw_dataset[&quot;validation&quot;][&quot;label&quot;]<br>print({<br>    &quot;accuracy&quot;: accuracy_score(refs, class_preds),<br>    &quot;f1&quot;:       f1_score(refs, class_preds)<br>})</pre><h3>Conclusion</h3><p>Fine-tuning lets you leverage cutting-edge models with minimal coding. With just a few lines of code, you can adapt BERT (or any Transformer) to your task, unlocking powerful language understanding. Experiment with hyperparameters, regularization, and training strategies to push performance even further.</p><p>Happy fine-tuning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf179130a412" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Birth and Evolution of CNNs: From ImageNet to Human-Level Performance]]></title>
            <link>https://medium.com/@22kavachdheer/the-birth-and-evolution-of-cnns-from-imagenet-to-human-level-performance-5e8d0c32a94c?source=rss-d651c9d9089b------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e8d0c32a94c</guid>
            <category><![CDATA[cnn]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Kavach Dheer]]></dc:creator>
            <pubDate>Sun, 02 Feb 2025 19:47:13 GMT</pubDate>
            <atom:updated>2025-02-02T19:47:13.717Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I will explain the founding blocks of CNN: the story behind it, the model that powers it, the people who created it, how it came into existence, and how it transformed the world of deep learning.</p><h3><strong>Part -1 Vision and Creation of Dataset</strong></h3><p>So the story starts in 2006. At that time, all the researchers were working on the models and algorithms of deep learning. Then a woman named <strong>Fei-Fei Li</strong> enters and decides to work on creating a dataset, because as we all know, in order for deep learning to perform really well, we need datasets. Everybody was trying to optimize and create algorithms, but we needed data, and nobody was working on that, and we didn’t have a dataset. <strong>Fei-Fei Li</strong> saw a larger vision — she knew even if we have these models and algorithms, we needed data to train and test them. So she started to work on creating a dataset called <strong>ImageNet</strong>.</p><p>It took her 2.5 years to create the dataset, and in 2009, she and her team completed it.</p><p>The creation of this dataset was phenomenal, and this was one of the biggest datasets. Indeed, to create this dataset, she and her team had to go through several challenges.</p><ol><li><strong>Scale:</strong> It contains over 14 million images that have been hand-annotated to indicate what objects are pictured. The database has more than 20,000 categories or “synsets.”</li><li><strong>Creation Process:</strong> The images were collected from the web and labeled by human workers through Amazon’s Mechanical Turk crowdsourcing platform. Each image was labeled by multiple workers to ensure accuracy.</li><li><strong>Organization:</strong> The database is organized according to the WordNet hierarchy. Each meaningful concept in WordNet, possibly described by multiple words or word phrases, is called a “synonym set” or “synset.”</li></ol><h3><strong>Part -2 Vison of ILSVRC</strong></h3><p>I strongly believe humans are competitive by nature — they tend to break their limitations when competing with each other. Olympics, racing, and sports are prime examples. Even in daily life, humans constantly compete, whether lifting heavier weights than friends at the gym or striving to outperform colleagues at work. The examples are endless.</p><p>Similarly, from 2006 to 2009, Netflix held a competition in machine learning. They offered a $1 million prize to anyone who could improve their recommendation system’s accuracy by 10%. The winning solution used matrix factorization techniques, which became a foundational approach in recommendation systems and revolutionized the field. It was this competitive spirit that transformed the field of recommender systems.</p><p>Similary, viewing this <strong>Fei Fei Li</strong> thougt of creating a similar competiton, because now we had the dataset, but we needed to to create models to test and create them.</p><p>So <strong>Fei Fei li</strong> and her team launched the ImageNet Large Scale Visual Recognition Challenge (ILSVRC) in 2010. ILSVRC was an annual competition that used a subset of ImageNet data to test and compare computer vision algorithms. The challenge focused on:</p><ul><li><strong>Image Classification:</strong> Algorithms had to classify images into 1000 different object categories</li><li><strong>Object Detection:</strong> Models needed to identify and locate specific objects within images</li><li><strong>Object Localization:</strong> Participants had to precisely indicate where objects appeared in images using bounding boxes.</li></ul><h3><strong>Part -3 Entry of Geoferry Hilton with the disruption of CNN</strong></h3><p>In the first two years of the competition, researchers used machine learning models, achieving error rates of <strong>28% in 2010 and 25% in 2011</strong>.</p><p>The <strong>breakthrough came in 2012</strong> when <strong>Geoffrey Hinton</strong> entered the competition. (If you don’t know who he is, you might want to brush up on your deep learning history!)</p><p>Hinton introduced a revolutionary architecture called <strong>AlexNET( Image of architecture attached at bottom)</strong>, which was groundbreaking for three reasons: it used <strong>GPU</strong> to <strong>train</strong> the <strong>models</strong>, implemented <strong>relu</strong> as the <strong>activation function</strong>, and pioneered the use of <strong>CNN</strong>.</p><p>He dramatically reduced the <strong>error rate to 16%</strong>, marking the moment when <strong>CNN took its birth</strong>. Everyone’s attention turned to CNNs, amazed by how this model significantly outperformed traditional machine learning approaches.</p><p>From that point forward, there was no looking back. CNNs revolutionized the field of deep learning, fulfilling Fei-Fei Li’s vision and validating her hard work.</p><p>The competition continued, with new CNN architectures consistently lowering the error rate:</p><p>2013 — ZFNet — 11.7%</p><p>2014 — VGG — 7.3%</p><p>2015 — GoogleNet — 6.7%</p><p>The competition concluded with ResNet in 2016 achieving a remarkable 3.5% error rate, surpassing human-level performance of 5%.</p><p>If you liked this article give it a Like, if not write in the comment section how I can improve more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wpNtb1dAV3UqAWJG.png" /><figcaption><strong>AlexNET</strong></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e8d0c32a94c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Multithreading]]></title>
            <link>https://medium.com/@22kavachdheer/multithreading-a8975204132b?source=rss-d651c9d9089b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8975204132b</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[multithreading]]></category>
            <category><![CDATA[oops-in-java]]></category>
            <category><![CDATA[threads]]></category>
            <category><![CDATA[java8]]></category>
            <dc:creator><![CDATA[Kavach Dheer]]></dc:creator>
            <pubDate>Mon, 27 Jan 2025 12:42:00 GMT</pubDate>
            <atom:updated>2025-01-27T12:42:00.028Z</atom:updated>
            <content:encoded><![CDATA[<p>A one stop guide for Multithreading</p><h3>Definations</h3><h4>1. Processes</h4><ul><li>A <strong>process</strong> represents a program in execution. It is an independent entity that has its own memory space (stack, heap, etc.) and system resources.</li><li>A process is managed by the operating system, and it runs sequentially unless it’s specifically designed to utilize multiple threads.</li></ul><h4>2. Threads</h4><ul><li>Threads are indeed considered <strong>“lightweight processes”</strong> because they share the same memory space and resources of their parent process.</li><li>Each thread has its own execution stack and program counter, but it operates within the context of a process. This shared memory allows for easier data exchange between threads, but it also introduces potential challenges, like race conditions.</li></ul><h4>3. Multithreading</h4><ul><li><strong>Multithreading</strong> occurs when multiple threads are running within a single process. These threads can execute concurrently, depending on the CPU and the threading model.</li><li>The main advantage of multithreading is the ability to perform tasks in parallel, improving efficiency and responsiveness in programs. For instance:</li><li>One thread might handle user input while another processes data or communicates with a server.</li></ul><h3>Typical Workflow</h3><h4>1. A process creates the environment:</h4><ul><li>A process is the container that holds everything needed for a program to run, such as the code, data, and system resources (like memory, file handles, etc.).</li><li>Think of a process as the “house” that provides the space and utilities for threads to “live and work.”</li></ul><h4>2. <strong>Threads work within the process:</strong></h4><ul><li>Threads are the “workers” inside the process. They share the process’s resources (like memory, files, and variables) but have their own <strong>execution context</strong> (like program counter, stack, and registers).</li><li>Each thread can execute independently, but since they share the same memory, they can easily communicate with each other.</li></ul><h4><strong>3. Multithreading:</strong></h4><ul><li>When a process has multiple threads, those threads can run concurrently (or in parallel on multi-core CPUs).</li><li>For example, in a web browser (a process), one thread might render the webpage, another might handle user input, and a third might manage background network requests — all happening in the same process.</li></ul><h3>Parallel Computing</h3><h4>1. Parallel Computing at the Process Level</h4><p>On a <strong>multi-core CPU</strong>, multiple <strong>processes</strong> can run in parallel at the same time.</p><blockquote>For example:</blockquote><ul><li>Core 1: Running Process A</li><li>Core 2: Running Process B</li><li>Core 3: Running Process C</li><li>Core 4: Running Process D</li><li>Each process runs independently and may or may not have threads inside it.</li></ul><h4>2. Parallel Computing at the Thread Level (Multithreading)</h4><ul><li>Inside a <strong>single process</strong>, <strong>multithreading</strong> allows different threads to run concurrently or in parallel.</li><li>On a <strong>multi-core CPU</strong>, threads from the same process can run in parallel on separate cores.</li></ul><blockquote>For example:</blockquote><ul><li>Process A (on 4 threads):</li><li>Core 1: Thread 1 of Process A</li><li>Core 2: Thread 2 of Process A</li><li>Core 3: Thread 3 of Process A</li><li>Core 4: Thread 4 of Process A</li><li>On a <strong>single-core CPU</strong>, multithreading does not achieve true parallelism but instead uses <strong>time slicing</strong> to switch between threads very quickly, creating the <strong>illusion of parallelism</strong> (this is called <strong>concurrency</strong>).</li></ul><h4>3. Can Parallel Computing Be Achieved with Just One Process?</h4><ul><li>Yes, <strong>a single process</strong> can achieve parallel computing using multithreading, but only if:</li></ul><ol><li>The CPU has <strong>multiple cores</strong> to run threads simultaneously.</li><li>The threads are properly written to divide the workload across those cores.</li><li>If the CPU has only <strong>one core</strong>, the threads will run one after another (time slicing), and it won’t be true parallel computing, but rather concurrency.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*75aNiUKCrIbwnD_pfouZdQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*CCHbdyEW9ZIlVoo89OkBJg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*TOoWgyqJqLvhg7cWL68Zuw.png" /></figure><h4>Key Takeaway</h4><p>To achieve <strong>parallel computing</strong>:</p><ol><li>Multiple <strong>processes</strong> can run in parallel on multiple CPU cores.</li><li>Inside a <strong>single process</strong>, <strong>multithreading</strong> allows parallelism if the CPU supports it (multi-core).</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8975204132b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Overview of Sentiment Analysis with Large language model]]></title>
            <link>https://medium.com/@22kavachdheer/overview-of-sentiment-analysis-with-large-language-model-14061f5d2c30?source=rss-d651c9d9089b------2</link>
            <guid isPermaLink="false">https://medium.com/p/14061f5d2c30</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[sentiment-analysis]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Kavach Dheer]]></dc:creator>
            <pubDate>Fri, 27 Sep 2024 12:44:59 GMT</pubDate>
            <atom:updated>2024-09-27T12:44:59.678Z</atom:updated>
            <content:encoded><![CDATA[<p>This article explores overview of Sentiment Analysis, covering its definition and types. We’ll start by examining what Sentiment Analysis is and its various types. Finally , we’ll delve into Sentiment Analysis using Large Language Models.</p><h3>Introduction</h3><p>Sentiment analysis is also called as Opinion analysis or Opinion mining.Several real-world applications require sentiment analysis for detailed investigation. for example, product analysis, discover which components or qualities of a product appeal to customers in terms of product quality.</p><p>Sentiment analysis for various applications like reputation management, market research, and competitor analysis, product analysis, customer voice, etc. Various issues are associated with sentiment analysis and natural language processing, such as individuals informal writing style, sarcasm, irony, and language-specific challenges. There are many words in different languages whose meaning and orientation change depending on the context and domain in which they are employed. Therefore, there are not many tools and resources available for all the languages. Sarcasm and irony are two of the most critical challenges that have recently attracted the attention of researchers. There has been much development in detecting sarcasm and irony in text. There are many challenges in sentiment analysis.</p><h3>Types of Sentiment Analysis</h3><p>Sentiment analysis has been investigated on several levels: Document Level, Sentence Level, Phrase Level, and Aspect Level. Sentiment analysis in each level such as document, sentence and phrase, aspect level shown in Fig. 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/1*oW-sh6rMh-cFpA3j18dXFA.png" /></figure><p><strong>Document level sentiment analysis</strong></p><p>Document-level: Document level sentiment analysis is performed on a whole document, and single polarity is given to the whole document. This type of sentiment analysis is not used a lot. It can be used to classify chapters or pages of a book as positive, negative, or neutral. At this level, both supervised and unsupervised learning approaches can be utilized to classify the document</p><p><strong>Sentence level sentiment analysis</strong></p><p>Sentence level: In this level of analysis, each sentence is analyzed and finding with a corresponding polarity. This is highly useful when a document has a wide range and mix of sentiments associated with it (Yang and Cardie 2014). This classification level is associated with subjective classification (Rao et al. 2018). Each sentence polarity will be determined independently using the same methodologies as the document level but with greater training data and processing resources. The polarity of each sentence may be aggregated to find the sentiment of the document or used individually.</p><p><strong>Phrase level sentiment analysis</strong></p><p>Phrase level: Sentiment analysis also be performed where opinion words are mined at phrase level, and classification will be done. Each phrase may contain multiple aspects or single aspects. This may be useful product reviews of multiple lines; here, it is observed that a single aspect is expressed in a phrase.</p><p><strong>Aspect level sentiment analysis</strong></p><p><strong>Aspect-level sentiment analysis</strong> takes words (and phrases) from text to identify specific aspects or features being discussed, and then it determines the sentiment (positive, negative, or neutral) associated with those aspects.</p><p>How it works:</p><p><strong>Identify the aspects</strong> (features) from the text:</p><p>For example, in a sentence like “The screen is bright, but the sound quality is poor,” the words <strong>“screen”</strong> and <strong>“sound quality”</strong> are recognized as aspects.</p><p><strong>Determine the sentiment</strong> for each aspect:</p><p>The sentiment associated with <strong>“screen”</strong> is <strong>positive</strong> (because of the word “bright”).</p><p>The sentiment associated with <strong>“sound quality”</strong> is <strong>negative</strong> (because of the word “poor”).</p><p>In this way, aspect-level sentiment analysis goes beyond just detecting the overall tone of the text and identifies opinions related to specific words or aspects mentioned.</p><h3>Feature Selection</h3><p>To develop a classification model it requires first identifying relevant features in dataset</p><ol><li>Emoji are facial expressions used in sentiment analysis to convey emotions.</li><li>Punctuation marks, or exclamation marks, serve to highlight the force of a positive or negative remark. Similarly, the apostrophe and the question mark are other punctuation marks.</li><li>Words in slang, such as lol and rofl. These are frequently used to introduce a sense of humor into a remark.</li><li>Punctuation marks, like exclamation marks, serve to highlight the force of a positive or negative remark. Similarly, the apostrophe and the question mark are other punctuation marks.</li></ol><h3>Feature Extraction</h3><p>Feature extraction is a key task in sentiment classification as it involves the extraction of valuable information from the text data, and it will directly impact the performance of the model.</p><p>Negations These are the words that can change or reverse the polarity of the opinion and shift the meaning of a sentence. Commonly used negation words include not, cannot, neither, never, nowhere, none, etc. Every word appearing in the sentence will not reverse the polarity; therefore, removing all negation words from stop-words may increase the computational cost and decrease the model’s accuracy. Negation words must be handled with at most care (George et al. 2013). Negation words such as not, neither, nor, and so on are critical for sentiment analysis since they can revert the polarity of a given phrase. For instance, the line “This movie is good.” is a positive sentence, but “The movie is not good.” is a negative sentence. Regrettably, some systems eliminate negation words because they are included in stop word lists or are implicitly omitted since they have a neutral sentiment value in a lexicon and do not affect the absolute polarity. However, reversing the polarity is not straight forward because negation words might occur in a sentence without affecting the text’s emotion.</p><p>Bag of Words (BoW) BoW is one of the simplest approach for extracting text features. BoW will describe the occurrence of words in a document. Bag represents the vocabulary of words using which a vector is formed for each sentence. The main problem with this model is that it does not consider the syntactic meaning of the text. For instance, consider two sentences s1= “the food was good”, s2= “the service was bad”. The vocabulary is created for two sentences where v= {’the’, ‘food’, ‘was’, ‘service’, ‘bad’, ‘good’} and the length of the vector is 6 and is represented as v1= [ 1 1 1 0 0 1] and v2= [1 0 1 1 1 0]. BoW approach performance evaluated using (TF-IDF) which performs better in most cases.</p><h3>Word Embedding</h3><p>Word embeddings represent words in a vector space by clustering words with similar meanings together. Each word is assigned to a vector, which is then learned in a manner similar to neural networks. It learns and chooses a vector from a predetermined vocabulary. The dimension of the words may be chosen by passing it as a hyperparameter. SG model and the continuous CBOW model are two of the most well-known algorithms for word embeddings. Both of these are shallow window approaches methods in which a short window of some size, such as four or six, is specified, and the current word is anticipated using context words in CBOW, while context words are forecasted using the current word in the SG model. Word embeddings are concerned with learning about words in the context of their local usage, which is specified by a window of nearby terms.</p><p><strong>Word2vec</strong> word2vec is a 2-layer neural network that is used for vectorizing the tokens. It is one of the famous and widely used vectorizing techniques developed by Mikolov et al. (2013). Word2vec mainly has two models CBOW and SG. The CBOW model predicts the target word using context words, whereas the SG model predicts the target word using context words. With a larger dataset, the SG model performs better. Global Vectors (GloVe) Global Vectors for word representation have developed (Pennington et al. 2014) by an unsupervised learning approach to generate word embeddings from a corpus word-to-word co-occurrence matrix. GloVe is a popularly used method as it is straightforward and quick to train GloVe model because of its parallel implementation capacity (Al Amrani et al. 2018).</p><p><strong>Fast Text</strong> It is an open-source and free library developed by FAIR (Facebook AI Research) mainly used for word classifications, vectorization, and creation of word embeddings. It uses a linear classifier to train the model, which is very fast in training the model (Bojanowski et al. 2017). It supports a CBOW and SG model. Semantic similarities may be found using this model.</p><p><strong>ELMo</strong> ELMo is a deep contextualized text representation. ELMo contributes to overcoming the limitations of conventional word embedding approaches such as LSA, TF-IDF and n-grams models (Peng et al. 2019). ELMo generates embeddings to words based on the contexts in which they are used to record the word meaning and retrieve additional contextual information. Through pretraining, ELMo can more accurately represent polysemous words in a variety of contexts and is more informative about the text’s higher-level semantics (Ling et al. 2020).</p><h3>Task of Sentiment Analysis</h3><p>Overview of the tasks various tasks of sentiment analysis is shown in the figure 2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*rdvEqjZUZvZeWO9ss6o2hA.png" /></figure><ol><li><strong>Subjectivity Classification</strong> is a Natural Language Processing (NLP) task that aims to classify a piece of text as either <strong>subjective</strong> or <strong>objective</strong>. The goal is to determine whether a text expresses personal opinions, feelings, and beliefs (<strong>subjective</strong>) or factual, neutral information (<strong>objective</strong>).Key Concepts: <strong>Subjective Text</strong> <strong>Definition</strong>: Subjective text expresses personal opinions, judgments, emotions, or viewpoints. It is non-factual and influenced by individual perceptions or feelings. <strong>Example</strong>: “The camera quality is amazing” is subjective because it conveys an opinion or personal experience.<strong>Objective Text</strong> <strong>Definition</strong>: Objective text provides factual information, usually neutral, verifiable, and not influenced by personal feelings or opinions. <strong>Example</strong>: “The camera has a 12-megapixel sensor” is objective because it presents a measurable fact.</li><li><strong>Sentiment Classification</strong> is a Natural Language Processing (NLP) task that involves determining the emotional tone or sentiment expressed in a piece of text. It classifies the text into predefined categories of sentiment, such as <strong>positive</strong>, <strong>negative</strong>, or <strong>neutral</strong>. This classification is often used in applications like product reviews, social media analysis, and customer feedback to understand users’ opinions or emotions about a particular subject.</li><li><strong>Opinion Spam Detection</strong> is the process of identifying and filtering out deceptive, fake, or manipulative opinions (e.g., product reviews, ratings, comments) that are intended to mislead potential consumers or distort the reputation of a product, service, or organization. These “spam” opinions are crafted to either promote or demote an item artificially and are a growing issue, especially in platforms like Amazon, Yelp, TripAdvisor, and social media.</li><li><strong>Implicit Language Detection</strong>: Sarcasm, irony, and humor are generally referred to as Implicit Languages.</li><li><strong>Aspect Extraction</strong> is a key task in Natural Language Processing (NLP) that focuses on identifying specific components, features, or attributes of a product or service mentioned in text. This process is crucial for understanding opinions expressed in reviews, feedback, or discussions, particularly in the context of <strong>aspect-based sentiment analysis</strong>.Key Concepts:</li><li><strong>Aspects</strong>: Aspects are specific features or attributes of a product, service, or entity that users express opinions about. For example, in a restaurant review, aspects could include <strong>food quality</strong>, <strong>service</strong>, <strong>ambiance</strong>, and <strong>price</strong>. In a smartphone review, aspects might be <strong>battery life</strong>, <strong>camera quality</strong>, <strong>screen resolution</strong>, etc.<br>Example:<br><strong>Review</strong>: “The food at the restaurant was delicious, but the service was slow.”<br><strong>Identified Aspects</strong>:</li></ol><ul><li><strong>Food</strong>: Associated sentiment is positive (delicious).</li><li><strong>Service</strong>: Associated sentiment is negative (slow).</li></ul><h3>Methodology</h3><p>Three mainly used approaches for Sentiment Analysis include Lexicon Based Approach, Machine Learning Approach, and Hybrid Approach, deep learning. In addition, researchers are continuously trying to figure out better ways to accomplish the task with better accuracy and lower computational cost.</p><h3>Neutal Network</h3><p>RNN (Donkers et al. 2017) have proven to improve results when trained on sufficient data and computations. Variants of RNN (Pham and Le-Hong 2017) like LSTM (Bandara et al. 2020), GRU (Cheng et al. 2020), Bi-LSTM (Abid et al. 2019; Cho and Lee 2019) have been used extensively in Sentiment analysis and related NLP task (Abid et al. 2019; Khan et al. 2016). Attention models are being introduced recently, which gives models an edge over another model. Recent transfer learning techniques using BERT (Devlin et al. 2018) and GPT (Ethayarajh 2019) are gaining the attention of researchers as the model is already trained on a massive corpus for days on high-end GPU and Super computers. Weights can be fine-tuned using the training dataset to get accurate results. Deep learning-based techniques are becoming highly popular due to their outstanding performance in recent times.</p><h3>Aspect Based Sentiment Analysis</h3><p>ASBA is valuable and rapidly growing part of sentiment analysis that has gained prominence in recent years. Three critical phases compose aspect-level sentiment analysis: aspect detection, polarity or sentiment categorization, and aggregation.</p><p>Aspect level sentiment analysis is most popular among product reviews or hotel reviews, as this approach will help them identify various aspects focused by the review writers and help them rectify aspects that have a negative sentiment.</p><p>Complex algorithms like LSTM, Bi-LSTM or pre-trained models like BERT, GPT-2 may be used to accomplish the task. The researchers avoid vanilla RNN as it faces many problems like vanishing and exploding gradient descent.</p><h3>Transfer Learning</h3><p>Transfer learning is one of the advances techniques in AI, where a pre-trained model can use its acquired knowledge to transfer to a new model. Transfer learning uses the similarity of data, distribution, and task. The new model directly uses the previously learned features without needing any explicit training data. Training data may be used to fine-tune to the model to a new task.</p><p>In 2018, Google AI Language Researchers open-sourced a new model for NLP called BERT. It has a breakthrough and has taken the industry of deep learning by storm due to its performance. In the work of Han et al. (2021) Transformer network revolutionized the area of NLP and replaced the usage of LSTM and Bi-LSTM. The main advantage is that Transformers do not suffer from vanishing or exploding gradient problems as they do not use recurrence at all, and also, they are faster and less expensive to train. BERT is an extension of the Transformers model proposed (Vaswani et al. 2017) in the “Attention is all you need” paper. BERT uses transformers, an attention mechanism that learns contextual relationships between words or sub-words in a given text. The input in this model contains the word embeddings and position embeddings, unlike transformers, but also has an extra vector representing the sentence it belongs to handle two or more sentences at a time. BERT consists of encoders based transformers; the encoder part is similar to the transformer encoder. BERT has two models BERT base with 12 encoders stacked with 110 million parameters and BERT large model with 24 encoders stacked with 330 million parameters. BERT model trained in two stages pre-training and fine-tuning. This is the model main advantage as the fine-tuning with the dataset can be done as per the task.</p><h3>Large Language Models</h3><ul><li><strong>LLMs’ Performance on Text Length:</strong>LLMs tend to perform better on longer texts using zero-short training due to thier pre-training on vast datasets.However, performance may decline with shorter texts or informal language, suggesting zero-shot training alone is insufficient for all tasks. While training an LLM on domain-specific tasks can yield better results, it’s often too costly and resource-intensive. Comparatively, we can achieve similar or better results using aspect-based sentiment analysis on movie reviews.</li><li><strong>Challenges with Informal Language:<br></strong>Slang, sarcasm, and punctuation pose significant challenges for LLMs.|<br>Movies are inherently subjective, and reviews often employ metaphors, sarcasm, etc. This complexity could pose challenges for LLMs</li><li><strong>Zero-shot capability is promising but not a universal solution</strong>:</li><li><strong>LLMs can analyze sentiment without specific training data</strong>: This zero-shot capability is advantageous when labeled review datasets are scarce.</li><li><strong>Performance may lag behind fine-tuned models</strong>: While convenient, zero-shot LLM performance might not always match the accuracy of models specifically trained on labeled review data, especially in specialized domains</li><li>Aspect based Sentiment Analysis in LLM hasn’t been reserched yet properly, whether zero-short LLM performs better or worst is still unclear.</li></ul><h3>When to use LLM for sentiment analysis</h3><p><strong>Considerations for choosing LLMs for review analysis</strong>:</p><ul><li><strong>Nature of the reviews</strong>: Consider the source (social media vs. dedicated review platforms), length, and domain specificity.</li><li><strong>Need for aspect-based analysis</strong>: Assess if understanding sentiment towards specific aspects is necessary.</li><li><strong>Availability of labeled data</strong>: If labeled review data is scarce, zero-shot or few-shot LLM approaches might be suitable, while ample data could favor fine-tuned models.</li><li><strong>Importance of explainability</strong>: If understanding the reasoning behind sentiment predictions is crucial, LLMs’ explainability features are advantageous.</li></ul><p>The resource I used to write this article is</p><ul><li>Wankhade, M., Rao, A.C.S. and Kulkarni, C., 2022. A survey on sentiment analysis methods, applications, and challenges. <em>Artificial Intelligence Review</em>, <em>55</em>(7), pp.5731–5780.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14061f5d2c30" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Analysis of an Ethical Case Study on Chatbot “Tay” created by Microsoft]]></title>
            <link>https://medium.com/@22kavachdheer/analysis-of-an-ethical-case-study-on-chatbot-tay-created-by-microsoft-dd13718c8881?source=rss-d651c9d9089b------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd13718c8881</guid>
            <category><![CDATA[case-study]]></category>
            <category><![CDATA[ethics-in-tech]]></category>
            <category><![CDATA[ethics]]></category>
            <category><![CDATA[ethical-ai]]></category>
            <dc:creator><![CDATA[Kavach Dheer]]></dc:creator>
            <pubDate>Wed, 28 Aug 2024 17:05:50 GMT</pubDate>
            <atom:updated>2024-08-28T17:05:50.518Z</atom:updated>
            <content:encoded><![CDATA[<h3>1. INTRODUCTION TO THE CASE</h3><p>[1] A chatbot is an AI program that simulates a conversation between a system and a user using NLP techniques. Chatbots can better grasp normal language thanks to natural language processing, which also helps them produce thoughtful responses.</p><p>Microsoft on March 23, 2016 released an artificial intelligence chat bot named [2] “Tay” as an acronym for “thinking about you” on Twitter under the name “TayTweets” and handle “@TayandYou”.</p><p>The goal of the Microsoft team was to have an chatbot that is both useful and empathetic, and helps the society as a whole.Therefore,[3]Tay was created to emulate the speech patterns of a 19-year old American woman and to pick up new vocabulary through communication with other Twitter users.Moreover, the bot was designed to reply to other Twitter users and it also had the ability to caption photos provided to it into a form of a Internet memes.</p><p>The chatbot was shut-down by the Microsoft in less than [4] 2 days because within 24 hours the chatbot had gained more than 50,000 followers and produced nearly 100,000 tweets in which most of them were tremendously racist and offensive.</p><p>Microsoft created three more versions after this but all them faced the same issue they were racist and offensive because of which they were scrutinised by media and they hurted the sentiments to a lot of communities and people.Moreover, while some later version only deflected to answer the questions related to ethical values but in the end they were all shut down without solving the real issue.</p><h3><strong>2. A REVIEW OF THE LITERATURE ON THE SUBJECT</strong></h3><p>There is a famous saying in Artificial Intelligence Community i.e “Garbage in Garbage Out”, It means that the kind of data we provide to the model it will create the results based on that.</p><p>The team of Microsoft created the chatbot using the data that was not properly processed and analysed and because of which within hours of release Tay absorbed sufficient information from the Twitter-verse to develop into a despicable tweeter, shamelessly expressing a variety of unfounded and unimaginable prejudices.</p><p>Microsoft instead of solving the root cause which was the chatbot was trained on unfiltered data, solving that and providing a data which is not offensive and has prejudice they only made the chatbot to avoid giving answers when asked questions based on political and ethical values</p><h3><strong>3. Lifficks’s Analysis of the Case</strong></h3><p>Main participants and Actions</p><blockquote><strong>3.1. Participants in the Primary Process</strong></blockquote><ul><li><strong>Engineers :-</strong>They were aware of the system flaw after the first version failed miserably, but instead of fixing the root problem of training the model on furnished data.They attempted to sweep the problems under the rug by making the model deflect certain questions.</li><li><strong>PR Team :-</strong>The PR team was changing the narrative of the people by making everyone believe that [5] Tay only imitated what it observed from other people rather than having been programmed to be racist or fascist.</li><li><strong>Managers :-</strong>After failing the initial versions of the chatbots the managers should have cross-checked with the engineering team and taken an action to improve in the future version, unfortunately all the 4 versions faced the same issue.</li></ul><blockquote><strong>3.2. Participants in the Secondary Process :-</strong></blockquote><ul><li><strong>Eithnicity Group :- </strong>Tay made a lot of racist tweets to people from different ethnicities.</li><li><strong>Political Views :-</strong>It made a lot of negative political jokes such as on Donald Trump.</li><li><strong>Gender Biased :-</strong>It was very much gender biased towards men and made jokes on feminism which hurted the sentiments of a lot of people.</li></ul><blockquote><strong>3.3. Participants who are implied :-</strong></blockquote><ul><li><strong>Engineering Team (Primary) :-</strong>They developed the Chatbot but never fixed the issues in the later versions.</li><li><strong>People on Twitter(Secondary) :-</strong>It hurted the sentiments of all the people and communities on Twitter.</li></ul><blockquote><strong>3.4. Reduced List</strong></blockquote><ul><li><strong>Engineers :</strong>The algorithms were created by this group, and they unwittingly used biased and prejudice data to train the program and did not fix the root cause in the later versions.</li></ul><blockquote><strong>3.5. Legal Considerations</strong></blockquote><ul><li><strong>Statue of Limitation, 1957, Section 72 :-</strong>The company benefited from these parts because it was experimenting with a technology whose behaviour was not entirely predictable and was not aware of bias and prejudice in the training data.</li><li><strong>General Data Protection Regulation[6] :-</strong>The GDPR mandates that businesses obtain applicants’ consent before processing their sensitive data, which is one of several key points. However, the business must be open about how it uses the data and how long it intends to keep it. Both of these appear to have been broken in this instance because the report shows that Twitter users was unaware that they were taking part in a trial and helping the bot learn and train more.</li></ul><blockquote><strong>3.6. Possible Options for Participants :-</strong></blockquote><ul><li><strong>The Company:</strong>Could have researched implications and possible challenges on releasing the chatbot on Twitter.<br> Could have tested the chatbot within the company before releasing it on the Twitter.</li><li><strong>Engineers :-</strong>Statistical study on the training data set might have been possible. They might have been alerted to the data skewness and prejudice by such study.<br> After failing the initial versions should have fixed the root problems rather than each time only restricting the chatbot to utilise its full potential.</li></ul><blockquote><strong>3.7. Possible Justifications for Actions</strong></blockquote><ul><li><strong>The Company :-</strong>According to the report, the corporation reportedly started this as an experiment and learned little about issues relating to privacy, morality, or ethics.</li><li><strong>Engineers :-</strong>Engineers also viewed this as an experiment to see if it was possible to create a chatbot using AI and NLP, therefore they didn’t design and build the system in a way suitable for “production” by conducting adequate study and testing.</li></ul><blockquote><strong>3.8. Key Statements</strong></blockquote><ul><li>“… tweets were highly offensive. In less than 16 hours Tay had turned into a brazen anti-Semite and was taken offline for re-tooling”</li><li>“… Tay said: ‘The Nazis were right”</li><li>“…They need to be reliable to misuse too”</li><li>“…flaming garbage pile in, flaming garbage pile out.”</li><li>“…Tay said:I fucking hate feminists they should all die and burn in hell”</li><li>“… Tay said: Hitler was right I hate the jews”</li><li>“… Tay has been built using “relevant public data” that has been “modeled, cleaned, and filtered,” but it seems that after the chatbot went live filtering went out the window”</li></ul><blockquote><strong>Ethical Questions Raised</strong></blockquote><ol><li>Has the company thought about the project’s moral and ethical ramifications ?</li><li>Did the data used to train the AI system was examined by engineers ? Did the engineers test the system properly ?</li><li>Did the Engineers fix the chatbot from being racist and prejudice ?</li></ol><blockquote><strong>3.10. Analogies Employed</strong></blockquote><ul><li><strong>Google Vision AI :-</strong>[7] In 2015, Google came under fire for an image-recognition system that automatically labeled images of black individuals as “gorillas.”</li><li><strong>Amazon AI Recruiting Tool :-</strong>[8]Amazon built AI hiring tool but it was gender biased as it favoured men more than women.</li></ul><blockquote><strong>3.11. Comparison with the new ACM code of Ethics</strong></blockquote><p>Following is a list of ACM code of ethics that the organisation did not consider [9]</p><p><strong>1.2 </strong>Avoid harm</p><p><strong>1.4 </strong>Be fair and take action not to discriminate</p><p><strong>2.1 </strong>Strive to achieve high quality in both the processes and products of professional work.</p><p><strong>2.5 </strong>Give comprehensive and thorough evaluations of computer systems and their impacts, including analysis of possible risks.</p><p><strong>3.1 </strong>Ensure that the public good is the central concern during all professional computing work.</p><p><strong>3.2 </strong>Articulate, encourage acceptance of, and evaluate fulfilment of social responsibilities by members of the organisation or group.</p><p><strong>3.6 </strong>Use care when modifying or retiring systems.</p><h3><strong>4. Alternative Proposals:</strong></h3><ul><li><strong>Pessimistic: </strong>Company could wait for the AI technology in NLP to improve so that it can be a very efficient chatbot. Meanwhile, use pre-generated answering chatbots without the use of AI.</li><li><strong>Optimistic: </strong>Organisation could optimise the AI system provide it a good training data and do design modification.</li><li><strong>Compromise: </strong>Make a hybrid chatbot using both the AI and traditional chatbots without the use of AI.</li></ul><h3><strong>Conclusion</strong></h3><p>We have been trying to develop chatbots from 1994 [10], the traditional chatbots were created using pre-generated answers but now with great computational power and the advantage of both neural networks &amp; NLP we can create AI chatbots which are intelligent enough to generate the answer on its own.Unfortunately, with great power comes great responsibility,In order to create a very efficient chatbot we need to train the chatbot on a dataset which is not biased and not of prejudice.Moreover, before releasing it to public we should test it thoroughly so that it performs decently unlike the chatbot Tay which failed miserably and hurted the sentiments of so many people and communities.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd13718c8881" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Phd a Music Symphony]]></title>
            <link>https://medium.com/@22kavachdheer/phd-a-music-symphony-f79e7ca99581?source=rss-d651c9d9089b------2</link>
            <guid isPermaLink="false">https://medium.com/p/f79e7ca99581</guid>
            <category><![CDATA[research]]></category>
            <category><![CDATA[phd-student]]></category>
            <category><![CDATA[phd-thesis]]></category>
            <category><![CDATA[researchers]]></category>
            <category><![CDATA[phd]]></category>
            <dc:creator><![CDATA[Kavach Dheer]]></dc:creator>
            <pubDate>Fri, 09 Aug 2024 08:19:28 GMT</pubDate>
            <atom:updated>2024-08-09T08:19:28.341Z</atom:updated>
            <content:encoded><![CDATA[<p>It’s been one year into my PhD, and whenever I meet non-PhD people, they always ask how a PhD is and what exactly it involves. I always struggled to give the most appropriate answer.</p><p><strong>After months of pondering, I think I finally have an answer.</strong></p><p><strong>I feel PhD students are like music artists.</strong></p><p>For example, a musician first brainstorms and thinks about the idea, subject, or theme of the song. Once they figure that out, they start experimenting with different melodies, spending a lot of time finding the perfect one. Once they have the perfect melody, they spend time writing lyrics to match it.<br>They also collaborate with other musicians, brainstorming on how to complete the jigsaw and make everything sound perfect.<br>After working on it for months, they finally produce the song. They then have to show that music to the record company, and if they like it, they publish it.<br>Once the song is out there, it is there for a lifetime.</p><p><strong>Now, let’s understand how this is very similar to a PhD.</strong></p><p>PhD students also start by brainstorming an idea, subject, or theme on which their PhD will revolve. Once they figure that out, they start experiments to support their idea. A PhD student spends a lot of time, similar to a musician finding the perfect melody, to get the experiment working.<br>Once the PhD student is successful in their experiment, they spend time writing a paper for it, similar to how musicians spend time writing lyrics.<br>PhD students also work in groups or solo, just like musicians, each bringing their specialty.<br>Once the student has worked on the experiments and written the paper, they need to publish it in a journal or conference. These also have rankings; the higher the rank, the more difficult it is to publish, but it’s also highly regarded. Similarly, musicians need to publish their song with a music label company, and it’s difficult to release it with a highly regarded one.</p><blockquote>Once the music is out, it is there for a lifetime. Even when the artist dies, we still listen to their songs and remember them. For example, we still listen to Michael Jackson’s songs.<br>Similarly, once the research is published, we still read about it even when the author has died.</blockquote><blockquote><strong>I strongly feel a PhD is like a song, and we are the musicians.</strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f79e7ca99581" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recommender Systems in Large Langauge Models]]></title>
            <link>https://medium.com/@22kavachdheer/recommender-systems-in-large-langauge-models-1800f90efc8e?source=rss-d651c9d9089b------2</link>
            <guid isPermaLink="false">https://medium.com/p/1800f90efc8e</guid>
            <category><![CDATA[recommendation-system]]></category>
            <category><![CDATA[recommender-systems]]></category>
            <category><![CDATA[large]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Kavach Dheer]]></dc:creator>
            <pubDate>Tue, 18 Jun 2024 12:04:10 GMT</pubDate>
            <atom:updated>2024-06-18T12:20:29.595Z</atom:updated>
            <content:encoded><![CDATA[<p>Up until 2018, transfer learning was only used in the Computer Vision domain for tasks such as object detection, classification, and segmentation. These models were not trained from scratch, but instead were fine-tuned from models that had been pretrained on ImageNet, MS-COCO, and other datasets. In 2018, [1] suggested that transfer learning could be utilized in NLP as well. Google and OpenAI saw this as an opportunity, and within one year, both of them came up with their pre-trained models such as BERT and GPT. Since then, there has been no turning back. The research and developments in the field of NLP skyrocketed, from Text-classification to Conversational AI chatbots like ChatGpt, revolutionizing research and development in Natural Language Processing. Each year, companies expand the parameters and training corpus of their large language models (LLMs). As these models grow larger, they improve in multiple ways:</p><ul><li>Their language understanding and generation become more human-like.</li><li>Their generalization capabilities improve, allowing them to be used for various downstream tasks without fine-tuning •</li><li>LLMs can provide insightful step-by-step reasoning for their outputs</li></ul><p>The research areas of AI are being revolutionized by the rapid progress of LLMs. In the field of information retrieval, search engines are seeing a new shift towards chatbots (i.e., ChatGpt) for information seeking. Devin, a product developed by Cognition, is capable of performing software engineering tasks independently, powered by LLM. It can deploy apps end-to-end, autonomously find and fix bugs, and can train and fine-tune its own AI models and much more. In the field of computer vision, Sora, a product developed by OpenAI, can create realistic and imaginative scenes from text instructions. It can generate minute-long videos with complex scenes and multiple characters, accurately detailing the subject and background.</p><p>Traditional recommender systems struggle to explain why a particular recommendation was made to the user. Additionally, they are not adept at interacting with the user. For instance, chatbots that use LLM excel at user interaction, creating a feeling of conversing with a real human. [Gao et al. 2023] addresses these two challenges by converting user profiles and historical interactions into prompts. It does not rely on training but instead on in-context learning. It learns the user’s preferences during the conversation with the system. Therefore, it provides an LLM-based chatbot interaction interface while also enhancing explainability.</p><p>There are many types of recommender systems, each trained and developed for different tasks, each having thier own unique architecture.Due to this, it becomes very difficult to transfer the knowledge and representation from one task to another. Hence, there weren’t any unified recommendation systems which performed multiple tasks together from the same framework This issue was solved by [Cui et al. 2022; Geng et al. 2022] creating a single framework that could handle multiple recommendation tasks from the same architecture. Modern Recommendation systems typically represent users and items through unique identifiers (IDs), which are then transformed into embedding vectors as parameters that can be learned. These IDbased models (IDRec) have become a standard and have prevailed in the field of recommender systems since ever long, although it has <strong>few limitations:</strong></p><ul><li>It faces cold-start problem when the interactions between the user and items are low it is unsuccessful to provide recommendations.</li><li>In real world applications maintaining a large, up-to-date embedding matrix for user and item IDs become resource intensive.</li><li><strong>Opaque Decision Process</strong>: IDRec models learn from and act upon the embeddings of user and item IDs. These embeddings are high-dimensional vectors that represent users and items in a latent space, where the dimensions don’t have an inherent meaning understandable to humans. Thus, when a recommendation is made, it’s challenging to explain in human-readable terms why the system considers the item a good match for the user, other than the fact that their embeddings are similar in the model’s latent space.</li><li><strong>Opaque Decision Process:</strong> IDRec models learn from and act upon the embeddings of user and item IDs. These embeddings are high-dimensional vectors that represent users and items in a latent space, where the dimensions don’t have an inherent meaning understandable to humans. Thus, when a recommendation is made, it’s challenging to explain in human-readable terms why the system considers the item a good match for the user, other than the fact that their embeddings are similar in the model’s latent space.</li><li><strong>Lack of Transferability: </strong>In IDRec systems, every user and item is assigned a unique identifier (ID) that is specific to a particular platform or dataset. These IDs are integral to how the system understands and categorizes data. The unique nature of these IDs means they are not inherently meaningful outside of their original context. For example, a user ID on one e-commerce site doesn’t correspond to anything on another site, and the same goes for item IDs.This specificity poses a problem when trying to apply a model trained on one platform to another. The model’s learned associations and embeddings for IDs do not translate across platforms because the IDs it “knows” don’t exist elsewhere. The inability to transfer models limits the development of large-scale, general-purpose RS models that can learn from diverse data sources and apply their insights universally. It necessitates training a new model from scratch for each platform, requiring significant data collection and computational resources</li></ul><p>Therefore, in LLM based Recommendation system we alleviate these problems by converting the data in a format which is understood by the LLM and to create a unique identity(IDs) of the items and user we create a short characteristic tokens.</p><h3><strong>Fine Tuned</strong></h3><p>Generally there are two ways of creating Unique Identifiers(IDs) i.e Numerical( eg 1947) and Description( eg titles and attributes ) IDs although both of them have their advantages when used used with traditional recommender systems but when used with LLMs it has some disadvantages such as for Numerical IDs it loses the semantic information, and it cannot utilize the corpus of LLM, therefore it leads to poor recommendation. For the Description IDs it fails to make the user-item unique because of the common words( eg “and”, “the”, “will”). To tackle these issues [Lin et al. 2023] came up with two approaches which make the item unique and also make them distinctive</p><ul><li>Each item is indexed using a combination of its ID, title, and attributes (such as category), allowing the system to capture both the distinctiveness and the semantic richness of each item.</li><li>Incorporating the data structure FM-Index</li></ul><p>He also developed an aggregated grounding module that effectively utilizes these multifaceted identifiers to accurately rank and recommend items within the corpus. While [Liao et al. 2023] does not rely on ID, token, and text-based representations to represent items. Instead, a unique framework, Large Language and Recommendation Assistant (LLaRA), is presented. This framework skillfully converts the sequential recommendation challenge into language modeling by fusing existing recommender models with LLMs. Specifically, LLaRA creates a curriculum learning technique that gradually introduces sequential patterns into the tuning of LLMs, which are learned by conventional sequential recommenders.</p><p>In sequential recommendation, there are some flaws. For instance, models often use a score-and-rank technique (also known as the Top-K strategy). The flaw of this method is that it scores each item separately, meaning that similar items will likely score similarly. In this situation, similar item categories are likely to dominate the model output, which may be suboptimal. In some cases, it is preferable to present the user with a variety of item types. To tackle these issues [Petrov and Macdonald 2023] thier models determines what to recommend at position k only after producing recommendations at position 1..k -1. In order to create recommendations, the model ranks each item iteratively (apart from those that have previously been recommended), adding the highest-scoring item to the recommended items list.Furthermore, the paper proposes a novel SVD Tokenization that reduces the large vocabulary and GPU memory requirements based on the architecture of GPT-2. It breaks the item IDs into sub-item tokens. SVD Tokenization quantizes item embeddings derived from the SVD decomposition of the user-item interaction matrix to produce sub-item tokens. The items can then be generated token by token, in a manner akin to how words in texts are generated from sub-word tokens.Whereas [Yue et al. 2023] uses a two-stage framework for sequential recommendation. First, they retrieve the items using unique identification (IDs). In the second stage, they rank the candidate items by generating scores over candidate indices using the item titles to understand user behavior and transition patterns. Their LLM-based ranking model is used to comprehend user preferences for personalized recommendations. Their LLM ranker is specifically designed to expedite inference via a simple verbalizer, and it utilizes textual attributes for preference comprehension.</p><p>[Lin et al. 2023]aims to utilise both the open and closed source LLM. For the open source, it is fine tuned and uses LLM in place of the original content encoder, emulating the PLM-NR [Wu et al. 2021].For the closed source LLM it uses generative recommendation method, It increases the performance in downstream recommendation tasks by acquiring more informative textual and user attributes and enriching the current training data by implementing different prompting tactics.</p><p>[Li et al. 2023][Bao et al. 2023] aims to mitigate the issue of extensive fine-tuning and slow inference time by converting discrete prompts into continuous prompts. The latter author converts the recommendation data into instructions and then tunes it.</p><h3>Not Fine Tuned</h3><p>Traditional recommender systems, while successful in many aspects, often lack proficiency in user interaction.However, with the advent of Large Language Models (LLMs), there has been a significant shift in this dynamic. LLMs have demonstrated astonishing capabilities, particularly in the area of user interaction.</p><p>They can engage in meaningful conversations, understand user preferences more deeply. For instance, chatbots that use LLM excel at user interaction, creating a feeling of conversing with a real human. [Huang et al. 2023] solve this challenge by combining the capabilities of both, it combines the traditional recommender with the conversational capabilities of LLM. [Wei et al. 2024] solves the data sparsity challenge in the recommendation model by creating a denoised augmentation robustification mechanism.</p><p>They use three LLM-based graph augmentation strategies in three ways:</p><ul><li>Providing additional support to the user-item interaction edge.</li><li>Improving the understanding of item node attributes.</li><li>Performing intuitive user node profiling from a natural language perspective.</li></ul><p>[Peng et al. 2023] tries to determine whether text embeddings from LLMs can aid ads and recommendation services. The techniques they utilize include using GPT embeddings as an input feature, a regularization term, and a pre-training task to integrate the LLM corpus of information into basic PLMs and guide token embedding aggregation. [Ren et al. 2023] aims to enhance existing recommenders with LLM-empowered representation learning by matching the representation space of collaborative relational signals with the semantic space of LLMs. A cross-view mutual information maximization technique facilitates this alignment by creating a single semantic subspace where collaborative relational embeddings and textual embeddings are well aligned. This improves the quality of learned representations by utilizing both generative and contrastive modeling techniques.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1800f90efc8e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding the Evolution of Gpt: From Encoder Decoder to LLMs]]></title>
            <link>https://medium.com/@22kavachdheer/understanding-the-evolution-of-gpt-from-encoder-decoder-to-llms-3bd2a7b615d3?source=rss-d651c9d9089b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3bd2a7b615d3</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[gpt]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[chatgpt]]></category>
            <dc:creator><![CDATA[Kavach Dheer]]></dc:creator>
            <pubDate>Thu, 28 Dec 2023 20:01:54 GMT</pubDate>
            <atom:updated>2023-12-28T20:06:45.235Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Table of Contents</strong></p><ol><li>Introduction</li><li>Methodologies — RNN, Seq2Seq</li><li>Encoder- Decoder</li><li>Attention Mechanism</li><li>Transformers</li><li>Transfer Learning</li><li>LLMs</li><li>References</li></ol><h3>1. Introduction</h3><p>To fully understand how Gpt3 works and how it came into existence, think of it as watching a movie.Just like a movie has multiple parts that need to be understood to grasp the full story, ChatGpt also has different components that contribute to its functioning.</p><p>Before we delve into the details, let’s start with some basic methodology. This will provide a solid foundation before we explore the intricacies of Gpt3.</p><h3>2. Methodologies</h3><blockquote>If you have basic understanding of RNN and Seq2Seq you can directly start reading from Encoder-Decoder</blockquote><h4>2.1 RNN</h4><p>RNN stands for Recurrent Neural Network. It is a type of neural network that is designed to process sequential data by using feedback connections. Unlike traditional neural networks, which process input data independently, RNNs can maintain internal states or memory, allowing them to capture information from previous inputs and use it to make predictions or generate outputs. This makes RNNs particularly effective for tasks involving sequential data, such as natural language processing and time series analysis.</p><p>RNN has 4 types</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*neVCDl42rBaDFtY3J_NmNw.png" /></figure><ol><li><strong>Many to One</strong> — In this type of RNN architecture, multiple input sequences are processed, but only a single output is generated. It is often used for tasks such as sentiment analysis, where the goal is to classify a piece of text into a specific category.</li></ol><p><strong>Example</strong></p><p>We will give many input, such as for a movie review than our model will tell based on the review of the movie, that it was positive[1] or negative[0]</p><p>2. <strong>One to many- </strong>In this type of RNN architecture, a single input is given, and multiple outputs are generated. It is often used for tasks such as image captioning, where the goal is to generate a descriptive caption for a given i</p><p><strong>Example</strong></p><p>Given an image ie the inpur, our model will generate a caption that describes the contents of the image ie the output of the model.</p><p>3<strong>. Many to Many</strong> — In this type of RNN architecture, multiple input sequences are processed, and multiple outputs are generated. It is often used for tasks such as machine translation, where the goal is to translate a sequence of words from one language to another.</p><p><strong>Example</strong></p><p>Given a sentence in English as input, our model will generate the corresponding sentence in French as output.</p><p>It has two types</p><ol><li><strong>Asynchronous</strong> — In this case, the input does not have to match the output exactly.</li></ol><p><strong>Example</strong></p><p>For speech translation, the input “I love India” may produce the output “Mein Bharat se baheth pyaar kerta hun” for Hinglish. In this case, the input consisted of 3 words, but the output consisted of 7 words.</p><p><strong>2. Synchronous </strong>— In Many to Many Synchronous RNN architecture, multiple input sequences are processed, and multiple outputs are generated in a synchronous manner. This type of RNN is commonly used for tasks such as speech recognition or music generation, where the input and output sequences have a one-to-one correspondence, basically the input will match the output exactly.</p><p><strong>Example</strong></p><p>For speech recognition, the input is an audio waveform, and the output is a sequence of recognized words or phonemes that correspond to the input audio.</p><blockquote>Seq2Seq model particularly uses RNN Many to Many [ Asynchronous]</blockquote><h3>2.2 Seq2Seq</h3><p>The Seq2Seq model, short for Sequence-to-Sequence model, is a type of neural network architecture that is used for tasks involving sequential data. It consists of two recurrent neural networks (RNNs), an encoder and a decoder.</p><p>The encoder takes an input sequence, such as a sentence in natural language or a series of data points, and processes it to create a fixed-length context vector, also known as the hidden state. This context vector encapsulates the input sequence’s information. The encoder RNN can be any type of RNN, such as LSTM or GRU.</p><p>The decoder then takes the context vector produced by the encoder and generates an output sequence, which can be of a different length or structure than the input sequence. The decoder RNN is typically another type of RNN, such as LSTM or GRU, and it uses the context vector as its initial hidden state.</p><p><strong>Seq2Seq models have various use cases, including:</strong></p><ol><li><strong>Machine Translation:</strong> Seq2Seq models have been successfully used for translating text from one language to another. The encoder processes the input sentence in the source language, and the decoder generates the corresponding sentence in the target language.</li><li><strong>Chatbot and Conversational</strong> <strong>AI</strong>: Seq2Seq models are employed in building chatbots and conversational agents. They can take an input message from a user and generate an appropriate response based on the learned patterns and context.</li><li><strong>Speech Recognition and Speech Synthesis</strong>: Seq2Seq models are utilised in converting spoken language into written text, as well as generating speech from text. The encoder processes the audio input, and the decoder generates the recognized words or the audio waveform.</li><li><strong>Summarisation and Text Generation</strong>: Seq2Seq models are employed for tasks such as automatic text summarisation and generating coherent paragraphs of text based on a given prompt or topic.</li></ol><p>These are just a few examples of the use cases for Seq2Seq models. The flexibility and effectiveness of Seq2Seq models make them suitable for a wide range of sequential data processing tasks.</p><blockquote>Now that you have understood the basic methodology, let’s dive into the evolution of ChatGpt. ChatGpt was built on 5 previous research studies, which we will explore below. We won’t go into the full depth of each research as that would require a separate article. Instead, I will provide an overview of each study, explaining why it was used and the problem in each of them and how it moved from one research to another to finally develop the ChatGpt. Additionally, I will include links to each research papers if you want to delve deeper into them.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*plCztUxe3sOdjOODG732-g.jpeg" /></figure><blockquote>Lets start with first one.</blockquote><h3>3. Encoder Decoder</h3><p>[1] The Encoder-Decoder model is a type of neural network architecture commonly used in sequence-to-sequence (Seq2Seq) tasks. It consists of two components: an encoder and a decoder.</p><p>The encoder takes an input sequence and processes it to create a fixed-length context vector, also known as the hidden state. This context vector represents the input sequence’s information and captures its important features. The encoder can be any type of recurrent neural network (RNN), such as LSTM or GRU.</p><p>The decoder, on the other hand, takes the context vector produced by the encoder and generates an output sequence. The output sequence can be of a different length or structure than the input sequence. The decoder is typically another type of RNN, such as LSTM or GRU, and it uses the context vector as its initial hidden state.</p><h3>Limitation in Encoder Decoder</h3><p>Encoder Decoder performs really well on small texts but on large texts it tends to forget important information. As the input sequence becomes longer, the context vector produced by the encoder may not be able to capture and retain all the relevant details. This is known as the “vanishing gradient” problem, leading to a loss of information. As a result, the decoder may struggle to generate accurate and coherent output sequences when faced with lengthy inputs.</p><blockquote>As one can see in the image below , when we give the encoder decoder, more than 30 words the quality of the translation starts to degrade.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*ZLRMkp9_nZPc9N0QUFTgTg.png" /></figure><blockquote>Now to solve this issue Attention Mechanism was developed, which bring us to the next part of the movie.</blockquote><h3>4. Attention Mechanism</h3><p>[2] The Attention Mechanism is a component used in neural network architectures, particularly in sequence-to-sequence (Seq2Seq) models. It addresses the limitation of the Encoder-Decoder model, where the context vector may struggle to capture and retain all relevant details for lengthy input sequences.</p><p>In the Seq2Seq model, the encoder takes an input sequence and processes it to create a fixed-length context vector, which represents the input sequence’s information. This context vector is then passed on to the decoder.</p><p>The attention mechanism is a component used in the Seq2Seq model to address the limitation of the Encoder-Decoder model, where the context vector may struggle to capture and retain all relevant details for lengthy input sequences.</p><p>The attention mechanism allows the decoder to focus on specific parts of the input sequence when generating the output sequence. Instead of relying solely on the fixed-length context vector produced by the encoder, the attention mechanism dynamically weighs the importance of different parts of the input sequence at each decoding step.</p><p>To do this, the attention mechanism calculates the similarity between the decoder’s current hidden state and the encoder’s hidden states. By calculating this similarity, the attention mechanism determines which parts of the encoder data are most relevant for the decoder at each step.</p><p>In other words, the attention mechanism stores the information of all the encoder text data and calculates the similarity between the encoder data and the decoder’s current hidden state. This allows the decoder to know which parts of the encoder data are correct and important for generating the output sequence.</p><h3>Limitation in Attention Mechanism</h3><p>The attention mechanism allows the decoder to focus on specific parts of the input sequence when generating the output sequence. It calculates the similarity between the decoder’s current hidden state and all of the the encoder’s hidden states, due to this attention mechanism requires a significant amount of computation resources and training time, as it calculates the similarity between the encoder and decoder data for each word in the encoder sequence.</p><blockquote>Now we come onto the climax of the movie, when the groundbreaking research paper that revolutionized the field of natural language processing and machine translation came which was <strong>“Attention is All You Need”</strong> . It was published in 2017 from Google Research. This paper further improved the Attention Mechanism by using parallel processing instead of sequential processing. This model reduced the computation resources and also reduced the training time.</blockquote><h3>5. GroundBreaking Research “Attention is all you Need” [Transformers]</h3><p>[3] The paper introduces a novel neural network architecture called the Transformer, which is based solely on the attention mechanism without any recurrent or convolutional layers. The attention mechanism allows the model to focus on relevant parts of the input sequence when generating the output sequence, eliminating the need for recurrent connections and making the model highly parallelizable.</p><p>The Transformer model introduced in the paper achieved state-of-the-art performance on machine translation tasks, outperforming traditional sequence-to-sequence models with recurrent or convolutional architectures. It demonstrated that the attention mechanism alone, when combined with a self-attention mechanism called the “scaled dot-product attention,” can effectively capture dependencies between words in a sequence and generate accurate translations.</p><p>One of the key advantages of the Transformer model is its ability to capture long-range dependencies in the input sequence more effectively than traditional recurrent neural networks. This is achieved through the use of self-attention, which allows the model to attend to different parts of the input sequence at different positions. By attending to relevant words in the input sequence, the Transformer model can generate more coherent and accurate translations.</p><h3>Limitations + Race between Google &amp; OpenAI</h3><p>The biggest challenge in developing this transformer is the requirement for a huge amount of data. It does not perform well on small or medium-sized datasets. Only companies like MAANG (Meta, Amazon, Netflix, Google) have access to such large amounts of data to train a transformer and achieve exceptional results.</p><p>Both Google and OpenAI recognized this as a significant opportunity and started working on developing their own transformers. In 2018, they each successfully developed their own transformers using the enormous amount of data they had access to.</p><p>Google’s transformer is called BERT, while OpenAI’s transformer is called GPT. The only difference between the two is that BERT is an encoder-only language model, while OpenAI is a decoder-only language model.</p><blockquote><em>Since not everyone has access to such large datasets, researchers and individuals were unable to develop their own transformers. However, theoretically, using the architecture of ‘Attention is all you need’, everyone knew it would yield astonishing results. Unfortunately, only companies like MANG (Meta, Amazon, Netflix, Google) were able to take advantage of this. In 2018, a new research introduced the concept of Transfer Learning, which revolutionized research in the field of Natural Language Processing. This leads us to the next part of the movie: Transfer Learning.</em></blockquote><h3>6. Transfer Learning</h3><p>[4] In 2018, a model and concept were developed and introduced that the use of transfer learning in Natural Language Processing (NLP), would yield very good results. Prior to this, transfer learning was only used in Convolutional Neural Networks, but not in NLP.</p><p>So, let’s first understand what transfer learning is.</p><p>Transfer learning is a machine learning technique that leverages knowledge gained from one task to improve performance on another related task. Instead of training a model from scratch for each specific task, transfer learning allows us to use pre-trained models that have already been trained on large amounts of data for a related task.</p><p>In transfer learning, the pre-trained model serves as a feature extractor, capturing general patterns and representations from the data. These learned features can then be used as input for a new model that is trained specifically for the target task. By using the pre-trained model as a starting point, the new model can benefit from the knowledge and insights gained from the previous task, even if the datasets are different.</p><p><strong>Example -</strong></p><p>For instance, if you have a dataset of images of cats and dogs, but you don’t have a large enough dataset to train a deep neural network from scratch, you can take a pre-trained model that has been trained on a large dataset, like ImageNet, and use it as a feature extractor. You can remove the last few layers of the pre-trained model and add new layers that are specific to your task, such as a classifier for classifying cats and dogs. Then, you can train this modified model on your smaller dataset, leveraging the knowledge and representations learned from the ImageNet dataset.</p><p>By using transfer learning, you can benefit from the pre-trained model’s ability to extract meaningful features from images and improve the performance of your model, even with limited training data. It saves training time and computational resources while still achieving good results.</p><h3>Advancement in Natural Language Processing: A Game-Changing Era</h3><p>The advancements in Natural Language Processing (NLP) after the introduction of transfer learning have been game-changing. With pre-trained models like BERT and GPT, researchers and developers can leverage transfer learning on these 2 transformers to improve the performance of their own models. This has led to significant progress in tasks such as machine translation, chatbot development, speech recognition, and text generation. The graph of natural language processing advancement has soared since the advent of transfer learning.</p><blockquote><em>Lets move onto the final part of the movie LLMS</em></blockquote><h3>7. LLMs</h3><p>OpenAI continued to work on their Large Language Models (LLMs) and developed GPT-2 and later GPT-3. Meanwhile, Google also made progress with their LLM, creating BARD, although OpenAI’s version proved to be superior. Additionally, Elon Musk is working on his own Language Model called Grok.</p><blockquote><strong>If you enjoyed the content, please give it a like. Each like acts as a dopamine rush for me.</strong></blockquote><h3>8. References</h3><p>I watched this video, which helped me write this document. — <a href="https://www.youtube.com/watch?v=8fX3rOjTloc">https://www.youtube.com/watch?v=8fX3rOjTloc</a></p><p>[1] Sutskever, I., Vinyals, O. and Le, Q.V., 2014. Sequence to sequence learning with neural networks. <em>Advances in neural information processing systems</em>, <em>27</em>.</p><p>[2] Bahdanau, D., Cho, K. and Bengio, Y., 2014. Neural machine translation by jointly learning to align and translate. <em>arXiv preprint arXiv:1409.0473</em>.</p><p>[3] Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A.N., Kaiser, Ł. and Polosukhin, I., 2017. Attention is all you need. <em>Advances in neural information processing systems</em>, <em>30</em>.</p><p>[4] Howard, J. and Ruder, S., 2018. Universal language model fine-tuning for text classification. <em>arXiv preprint arXiv:1801.06146</em>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3bd2a7b615d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A one stop destination for Recommendation Systems]]></title>
            <link>https://medium.com/@22kavachdheer/a-one-stop-destination-for-recommendation-systems-995533058376?source=rss-d651c9d9089b------2</link>
            <guid isPermaLink="false">https://medium.com/p/995533058376</guid>
            <category><![CDATA[recommendation-system]]></category>
            <category><![CDATA[recommendation-engine]]></category>
            <dc:creator><![CDATA[Kavach Dheer]]></dc:creator>
            <pubDate>Tue, 21 Nov 2023 20:44:03 GMT</pubDate>
            <atom:updated>2023-11-21T20:44:03.980Z</atom:updated>
            <content:encoded><![CDATA[<p>Your one stop destination to gain all the knowledge you need from the basics of recommendation system to going in depth to three Major types of recommendation system.</p><h4>Lets start first with what is recommendation system and why do we need them</h4><p>Every day, we are inundated with choices and options. What to wear? What movie to rent? What stock to buy? What blog post to read? The sizes of these decision domains are frequently massive: Netflix has over 17,000 movies in its selection , and Amazon has over 410,000 titles in its Kindle store alone.</p><p>We need a system which will help in suggesting us or help us in decision-making process from the massive options and choices to choose from, and this is exactly where a Recommendation system comes into play.</p><p>Recommender Systems are the set of tools and techniques to provide useful recommendations and suggestions to the users to help them in the decision-making process for choosing the right products or services and giving them a good user experience.</p><p>What a recommendation system does is that it tailors and creates a personalised and unique place for each user.</p><blockquote><strong><em>For Example </em></strong><em>— [1]In Amazon showing programming titles to a software engineer and baby toys to a new mother.</em></blockquote><p>A recommendation knows what a the user needs and suggest them those things.</p><h3>Data Collection</h3><p>Recommendation system needs data to work and there are 2 major ways through which data is collected</p><ul><li><strong>Explicit Feedback</strong> — Through user interface by giving them options.</li></ul><blockquote><strong><em>Example</em></strong><em> —When we create a new Spotify account it asks what genre of music we like, what are the artist we like, our favourite band and so on.</em></blockquote><p>However, it often requires users to actively provide this information, and not all users may be willing to do so. Additionally, collecting explicit feedback can be resource-intensive and may impact the user experience.</p><ul><li><strong>Implicit Feedback</strong> — Observing the User — [3]if a user purchases an item, that is a sign that the user likes the item, while if the user purchases and returns the item that is a sign that the user doesn’t like the item.Implicit feedback is more common and easier to collect because it doesn’t require users to explicitly rate or review items. It is often used when explicit feedback is scarce or unavailable.</li></ul><p>In this article we will be discussing different types of recommendation system what are the algorithms used in them and what are the merits and demerits of each.</p><p>1.</p><p><strong>Content-based</strong></p><p><strong>Collaborative recommendation</strong></p><p><strong>Context base Recommendation System</strong></p><p><strong>Knowledge Based Recommendation System</strong></p><p><strong>Knowledge Graph Recommendation System</strong></p><p><strong>ChatGpt Bases Recommendation System</strong></p><p>Lets understand the first one</p><h3>Content Based Recommendation system</h3><p>[2]<strong>Content-based recommendation</strong> systems try to recommend items similar to those a given user has liked in the past.</p><p>The way this recommendation system works is it first needs data of the user, and it starts collecting those data either by Explicit feedback or implicit feedback and keeps storing the data in database and creates a whole profile on that user.</p><h3><strong>Let’s illustrate how a content-based recommendation system works with a practical example in the context of movie recommendations:</strong></h3><p><strong>Step 1:Item Representation</strong>: Each movie in the system is represented by various features, such as genre, director, actors, and user ratings. For instance:</p><p><em>Movie A</em><strong><em>: </em></strong>Action, Sci-Fi, Directed by Christopher Nolan, Starring Leonardo DiCaprio, User Rating 4.5/5</p><p><em>Movie B</em><strong><em>: </em></strong>Drama, Romance, Directed by Greta Gerwig, Starring Saoirse Ronan, User Rating 4.0/5</p><p><em>Movie C</em><strong><em>:</em></strong> Action, Adventure, Directed by Steven Spielberg, Starring Harrison Ford, User Rating 4.2/5</p><p><strong>Step 2: User Profile Creation</strong>: The system builds a user profile based on the movies the user has interacted with. Let’s say the user has previously liked and watched:</p><p><em>Movie A</em>: Action, Sci-Fi, Directed by Christopher Nolan, Starring Leonardo DiCaprio</p><blockquote><strong><em>The user’s profile might look like this:</em></strong></blockquote><blockquote><strong><em>Preferences: </em></strong><em>Action (high weight), Sci-Fi (medium weight), Christopher Nolan (high weight), Leonardo DiCaprio (medium weight)</em></blockquote><p><strong>Step3: Similarity Calculation</strong>: The system calculates the similarity between the user’s profile and other movies in the database. For example, it might find that Movie D shares many features with the user’s profile:</p><p><em>Movie D</em><strong><em>:</em></strong> Action, Sci-Fi, Directed by Christopher Nolan, Starring Tom Hardy, User Rating 4.3/5</p><p>The similarity calculation could result in a high similarity score between the user’s profile and Movie D because of the shared attributes with Movie A.</p><p><strong>Step 4: Ranking and Filtering</strong>: Based on similarity scores, the system ranks the movies in the database. Movie D, being highly similar to the user’s profile, is ranked at the top.</p><p><strong>Step 5: Recommendation Generation</strong>: The system presents Movie D as a recommendation to the user, as it’s the most relevant to their preferences. The user is more likely to be interested in watching Movie D because it aligns with their past interactions and preferences.</p><p><strong>Step 6: Feedback Loop</strong>: If the user watches Movie D and provides feedback (e.g., by rating it or indicating whether they liked it), this feedback is incorporated into their profile. Over time, the user’s profile evolves to reflect their changing preferences.</p><blockquote>This example simplifies the collaborative filtering process. In practice, large datasets and more complex algorithms are used to provide accurate recommendations.</blockquote><h3>Advantages</h3><ul><li><strong>Personalization</strong>: Content-based recommendation systems can provide highly personalized recommendations because they focus on the specific preferences and characteristics of individual users. This personalization can enhance user satisfaction and engagement.</li><li><strong>Domain-specific Recommendations</strong>: Content-based methods work well when there are domain-specific attributes or features that are important for recommendations. For example, in music recommendation, genre and artist preferences can be crucial.</li></ul><h3>Disadvantages</h3><p><strong>Limited Serendipity</strong>: Content-based recommendation systems may <strong>struggle to introduce users to new and unexpected items</strong> because recommendations are based on the user’s existing preferences and item features.</p><blockquote><strong>Example — </strong>a user may not follow football during the season but then become interested in the Superbowl.</blockquote><h3>Collaborative Recommendation system</h3><p>In this recommendation, it recommends items based on the similar users. For instance, when the recommendation system seeks to suggest content to User A, it examines profiles to identify users with similar preferences. If it identifies that User B shares a similar profile with User A, the system recommends items to User A based on User B’s preferences and likes as well.</p><blockquote>Let’s illustrate how a content-based recommendation system works with a practical example</blockquote><p>Now, let’s say we want to recommend movies to Alice, who has already rated Movie A, Movie C, and Movie E. We’ll use user-based collaborative filtering to make these recommendations.</p><p><strong>Step 1: User Similarity Calculation (Cosine Similarity):</strong></p><p>We calculate the similarity between Alice and the other users based on their movie ratings.</p><ul><li>Similarity(Alice, Bob) = 0.28</li><li>Similarity(Alice, Carol) = 0.95</li><li>Similarity(Alice, Dave) = 0.27</li></ul><p><strong>Step 2: Neighbourhood Selection:</strong></p><p>We select a subset of users with the highest similarity to Alice. Let’s choose a similarity threshold of 0.5, so we select Carol (similarity 0.95).</p><p><strong>Step 3: Rating Prediction:</strong></p><p>Now, we predict Alice’s rating for movies she hasn’t seen (Movie B and Movie D) based on the ratings of users in her neighbourhood (in this case, just Carol).</p><ul><li>Predicted Rating(Alice, Movie B) = (Similarity(Alice, Carol) * Rating(Carol, Movie B)) / Similarity Sum = (0.95 * 3) / 0.95 = 3</li><li>Predicted Rating(Alice, Movie D) = (0.95 * 4) / 0.95 = 4</li></ul><p><strong>Step 4: Top-N Recommendations:</strong></p><p>Now, we recommend the top-N movies with the highest predicted ratings to Alice. Let’s say we recommend the top 2.</p><ul><li>Top 2 Recommendations for Alice: Movie D and Movie B</li></ul><p>So, based on user-based collaborative filtering, Alice should watch Movie D and Movie B because users with similar tastes (in this case, only Carol) liked these movies, and they are predicted to be good matches for Alice’s preferences.</p><blockquote>This example simplifies the collaborative filtering process. In practice, large datasets and more complex algorithms are used to provide accurate recommendations.</blockquote><h3>There are majorly two types of Algotithms used in this</h3><ol><li><strong>Memory based algorithms</strong> — These are heuristic based algorithms that try to predict target user rating for an item based on partial information available about the target user and normalized weights obtained from the dataset.<strong>Commonly used techniques in memory based algorithms are Pearson correlation coefficient and vector similarity techniques. </strong>Some advanced techniques in memory based algorithms include default voting, inverse user frequency, case amplification and imputation-boosted CF algorithms.</li><li><strong>Model based algorithms</strong> — These are machine learning mod- els trying to recognize patterns in datasets available for CF. Commonly used methods in this category include Bayesian networks, clustering models, regression models, latent semantic models etc.</li></ol><h3>Advantages</h3><ol><li><strong>No Need for Item Metadata:</strong> Unlike content-based recommendation systems that rely on item attributes, user-based collaborative filtering doesn’t require detailed information about items. It works solely based on user behavior, making it applicable to a wide range of item types.</li><li><strong>Serendipity</strong>: It can introduce users to new and unexpected items that they might not have discovered on their own. This serendipity can enhance the user experience by exposing users to diverse content.</li></ol><h3>Disadvantages</h3><ol><li><strong>Sparsity</strong>: Collaborative filtering can suffer from sparsity issues when dealing with large datasets, as most users have only interacted with a small fraction of available items. Techniques like matrix factorization and dimensionality reduction can help mitigate this issue.</li><li><strong>Cold Start Problem</strong>: Collaborative filtering struggles to provide recommendations for new users or items with no interaction history. Hybrid recommendation systems that combine collaborative filtering with content-based or other approaches can address this problem.</li></ol><h3>Context Recommendation System</h3><p><em>R</em> : <em>User</em> × <em>Item</em> × <em>Context</em> → <em>Rating</em>,</p><p>In this recommendation it takes into the account the context when it is recommending something, rather than simply relying on users and items, whereas in this recommendation system it takes into account the <strong>time, location, temporal trends, device &amp; platform, weather conditions and so on</strong>.</p><blockquote>Let’s illustrate how a context-based recommendation system works with a practical example</blockquote><p>Consider the application for recommending movies to users, where users and movies are described as relations having the following at- tributes:</p><p><strong>Movie: </strong>the set of all the movies that can be recommended; it is defined as Movie(MovieID, Title, Length, ReleaseYear, Director, Genre).</p><p><strong>User:</strong> the people to whom movies are recommended; it is defined as User(UserID, Name, Address, Age, Gender, Profession).</p><p>Further, the contextual information consists of the following three types that are also defined as relations having the following attributes:</p><p><strong>Theater:</strong> the movie theaters showing the movies; it is defined as The- ater(TheaterID, Name, Address, Capacity, City, State, Country).</p><p><strong>Time:</strong> the time when the movie can be or has been seen; it is defined as Time(Date, DayOfWeek, TimeOfWeek, Month, Quarter, Year). Here, attribute DayOfWeek has values Mon, Tue, Wed, Thu, Fri, Sat, Sun, and attribute TimeOfWeek has values “Weekday” and “Weekend”.</p><p><strong>Companion:</strong> represents a person or a group of persons with whom one can see a movie. It is defined as Companion(companionType), where attribute companionType has values “alone”, “friends”, “girlfriend/boyfriend”, “fam- ily”, “co-workers”, and “others”.</p><p>Then the rating assigned to a movie by a person also depends on where and how the movie has been seen, with whom, and at what time. For example.</p><blockquote>The type of movie to recommend to college student Jane Doe can differ sig- nificantly depending on whether she is planning to see it on a Saturday night with her boyfriend vs. on a weekday with her parents.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=995533058376" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>