<?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 Rachit on Medium]]></title>
        <description><![CDATA[Stories by Rachit on Medium]]></description>
        <link>https://medium.com/@rachit1031?source=rss-62640d9ac23b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qKdtFn-UoTNMJYd1PD5-tQ.jpeg</url>
            <title>Stories by Rachit on Medium</title>
            <link>https://medium.com/@rachit1031?source=rss-62640d9ac23b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 19:18:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rachit1031/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[HOPE — Google’s answer to long term context problems]]></title>
            <link>https://medium.com/@rachit1031/hope-googles-answer-to-long-term-context-problems-8f08d9dc0991?source=rss-62640d9ac23b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f08d9dc0991</guid>
            <dc:creator><![CDATA[Rachit]]></dc:creator>
            <pubDate>Sat, 08 Nov 2025 04:02:00 GMT</pubDate>
            <atom:updated>2025-11-08T04:04:18.935Z</atom:updated>
            <content:encoded><![CDATA[<h3>HOPE — Google’s answer to long term context problems</h3><h3>The Idea</h3><p>Deep learning models today suffer from catastrophic forgetting. To fix this, we have always been throwing more data towards the models and increasing the number of layers in the model. But what if there was another way to eliminate catastrophic forgetting?</p><p>For this, we go back to the basics: “The human brain”. Our brains learn because of neuroplasticity as opposed to LLMs that memorize instead of learning.</p><p>To fix this, Google draws inspiration from the concept of associative memory, which means mapping memories in key-value pairs. It’s just like us recalling a name after looking at a face.</p><p>This concept can be applied to backpropagation, attention, and other components of the transformer architecture.</p><p>To ingest associative memory, we need new types of optimizers for which L2 regression loss is used as opposed to the conventional dot product. This ensures momentum is maintained, making the network more resilient to noisy data.</p><h3>Continuum learning</h3><p>Memory is divided into separate modules; each module has its own update rate, ensuring granular control over memory and more information to be retained over time.</p><h3>Hope</h3><p>A variation of the Titan architecture that is generally good at long-term context. It is a self-modifying recurrent architecture that has unbounded in-context learning and can create an architecture of infinite, looped level learnings.</p><h3>Results</h3><p>Hope outperforms the general transformer architecture on the common reasoning and language modelling benchmark. It also beats Titan in a variety of needle-in-a-haystack benchmarks.</p><p><strong>Sources</strong></p><ol><li><a href="https://abehrouz.github.io/files/NL.pdf">https://abehrouz.github.io/files/NL.pdf</a></li></ol><p>2. https://research.google/blog/introducing-nested-learning-a-new-ml-paradigm-for-continual-learning/</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f08d9dc0991" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OS Agents: Agents That Truly Know Us?]]></title>
            <link>https://medium.com/@rachit1031/os-agents-agents-that-truly-know-us-9c768fdd1d06?source=rss-62640d9ac23b------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c768fdd1d06</guid>
            <category><![CDATA[operating-systems]]></category>
            <category><![CDATA[ai-agents-in-action]]></category>
            <category><![CDATA[retrieval-augmented-gen]]></category>
            <dc:creator><![CDATA[Rachit]]></dc:creator>
            <pubDate>Sun, 02 Nov 2025 03:10:58 GMT</pubDate>
            <atom:updated>2025-11-02T03:10:58.039Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*f9R5ztksGbpmAW6WY67E7g.png" /></figure><p>There’s not a day that goes by that I live without my phone. At this point, my phone knows me better than the people I call close. :)</p><p>Jokes aside, personalization is always better — and what better way to achieve it than baking AI agents directly into the operating system itself? But here’s the thing: to make this work, we need to solve two fundamental problems that sit at the heart of OS-level intelligence.</p><h3>The Two Pillars of Personal OS Agents</h3><p><strong>First, there’s the security question.</strong> How do we securely orchestrate these agents? Ideally, they’d run locally on our devices, but if they must operate in the cloud, the protocol needs to be bulletproof — something we’d trust with our digital lives. Recent work from ColorAgent demonstrates this is achievable through a multi-agent framework that enhances model capabilities via step-wise reinforcement learning and self-evolving training, but the security architecture remains the critical piece.</p><p><strong>Second, and equally important: how does the agent adapt to context and make the experience truly personal?</strong>This isn’t just about remembering your favorite pizza order. It’s about understanding the subtle patterns in how you work, communicate, and make decisions throughout your day.</p><h3>ColorAgent: A Blueprint for Personalized OS Intelligence</h3><p>ColorAgent, detailed in a recent arXiv paper (2510.19386), tackles these challenges head-on using a sophisticated multi-agent framework designed for long-horizon, robust interactions with the environment. Their approach is instructive for anyone thinking about this space.</p><p>The system employs specialized data curation techniques involving custom data generation, filtering, and query generation methods to fine-tune the agents for maximum accuracy. But what’s particularly clever is their dual approach to personalization: they leverage both explicit signals from past user trajectories and implicit cues from user habits, supported by a retrieval-augmented knowledge base that’s queried alongside user instructions.</p><p>The self-learning loop is another critical piece. The system learns from past user behavior but doesn’t indiscriminately update itself — only high-quality data deemed valuable by the system is used for agent refinement. This prevents the agent from learning your bad habits or one-off mistakes.</p><p>On AndroidWorld and AndroidLab benchmarks, ColorAgent achieved success rates of 77.2% and 50.7% respectively, setting a new state of the art — though even the researchers acknowledge that current benchmarks are insufficient for comprehensive OS agent evaluation.</p><h3>Beyond ColorAgent: A Tree-Based Approach to User Context</h3><p>Here’s where things get interesting. Can we use tree structures to index user history and accurately retrieve only what’s needed for the task at hand? Modern “vibe-coding” IDEs already do this with codebases — why not apply the same principle to user behavior?</p><p>This approach could dramatically reduce noise in the data pipeline, ensuring agents focus exclusively on relevant information. Picture this: an index that updates every time you perform an action, storing it under a task as a node, with child nodes representing the specific actions taken within particular apps. The structure would be hierarchical, creating a rich map of your digital behavior.</p><p><strong>But here’s my proposal: instead of a traditional trie structure with its array-based indexing, what if we used embeddings?</strong> Each instance in your environment gets converted to a JSON-like structure for easy storage and retrieval. This eliminates the ambiguity that comes with creating embeddings directly from images or complex UI states. You’re essentially creating a standardized representation layer.</p><p>This embedding-based trie could solve one of the persistent problems with current GUI agents: tapping on the wrong part of the screen. With a well-indexed representation of UI elements and their relationships, agents would have clearer targets. The key insight is ensuring that at any given moment, the current environment state matches the format it’s stored in within the knowledge base — what you see is what’s indexed.</p><h3>Security Architecture: Isolating What Matters Most</h3><p>For security, the knowledge base could reside on a separate chip, isolated from the rest of memory — similar to how keychains work on modern devices. This hardware-level separation would provide a strong security boundary: even if the main system is compromised, your behavioral data and agent memory remain protected. Given sufficient access permissions, this isolated storage could become the trusted foundation for truly personal AI.</p><h3>Fine-Tuning with Temporal Graphs</h3><p>While training these systems, what if we employed a graph-based approach to maintain the chronology of events? Each event would need meaningful closure — not just “user opened email” but “user opened email, read message, flagged for follow-up, then switched to calendar to schedule meeting.”</p><p>This graph structure would preserve causal relationships between actions, giving the agent a deeper understanding of <em>why</em> you do things in a particular sequence, not just <em>what</em> you do. The edges in the graph represent transitions between states, and their weights could reflect how frequently you take particular paths through your workflow.</p><h3>Roadblocks That Might Pop Up</h3><p>Before we get too excited about this vision, let’s talk about the practical challenges that could derail the entire concept.</p><p><strong>1. How does this affect the power and memory consumption of our devices?</strong></p><p>Running multi-agent frameworks, maintaining embedding-based tries, continuously querying knowledge bases, and training on temporal graphs — all of this has a computational cost. If these systems turn our phones into pocket heaters or drain battery life to the point where we’re scrambling for chargers by noon, the personalization gains become meaningless. Users will simply turn them off.</p><p>The thermal and energy constraints of mobile devices aren’t negotiable. We’ve seen what happens when software gets too ambitious with hardware resources — throttling, crashes, and user frustration. Any OS-level agent system needs to operate within these boundaries, not push against them.</p><p><strong>2. Will we need new compression techniques to fit as much information into small memory spaces?</strong></p><p>Here’s the math problem: if you’re indexing every user action, storing embeddings for UI states, maintaining temporal graphs of behavior patterns, and keeping a knowledge base of personal context — that’s a lot of data. And it’s growing continuously.</p><p>Current compression techniques might not cut it. We might need fundamentally new approaches to represent user behavior in compact forms without losing the fidelity that makes personalization effective. It’s one thing to compress a video file; it’s another to compress the semantic meaning of “why this user prefers to handle emails before meetings on Mondays but reverses that order on Fridays.”</p><p>The knowledge base can’t balloon indefinitely. At some point, you hit device storage limits, or the retrieval process becomes too slow to be useful. How do you decide what to keep and what to discard without losing the context that makes the agent personal?</p><h3>The Road Ahead</h3><p>As ColorAgent’s researchers note, significant challenges remain in evaluation paradigms, agent collaboration, and security. But the foundation is taking shape. We’re moving toward a future where our devices don’t just respond to commands — they anticipate needs, adapt to preferences, and become genuine collaborative partners in our digital lives.</p><p>The question isn’t whether OS-level agents will know us intimately. They already do. The real question is: can we build them in a way that’s secure, transparent, and truly in service of making our lives better?</p><p>Source-<a href="https://arxiv.org/pdf/2510.19386">https://arxiv.org/pdf/2510.19386</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c768fdd1d06" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Self-Adapting Language Models — My Two Cents]]></title>
            <link>https://medium.com/codex/self-adapting-language-models-my-two-cents-f9b4806f14fc?source=rss-62640d9ac23b------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9b4806f14fc</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[research]]></category>
            <category><![CDATA[large-language-models]]></category>
            <dc:creator><![CDATA[Rachit]]></dc:creator>
            <pubDate>Wed, 18 Jun 2025 13:40:20 GMT</pubDate>
            <atom:updated>2025-06-20T10:04:24.940Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Self-Adapting Language Models</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*yzMregtbs5-RbgKPUEJDAw.png" /></figure><p>Weights are the magical stuff that power language models. Once a model is trained, its weights become static. When updates are needed, manual fine-tuning is usually the go-to or a more cost-effective alternative is to hook the model up with a RAG (Retrieval-Augmented Generation) system. Both approaches require manual effort, high-quality data, and a good amount of time.</p><p>To tackle this, researchers at MIT introduced <strong>SEAL — </strong><em>Self-Adapting Language Models</em>.</p><p>SEAL revolves around a novel idea called <em>self-edits — </em>natural language instructions that guide how the model’s weights should be updated. These self-edits are embedded into the model using supervised fine-tuning (SFT), and their effectiveness is evaluated on downstream tasks to see which edits actually help.</p><p>What really sets SEAL apart is its reinforcement learning loop. Instead of blindly applying edits, the model uses a lightweight RL algorithm called <strong>ReSTEM</strong> to figure out which self-edits actually improve performance and remembers only those. It’s like trial and error, but smarter: the model learns what works and forgets what doesn’t.</p><p>One of their standout findings was a significant boost in knowledge incorporation accuracy when using a smaller model like Qwen2.5‑7B with SEAL, outperforming even fine-tuning on synthetic data generated by GPT-4.1. In another test, SEAL drastically improved few-shot learning performance, bumping up the success rate to <strong>72.5%</strong>, compared to <strong>0%</strong> for in-context learning and <strong>20%</strong> for self-edits without reinforcement learning.</p><p>This approach opens the door to fully autonomous pipelines that can intelligently update model weights keeping the useful stuff and discarding what doesn’t work.</p><p>That said, a key challenge remains: <em>catastrophic forgetting </em>where too many updates can cause the model to lose valuable knowledge from its original training.</p><p>Reference — <a href="https://arxiv.org/pdf/2506.10943">https://arxiv.org/pdf/2506.10943</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9b4806f14fc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/self-adapting-language-models-my-two-cents-f9b4806f14fc">Self-Adapting Language Models — My Two Cents</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fine tune BERT for text classification]]></title>
            <link>https://medium.com/codex/fine-tune-bert-for-text-classification-cef7a1d6cdf1?source=rss-62640d9ac23b------2</link>
            <guid isPermaLink="false">https://medium.com/p/cef7a1d6cdf1</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[bert]]></category>
            <category><![CDATA[transformers]]></category>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Rachit]]></dc:creator>
            <pubDate>Thu, 20 Jun 2024 11:08:30 GMT</pubDate>
            <atom:updated>2024-06-20T12:04:57.740Z</atom:updated>
            <content:encoded><![CDATA[<p>Fine tuning is an important technique that helps a Large Language Model adapt to custom data and get better at doing downstream tasks like text classification.</p><p>This article mainly focusses on the bare bones of fine tuning and not diving deeper into other techniques like LORA, QLORA etc. To get started the best way to learn is by experimenting with BERT and that is what we are going to do over here.</p><p>There are mainly two ways you could do this :</p><ol><li>Using the hugging face trainer API : Easier to use but not very customisable</li><li>Using PyTorch : Little harder when compared to the trainer but provides more customisability and control over the process</li></ol><p><strong>The Dataset</strong></p><p>We will use the Yelp Reviews dataset, available on Hugging Face. This dataset contains two columns:</p><ul><li><strong>Label</strong>: The rating given, ranging from 1 to 5 stars.</li><li><strong>Text</strong>: The review text.</li></ul><p>Our goal is to train a model that can predict the number of stars from the review text.</p><p><strong>Finetuning using the hugging face trainer API</strong></p><ol><li><strong>Install all the libraries :</strong></li></ol><pre>!pip install --upgrade transformers datasets evaluate huggingface_hub torch</pre><p>Note : Always ensure you have the latest versions of these libraries</p><p><strong>2.</strong> <strong>Load the dataset</strong> : You can load the dataset using the <em>datasets</em> library provided by hugging face</p><pre>from datasets import load_dataset<br>dataset=load_dataset(&quot;yelp_review_full&quot;)</pre><p>Lets have a look at the dataset to see what we are dealing with</p><pre>dataset[&quot;train&quot;][1]</pre><p>This is how our data looks</p><pre>{&#39;label&#39;: 1,<br> &#39;text&#39;: &quot;Unfortunately, the frustration of being Dr. Goldberg&#39;s patient <br>is a repeat of the experience I&#39;ve had with so many other doctors in NYC <br>-- good doctor, terrible staff.  It seems that his staff simply never answers <br>the phone.  It usually takes 2 hours of repeated calling to get an answer.  <br>Who has time for that or wants to deal with it?  I have run into this problem <br>with many other doctors and I just don&#39;t get it.  You have office workers, <br>you have patients with medical needs, why isn&#39;t anyone answering the phone?  <br>It&#39;s incomprehensible and not work the aggravation.  It&#39;s with regret that <br>I feel that I have to give Dr. Goldberg 2 stars.&quot;}</pre><p><strong>3.</strong> <strong>Load the tokenizer and create a function to tokenise your text :</strong></p><pre>from transformers import AutoTokenizer<br><br>tokenizer = AutoTokenizer.from_pretrained(&quot;google-bert/bert-base-cased&quot;)<br><br><br>def tokenize_function(examples):<br>    return tokenizer(examples[&quot;text&quot;], padding=&quot;max_length&quot;, truncation=True)<br><br><br>tokenized_datasets = dataset.map(tokenize_function, batched=True)</pre><p>The tokenizer converts text to into three columns that can be understood by the model namely into input_ids, token_type_ids and attention_mask.</p><p><strong>Create a small batch from the dataset(optional)</strong></p><pre>small_train_dataset = tokenized_datasets[&quot;train&quot;].shuffle(seed=42).select(range(1000))<br>small_eval_dataset = tokenized_datasets[&quot;test&quot;].shuffle(seed=42).select(range(1000))</pre><p><strong>4. Load the model :</strong></p><pre>from transformers import AutoModelForSequenceClassification<br><br>model = AutoModelForSequenceClassification.from_pretrained(&quot;google-bert/bert-base-cased&quot;, num_labels=5)</pre><p>Initialise the number of labels you want to classify for, by using the <em>num_labels</em> parameter</p><p><strong>5. Initialise the training arguments</strong></p><pre>from transformers import TrainingArguments<br><br>training_args = TrainingArguments(output_dir=&quot;test_trainer&quot;)</pre><p><a href="https://huggingface.co/docs/transformers/main/en/main_classes/trainer#transformers.TrainingArguments">https://huggingface.co/docs/transformers/main/en/main_classes/trainer#transformers.TrainingArguments</a> contains more information on the arguments it provides.</p><p><strong>6. Set up the metric calculation function:</strong></p><pre>import numpy as np<br>import evaluate<br><br>metric = evaluate.load(&quot;accuracy&quot;)<br>def compute_metrics(eval_pred):<br>    logits, labels = eval_pred<br>    predictions = np.argmax(logits, axis=-1)<br>    return metric.compute(predictions=predictions, references=labels)</pre><p><strong>7. Start training:</strong></p><pre>from transformers import Trainer<br>trainer = Trainer(<br>    model=model,<br>    args=training_args,<br>    train_dataset=small_train_dataset,<br>    eval_dataset=small_eval_dataset,<br>    compute_metrics=compute_metrics,<br>)<br>trainer.train()</pre><p>You will be prompted to enter a wandb key, insert your key and that should start your training process. This is what you will see after the training is complete.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CclZI2FRe3hzbDiW8Py4Cw.png" /></figure><p>Optionally you can also save your model to hugging face from your notebook</p><pre>from huggingface_hub import login<br>login()<br>model.push_to_hub(&quot;HuggingfaceUsername/yourModelName&quot;)</pre><p><strong>8. Perform inference:</strong></p><p>You can use pytorch to test out your model.</p><pre>import torch<br>import torch.nn.functional as F<br># Load model directly<br>from transformers import AutoTokenizer, AutoModelForSequenceClassification<br><br>tokenizer = AutoTokenizer.from_pretrained(&quot;google-bert/bert-base-cased&quot;)<br>model = AutoModelForSequenceClassification.from_pretrained(&quot;HuggingfaceUsername/yourModelName&quot;)<br>s=&quot;The was awesome and I loved it&quot;<br>tt=tokenizer(s,return_tensors=&quot;pt&quot;, padding=True, truncation=True)</pre><p>Set the model into evaluation mode as we no longer need to update the weights and then you can use it for classification</p><pre>model.eval()<br>with torch.no_grad():<br>    outputs=model(**tt)</pre><p>Lets look at the output to see how it looks</p><pre>SequenceClassifierOutput(loss=None, logits=tensor([[-2.3995, -2.0111, -0.8381,  2.4683,  2.8968]]), hidden_states=None, attentions=None)</pre><p>The only variable we are concerned about here is the logits variable. In this case the logits show how probable it is for a text to be in a certain class. Right now the logits are in a form which is harder to understand. To make it into a form we can understand we would have to convert it to numbers we can understand</p><pre>logits = outputs.logits<br>print(&quot;Logits:&quot;, logits)<br><br># Convert logits to probabilities using softmax<br>probabilities = F.softmax(logits, dim=-1)<br>print(&quot;Probabilities:&quot;, probabilities)<br><br># Determine the predicted class<br>predicted_class = torch.argmax(probabilities, dim=-1)<br>print(&quot;Predicted Class:&quot;, predicted_class.item())</pre><p>The output here is 4.</p><p><strong>Fine tuning using pytorch</strong></p><p>There are a few preprocessing steps that are needed so that the model can understand it</p><ol><li><strong>Dropping columns</strong></li></ol><pre>tokenized_datasets = tokenized_datasets.remove_columns([&quot;text&quot;])<br>tokenized_datasets = tokenized_datasets.rename_column(&quot;label&quot;, &quot;labels&quot;)<br>tokenized_datasets.set_format(&quot;torch&quot;)<br>small_train_dataset = tokenized_datasets[&quot;train&quot;].shuffle(seed=42).select(range(1000))<br>small_eval_dataset = tokenized_datasets[&quot;test&quot;].shuffle(seed=42).select(range(1000))</pre><p><strong>2. Create a Dataloader</strong></p><pre>import torch<br>from torch.utils.data import DataLoader<br>traindataloader=DataLoader(small_train_dataset,batch_size=8,shuffle=True)<br>testdataloader=DataLoader(small_eval_dataset,batch_size=8)</pre><p><strong>3. Download the model and load it onto the GPU</strong></p><pre>from transformers import AutoModelForSequenceClassification<br>model=AutoModelForSequenceClassification.from_pretrained(&quot;google-bert/bert-base-cased&quot;, num_labels=5)<br>device = torch.device(&quot;cuda&quot;) if torch.cuda.is_available() else torch.device(&quot;cpu&quot;)<br>model.to(device)</pre><p><strong>4. Create an optimizer and a learning rate scheduler</strong></p><pre>from torch.optim import AdamW,SGD<br>from transformers import get_scheduler<br>optimizer=SGD(model.parameters(),lr=5e-5)<br>num_epochs=3<br>num_training_steps = num_epochs * len(traindataloader)<br>lr_scheduler = get_scheduler(<br>    name=&quot;linear&quot;, optimizer=optimizer, num_warmup_steps=0, num_training_steps=num_training_steps<br>)</pre><p>You can play around with the optimizers and learning rate schedulers to select what suits best for you.</p><p><strong>5. Training and evaluation</strong></p><p>Set the model into training mode using <em>model.train()</em></p><pre>from tqdm.auto import tqdm<br><br>progress_bar = tqdm(range(num_training_steps))<br><br>model.train()<br>for epoch in range(num_epochs):<br>    for batch in traindataloader:<br>        batch = {k: v.to(device) for k, v in batch.items()}<br>        outputs = model(**batch)<br>        loss = outputs.loss<br>        loss.backward()<br><br>        optimizer.step()<br>        lr_scheduler.step()<br>        optimizer.zero_grad()<br>        progress_bar.update(1)</pre><pre>import evaluate<br><br>metric = evaluate.load(&quot;accuracy&quot;)<br>model.eval()<br>for batch in testdataloader:<br>    b = {k: v.to(device) for k, v in batch.items()}<br>    with torch.no_grad():<br>        outputs = model(**b)<br><br>    logits = outputs.logits<br>    predictions = torch.argmax(logits, dim=-1)<br>    metric.add_batch(predictions=predictions, references=batch[&quot;labels&quot;])<br><br>metric.compute()</pre><p>You can check out my notebook on kaggle for the script <a href="https://www.kaggle.com/code/exterminator11/finetune-bert">https://www.kaggle.com/code/exterminator11/finetune-bert</a>. Happy fine-tuning!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cef7a1d6cdf1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/fine-tune-bert-for-text-classification-cef7a1d6cdf1">Fine tune BERT for text classification</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting started with LLM’s using Langchain]]></title>
            <link>https://medium.com/@rachit1031/getting-started-with-llms-using-langchain-b59fff5513d4?source=rss-62640d9ac23b------2</link>
            <guid isPermaLink="false">https://medium.com/p/b59fff5513d4</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[generative-ai-tools]]></category>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Rachit]]></dc:creator>
            <pubDate>Sat, 28 Oct 2023 11:37:58 GMT</pubDate>
            <atom:updated>2023-10-28T11:37:58.853Z</atom:updated>
            <content:encoded><![CDATA[<p>LLM’s or Large language models are the talk of the town. These models are trained on a huge corpura of text and can answer almost any question a user can think of, hence the name Large Language models. ChatGPT being one of them. LLM’s can be overwhelming for beginners so the best place to get started is <a href="https://huggingface.co/models">hugging face</a>. <a href="https://huggingface.co/">Hugging face</a> is LLM haven😀.</p><p>You can visit the <a href="https://huggingface.co/models">hugging face</a> website and explore what they have to offer by navigating through the navbar on the website.</p><p>To get started with LLM’s we can use the langchain framework. It is a library to create Prompt templates, generate responses via inference and a lot more.</p><p>To access inference, you will have to create a token on hugging face. To do this click on your profile then settings</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WXN6y8N_hU2R3xAaGfEzYg.png" /></figure><p>Then click on access tokens</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*Cp1hmN7GwGnTpg5_wQUQ4A.png" /></figure><p>Create a new token and give it write or read access according to your use case</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eUQM8yjuCQvWqtSau5C-Dg.png" /></figure><p>To install langchain</p><pre>pip install langchain</pre><p>import all the necessary functions and classes required from langchain</p><pre>from langchain import HuggingFaceHub,PromptTemplate, LLMChain<br>import os</pre><p>Now, you have all the tools necessary to generate responses via inference</p><p>Next select a model to infer from, in this case i will be using a text generation model called <a href="https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.1">Mistral-7B-Instruct-v0.1</a>.</p><p>This model was created by mistralai and is open source. It is available for free on hugging face.</p><p>This is a 7 Billion parameter instruct model that can be further fine-tuned using prompts. But that is a story for another day.</p><p>Get the repo_id or model id from the hugging face website</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ls8IUIRvjsWreKZxa8w8KA.png" /></figure><p>First, put your key in an environment variable using the os module in python</p><pre>os.environ[&quot;HUGGINGFACE_HUB_TOKEN&quot;] = &quot;YOUR_API_KEY&quot;</pre><p>Initialize the model_id</p><pre>model_id = &#39;mistralai/Mistral-7B-Instruct-v0.1&#39;</pre><p>Create a prompt template</p><pre>template = &quot;&quot;&quot;<br><br>            You are an AI assistant that provides helpful answers to user queries.<br>            <br>            {question}<br><br>            &quot;&quot;&quot;<br>prompt = PromptTemplate(template=template, input_variables=[&#39;question&#39;])</pre><p>Create a hugging face hub instance to access inference</p><pre>mistral_llm = HuggingFaceHub(huggingfacehub_api_token=os.environ[&#39;HUGGINGFACE_HUB_TOKEN&#39;],<br>                            repo_id=model_id,<br>                            model_kwargs={&quot;temperature&quot;:0.8,&quot;max_new_tokens&quot;:250})</pre><ol><li>Temperature : Defines the creativeness of the LLM. Ranges between 0 to 1</li><li>max_new_tokens : maximum number of tokens that could be in the output. This can vary across use cases and each model also has a maximum number of tokens it can generate</li></ol><p>You can look up other parameters for model_kwargs to customize the output to your requirements.</p><p>Now the only thing left to do is generate</p><pre>mistral_chain = LLMChain(llm=mistral_llm, prompt=prompt)</pre><p>LLM Chain is the most basic type of chain that takes the prompt and the model</p><pre>response=mistral_chain.run(&quot;Draft a partnership agreement for a startup&quot;)<br>print(response)</pre><pre>STARTUP PARTNERSHIP AGREEMENT<br><br>This Partnership Agreement (&quot;Agreement&quot;) is entered into as of [Date] by and between [Startup Company Name], a [State of Incorporation] corporation (&quot;Startup Company&quot;), and [Partner Company Name], a [State of Incorporation] corporation (&quot;Partner Company&quot;).<br><br>WHEREAS, Startup Company and Partner Company desire to enter into a partnership to develop and promote innovative products and services in the [industry] industry;<br><br>NOW, THEREFORE, in consideration of the mutual promises and covenants contained herein, the parties agree as follows:<br><br>1. Purpose. The purpose of this Agreement is to establish a partnership between Startup Company and Partner Company to develop and promote innovative products and services in the [industry] industry.<br><br>2. Scope of Partnership. The partnership shall consist of the following activities:<br><br>    a. Development of new products and services in the [industry] industry;<br>    b. Marketing and promotion of new products and services;</pre><p><strong>Note : Inference can only be done on models that have the API on hugging face</strong></p><p>This is the whole script</p><pre>import os<br>from langchain import HuggingFaceHub,PromptTemplate, LLMChain<br><br>os.environ[&quot;HUGGINGFACE_HUB_TOKEN&quot;] = &quot;YOUR_API_KEY&quot;<br>model_id = &#39;mistralai/Mistral-7B-Instruct-v0.1&#39;<br><br>template = &quot;&quot;&quot;<br><br>            You are an AI assistant that provides helpful answers to user queries.<br>            <br>            {question}<br><br>            &quot;&quot;&quot;<br>prompt = PromptTemplate(template=template, input_variables=[&#39;question&#39;])<br><br>mistral_llm = HuggingFaceHub(huggingfacehub_api_token=os.environ[&#39;HUGGINGFACE_HUB_TOKEN&#39;],<br>                            repo_id=model_id,<br>                            model_kwargs={&quot;temperature&quot;:0.8,&quot;max_new_tokens&quot;:250})<br><br>mistral_chain = LLMChain(llm=mistral_llm, prompt=prompt)<br><br>response=mistral_chain.run(&quot;Draft a partnership agreement for a startup&quot;)<br>print(response)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b59fff5513d4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Extract comments and code from python syntax]]></title>
            <link>https://medium.com/@rachit1031/extract-comments-and-code-from-python-syntax-2ec9b7d99539?source=rss-62640d9ac23b------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ec9b7d99539</guid>
            <category><![CDATA[code]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Rachit]]></dc:creator>
            <pubDate>Thu, 19 Oct 2023 17:36:30 GMT</pubDate>
            <atom:updated>2023-10-19T17:36:30.569Z</atom:updated>
            <content:encoded><![CDATA[<p>Sometimes, the need may arise to extract comments and code from a file. Some applications for them may include making a dataset out of them. To do this there can be two approaches:</p><ol><li>Using the ast module that works on abstract syntax</li><li>Using the re library</li></ol><p>I prefer using the ast module as this way you do not have to worry about loss of data or incorrect patterns for extraction. The ast module works on abstract syntax that is also updated with new python versions so your applications or data extraction techniques are never outdated.</p><p>Here is a small tutorial of how to extract the code from a python file convert it to a string, extract docstrings(from the global scope) and code.</p><p><strong>Step-1 : Converting the file content to string</strong></p><pre>def get_file_content(path):<br>  with open(path,&#39;r&#39;) as f:<br>    content=f.read()<br>    return content</pre><p>This function gets the file contents and returns it in the <em>string</em> datatype</p><p><strong>Step-2 : Extracting the code and comments</strong></p><pre>def get_comment_and_code(content):<br>    parsed = ast.parse(content)<br>    comments=ast.get_docstring(parsed)<br>    for node in ast.walk(parsed):<br>        if not isinstance(node, (ast.FunctionDef, ast.ClassDef, ast.AsyncFunctionDef, ast.Module)):<br>            continue<br>        if not len(node.body):<br>            continue<br>        if not isinstance(node.body[0], ast.Expr):<br>            continue<br>        if not hasattr(node.body[0], &#39;value&#39;) or not isinstance(node.body[0].value, ast.Str):<br>            continue<br>        node.body = node.body[1:]<br>    return astor.to_source(parsed),comments</pre><p>Here’s a breakdown of the function:</p><ol><li>parsed = ast.parse(content): The ast module&#39;s parse function is used to parse the input content and create an abstract syntax tree (AST) representation of the Python code. The AST represents the structure of the code.</li><li>comments = ast.get_docstring(parsed): This line extracts the docstring from the parsed code using the ast.get_docstring function. The docstring is typically a string enclosed in triple-quotes that serves as documentation for a module, function, or class. It is not considered a regular comment.</li><li>The function then iterates through the nodes in the AST using ast.walk(parsed) to process and filter the code:</li></ol><ul><li>It checks if the current node is one of FunctionDef, ClassDef, AsyncFunctionDef, or Module using isinstance. These are top-level structures in Python code.</li><li>If the node has an empty body (no code within it), it is skipped.</li><li>If the first statement in the body is not an Expr node (an expression), it is skipped.</li><li>If the expression is not of type Str (a string), it is also skipped.</li><li>If all the conditions are met, it removes the first statement from the body list, which effectively removes the comment or docstring that was present before the code.</li></ul><p>Finally, the function uses the astor library to convert the modified AST back into source code using astor.to_source(parsed), and it returns the modified source code along with the extracted comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ec9b7d99539" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Customising your firewall rules for macOS to block incoming connections]]></title>
            <link>https://medium.com/@rachit1031/customising-your-firewall-rules-for-macos-to-block-incoming-connections-dba8c40e88b1?source=rss-62640d9ac23b------2</link>
            <guid isPermaLink="false">https://medium.com/p/dba8c40e88b1</guid>
            <category><![CDATA[firewall]]></category>
            <category><![CDATA[firewall-security]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[applescript]]></category>
            <category><![CDATA[macos-ventura]]></category>
            <dc:creator><![CDATA[Rachit]]></dc:creator>
            <pubDate>Tue, 25 Jul 2023 02:12:52 GMT</pubDate>
            <atom:updated>2023-07-25T02:12:52.522Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EP0EomVGI6eyU2APKs31CQ.png" /></figure><h3>Introduction</h3><p>All of us have used a firewall at some point in our life. But have you ever wondered if you can customise the rules that govern the functioning of a firewall? But why customise, out of the box your firewall only comes with certain capabilities that do not provide all-around protection for your computers so you might want to block out a few connections that look suspicious. This can be done using the pfctl software inbuilt in your mac. pfctl is the software used by macOS for firewalling.</p><h3>The firewall</h3><p>Before doing any changes remember to turn on your firewall from the <strong>System Settings-&gt;Network-&gt;Firewall</strong> option</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*2eFZliiN6fLLmM_Ckc1qZw.png" /></figure><p>All the rules for the firewall are stored in a file <strong>/etc/pf.conf </strong>this file comes out of box with your mac. This file comes with preloaded anchors that give the basic layout for the firewall. You can check the basic configuration of your firewall by using the <strong>sudo nano /etc/pf.conf </strong>command<strong>.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cdd_cfMDqPMXAEn_ZUE7eA.png" /></figure><p>You can add or remove rules to this file to customize the working of the firewall.</p><h4>Blocking an incoming connection</h4><p>Incoming connections to your PC can be blocked in three ways</p><ol><li>On a specific port</li><li>for a specific IP address</li><li>for a specific IP address on a specific port</li></ol><h4>On a specific Port</h4><p>Use the <strong>echo block return in proto tcp from any to any port 5500 | sudo tee -a /etc/pf.conf </strong>this adds the line to the file <strong>/etc/pf.conf </strong>you will then need to flush or refresh the rules using <strong>sudo pfctl -f /etc/pf.conf </strong>always do this with caution as it may flush out all the rules then restart the firewall using <strong>sudo pfctl -E </strong>. <strong>sudo</strong> is used as all these commands require root permissions</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YJsjGBo4YLLYCUYU7JR1Pg.png" /></figure><p>This is how the the output will look</p><h4>For a specific IP address</h4><p>Use the <strong>echo block return in proto tcp from IP_address_to_block to any | sudo tee -a /etc/pf.conf </strong>this command adds directly to the file<strong> /etc/pf.conf </strong>and then you will need the flush the rules and restart the firewall as shown above</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5c62hL3a-I4EeU0Q4rYlmw.png" /></figure><h4>For a specific IP address on a specific port</h4><p>Use the <strong>echo block return in proto tcp from IP_address_to_block to any port PORT_TO_BLOCK | sudo tee -a /etc/pf.conf </strong>this command adds directly to the file<strong> /etc/pf.conf </strong>and then you will need the flush the rules and restart the firewall as shown in the first example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4-OlUg2pjiD_LNJEtMyK3w.png" /></figure><p>After all this your <strong>/etc/pf.conf file </strong>will look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0iha4Npc91f6mTOeX-Ih0A.png" /></figure><h4>Unblocking the port and IP</h4><p>use the <strong>sudo sed -i ‘’ ‘/block return in proto tcp from 192.168.100.12 to any port 5500/d’ /etc/pf.conf</strong>. This command removes the line from the file and then flush the rules using <strong>sudo pfctl -f /etc/pf.conf </strong>and then reload the firewall using <strong>sudo pfctl -E.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OtIOjIqVTb3lplXCywCTMw.png" /></figure><p>if might have used sudo recently on some other command it will prompt you for your password</p><p>You can use the same approach mentioned above to unblock the other ports and IP addresses by only changing the rule in the command.</p><h4>Automation</h4><p>You can also automate the blocking and unblocking part using something called applescript. Applescript comes built-in with your mac. You can write it in the script editor that comes pre-installed with your Mac in the <strong>Applications-&gt;Other</strong> folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*tbrLe5JIrS758yJqNRVvwA.png" /></figure><p>AppleScript is a scripting language developed by Apple for inter-application communication and scripting tasks.</p><h4>Blocking using AppleScript</h4><pre>on run argv<br> if (count of argv) &lt; 1 then<br>  display dialog &quot;Please provide the IP address to block as a command-line argument.&quot; buttons {&quot;OK&quot;} default button 1<br> else<br>  set ipToBlock to item 1 of argv<br>  set portToBlock to item 2 of argv<br>  set blockedRule to &quot;block return in proto tcp from &quot; &amp; ipToBlock &amp; &quot; to any port &quot; &amp; portToBlock<br>  <br>  do shell script &quot;echo &#39;&quot; &amp; blockedRule &amp; &quot;&#39; | sudo tee -a /etc/pf.conf&quot;<br>  do shell script &quot;sudo pfctl -f /etc/pf.conf&quot;<br>  do shell script &quot;sudo pfctl -E&quot;<br> end if<br>end run</pre><p>This script takes in as argument the IP address you want to block and the port you want to block. You can run this script using <strong>osascript name_of_file IP_address Port_number.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yVpcBTwFKTbEq6rWync6HQ.png" /></figure><p>It will ask for your password if you haven’t used <strong>sudo</strong> lately.</p><h4>Unblocking using AppleScript</h4><pre>on run argv<br> if (count of argv) &lt; 1 then<br>  display dialog &quot;Please provide the IP address to unblock as a command-line argument.&quot; buttons {&quot;OK&quot;} default button 1<br> else<br>  set ipToUnblock to item 1 of argv<br>  set portToBlock to item 2 of argv<br>  set blockedRule to &quot;block return in proto tcp from &quot; &amp; ipToUnblock &amp; &quot; to any port &quot; &amp; portToBlock<br>  <br>  do shell script &quot;sudo sed -i &#39;&#39; &#39;/&quot; &amp; blockedRule &amp; &quot;/d&#39; /etc/pf.conf&quot;<br>  do shell script &quot;sudo pfctl -f /etc/pf.conf&quot;<br>  do shell script &quot;sudo pfctl -E&quot;<br> end if<br>end run</pre><p>This script takes in as argument the IP address you want to unblock and the port you want to block. You can run this script using <strong>osascript name_of_file IP_address Port_number.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yeFvbsY9ImuLMzHK-zax0g.png" /></figure><p>This was a basic introduction as to how to customise your Apple firewall to block out incoming connections.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dba8c40e88b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using the Python CICFlowMeter tool for Mac]]></title>
            <link>https://medium.com/@rachit1031/using-the-python-cicflowmeter-tool-496564259ac4?source=rss-62640d9ac23b------2</link>
            <guid isPermaLink="false">https://medium.com/p/496564259ac4</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[collecting-logs]]></category>
            <category><![CDATA[log-collection]]></category>
            <category><![CDATA[pip]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Rachit]]></dc:creator>
            <pubDate>Mon, 24 Apr 2023 15:13:04 GMT</pubDate>
            <atom:updated>2023-05-04T06:34:41.056Z</atom:updated>
            <content:encoded><![CDATA[<p>CICFlowMeter is a network traffic flow generator and analyser. This tool can be used to generate bidirectional flows of data and as well as create a csv file with over 80 features from real-time network traffic logs from your own computer.</p><p>There are two ways in which you can install Python CICFlowMeter:</p><ol><li>Download from gitlab</li></ol><pre>git clone https://gitlab.com/hieulw/cicflowmeter<br>cd cicflowmeter<br>python setup.py install</pre><p>2. Using pip</p><pre>pip install cicflowmeter</pre><p>if the above command does not work you may want to try</p><pre>pip3 install cicflowmeter</pre><p>After downloading the cicflowmeter tool from one of the above two methods the usage of the tool is as follows</p><pre>usage: cicflowmeter [-h] (-i INPUT_INTERFACE | -f INPUT_FILE) [-c] [-u URL_MODEL] output<br><br>positional arguments:<br>  output                output file name (in flow mode) or directory (in sequence mode)<br><br>optional arguments:<br>  -h, --help            show this help message and exit<br>  -i INPUT_INTERFACE    capture online data from INPUT_INTERFACE<br>  -f INPUT_FILE         capture offline data from INPUT_FILE<br>  -c, --csv, --flow     output flows as csv</pre><p>The interface for cicflowmeter is your choice, one way to check the interfaces that are active is to run the “ifconfig” command in Macs to check for the interfaces available.</p><pre>ifconfig</pre><p>This command will give you a list of interfaces available just like the one in the image below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VQBhQd8PVfksd6pAYmFYXA.png" /></figure><p>The interface is en0 and the status shows whether the service is active or not.</p><p>The tool can be used in two ways:</p><ol><li>Convert pcap files to csv files</li></ol><pre>cicflowmeter -f example.pcap -c flows.csv</pre><p>When this command is executed the contents of the example.pcap file are stored in the flows.csv file as specified in the command. If you want the file to be stored at a particular location you can give the path to the output file path/to/flows.csv</p><p>2. It can also be used to monitor real-time networks and convert them into csv files for further use</p><pre>cicflowmeter -i en0 -c flows.csv</pre><p>If this does not work you may want to add “sudo” at the beginning</p><pre>sudo cicflowmeter -i en0 -c flows.csv</pre><p>The path for flow.csv is again upto the user and can be specified by the user . This is an example path/to/flows.csv</p><p>The first time you run this command you may see an error like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DBJy-DMK4SjuEIDbdbljuw.png" /></figure><p>To fix this you can go the the flow.py file of the cicflowmeter tool and change all occurences of Decimal(“1e6”) to float(“1e6”). This change should get the job done.</p><p>After fixing these errors when you run the “sudo cicflowmeter -i en0 -c flows.csv” the output will look something like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*na8MoA0HWhQDUBVjAi8zLQ.png" /></figure><p>This shows that log collection has started and you can verify the same from the flows.csv file.</p><p>The above commands may take some time to run so sit back and enjoy the article with a cup of coffee☕️😀.</p><p>For more information visit <a href="https://pypi.org/project/cicflowmeter/">https://pypi.org/project/cicflowmeter/</a> and <a href="https://www.unb.ca/cic/research/applications.html#CICFlowMeter">https://www.unb.ca/cic/research/applications.html#CICFlowMeter</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=496564259ac4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>