<?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 Adamized on Medium]]></title>
        <description><![CDATA[Stories by Adamized on Medium]]></description>
        <link>https://medium.com/@paryagsahni2?source=rss-6ddb2c027610------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ABxquxsFo-lK7XIsMXr0XQ.png</url>
            <title>Stories by Adamized on Medium</title>
            <link>https://medium.com/@paryagsahni2?source=rss-6ddb2c027610------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 13:05:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@paryagsahni2/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[How i Built a Deepfake Detection System with Vision Transformers]]></title>
            <link>https://medium.com/@paryagsahni2/how-i-built-a-deepfake-detection-system-with-vision-transformers-0217a6b3855c?source=rss-6ddb2c027610------2</link>
            <guid isPermaLink="false">https://medium.com/p/0217a6b3855c</guid>
            <dc:creator><![CDATA[Adamized]]></dc:creator>
            <pubDate>Thu, 04 Sep 2025 16:16:02 GMT</pubDate>
            <atom:updated>2025-09-04T16:50:38.574Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/793/0*HX2vQQOnyDh7BUPc" /></figure><h3>Introduction: From Research to Real-World Application</h3><p>A couple of months back, I co-authored a research paper on Deepfake detection with my friend for a college professor which was later accepted as a book chapter by <a href="https://www.springer.com/gp"><em>Springer Publications</em></a><em> , </em>an exciting milestone that boosted my credibility in the field. That experience inspired me to go hands-on and build a practical system around my research, turning theoretical insights into a real-world tool.</p><blockquote>My publication adds authority , check out the title page below!</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*g6rzXhPrzWqEzKOBtJYwGg.png" /></figure><h3>The Deepfake Threat: Why Detection Matters</h3><p>Deepfakes are fascinating but dangerous . Fake photos of celebrities, political leaders, or even ordinary people can go viral within minutes, damaging reputations and spreading misinformation. Unlike videos, a single manipulated image can be shared, edited, and reused endlessly across social media, making detection equally critical. So how do we fight back against these synthetic threats that can alter reality and erode trust?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kBoVSLiIIR4sPs2i.png" /></figure><h3>Why Transformers?</h3><p>Transformers revolutionized NLP with their ability to capture context using self-attention. Later, researchers applied this idea to images → Vision Transformers (ViT). Instead of scanning images like CNNs, ViT breaks an image into small patches (like puzzle pieces), treats them as a sequence, and understands global patterns with attention. This makes them powerful for detecting subtle manipulations in Deepfakes.</p><figure><img alt="A demo of a Vision Transformer for Image Classification (source)" src="https://cdn-images-1.medium.com/max/1024/0*aCn4M0a8IPKL0Xd9" /><figcaption>A demo of a Vision Transformer for Image Classification (<a href="https://arxiv.org/pdf/2010.11929">source</a>)</figcaption></figure><pre>from transformers import ViTImageProcessor, ViTForImageClassification<br>processor = ViTImageProcessor.from_pretrained(&quot;Sxhni/deepfake-detector-vit&quot;)<br>model = ViTForImageClassification.from_pretrained(&quot;Sxhni/deepfake-detector-vit&quot;)</pre><blockquote>That’s why I chose Vision Transformers — they don’t just see pixels, they understand context.</blockquote><h3>Dataset &amp; Preprocessing</h3><p>The Kaggle dataset started small (1K images). I expanded it to 76K images using oversampling and to balance Real vs. Fake and some augmentation , giving the model enough diversity to generalize. This step was crucial to ensure fair training across both classes.</p><pre>from PIL import Image<br>from torchvision import transforms<br>preprocess = transforms.Compose([<br>    transforms.Resize((224, 224)),<br>    transforms.RandomRotation(90),<br>    transforms.ToTensor(),<br>    transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])<br>])</pre><h3>Model Training with Vision Transformers</h3><p>I fine-tuned a pretrained ViT from Hugging Face. Transfer learning saved me weeks of compute while still achieving state-of-the-art accuracy. The journey was intense but rewarding!</p><pre>from transformers import TrainingArguments, Trainer<br>training_args = TrainingArguments(<br>    output_dir=&quot;./results&quot;, num_train_epochs=2, per_device_train_batch_size=32,<br>    learning_rate=1e-6, weight_decay=0.02, evaluation_strategy=&quot;epoch&quot;<br>)<br>trainer = Trainer(model=model, args=training_args, train_dataset=train_dataset, eval_dataset=eval_dataset)<br>trainer.train()</pre><blockquote>In only 2 epochs (2 hours of training), the ViT reached 99.24% accuracy on 76K images showing how powerful transfer learning can be.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*NKQeoUM_z43hnkGKXE3DIg.png" /></figure><h3>Evaluation &amp; Results</h3><p>Out of 76,161 test images, the model only misclassified ~582 , less than 1% error rate, proving its reliability. This performance showcases ViT’s strength in deepfake detection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*spV21ZXgKlLGnWcZtO-KAQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/0*PUO0EdsHXic2vJ9M" /></figure><blockquote>With 99.24% accuracy, ViT proved itself the best Deepfake guardian in my experiments.</blockquote><h3>Deployment</h3><p>Research isn’t complete until it helps people. So I built a web app, Dockerized it, and deployed on Hugging Face Spaces for easy access.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aS2d5IlLMcs37MX3" /></figure><pre>@app.route(&quot;/predict&quot;, methods=[&quot;POST&quot;])<br>def predict():<br>    file = request.files[&quot;image&quot;]<br>    img = Image.open(file.stream)<br>    inputs = processor(images=img, return_tensors=&quot;pt&quot;)<br>    outputs = model(**inputs)<br>    probs = torch.softmax(outputs.logits, dim=-1)[0].detach().numpy()<br>    pred_id = probs.argmax()<br>    return jsonify({&quot;prediction&quot;: model.config.id2label[pred_id], &quot;confidence&quot;: float(probs[pred_id])})</pre><blockquote>Anyone can try it in 5–10 seconds, no setup needed.</blockquote><h3>Future Scope &amp; Wrap-Up</h3><p>Next, I plan to explore multimodal detection — spotting audio-visual mismatches and defending against adversarial attacks. This journey, from a simple idea to a deployed app, has shown me how quickly experiments can turn into real impact</p><h3>Call to Action</h3><p><strong>Links</strong>:</p><ul><li>Live Demo: <a href="https://huggingface.co/spaces/Sxhni/deepfakedetector-vit">Hugging Face Spaces</a></li><li>Model Repository: <a href="https://huggingface.co/Sxhni/deepfake-detector-vit">Hugging Face Hub</a></li><li>Dataset Source: <a href="https://www.kaggle.com/datasets/manjilkarki/deepfake-and-real-images">Kaggle Dataset</a></li><li>GitHub Repository: <a href="https://github.com/paryagsahni1845/deepfake-detector-vit">paryagsahni1845/deepfake-detector-vit</a></li></ul><blockquote>Built with tensors, attention, and a lot of coffee ☕</blockquote><p>Thanks for sticking around till the end 🙌 If you enjoyed this, do give it a clap and share.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0217a6b3855c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My First Kaggle Submission: Cracking the Titanic Challenge with 74% Accuracy]]></title>
            <link>https://medium.com/@paryagsahni2/my-first-kaggle-submission-cracking-the-titanic-challenge-with-74-accuracy-042e21498697?source=rss-6ddb2c027610------2</link>
            <guid isPermaLink="false">https://medium.com/p/042e21498697</guid>
            <dc:creator><![CDATA[Adamized]]></dc:creator>
            <pubDate>Fri, 18 Jul 2025 10:01:12 GMT</pubDate>
            <atom:updated>2025-07-18T10:01:12.111Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/950/0*TniCAS8HlXlj-rHS" /></figure><h3><strong>Introduction</strong></h3><p>The Titanic challenge is the perfect entry point into machine learning competitions. You’re given basic passenger information — name, age, class, etc. and your task is to predict whether they survived the disaster.</p><p>I decided to take this on as my first Kaggle submission. I ended up scoring <strong>0.74641</strong> on the public leaderboard using a simple <strong>Random Forest</strong> model and learned a ton in the process.</p><p>In this blog, I’ll walk you through <strong>exactly what I did</strong>, step-by-step — from data cleaning to submission.</p><h3>Step 1: Loading the Data</h3><p>Kaggle provides train.csv and test.csv. The train set includes the target (Survived) and the test set is what we predict on.</p><pre>import pandas as pd<br>import numpy as np<br>import matplotlib.pyplot as plt<br>import seaborn as sns<br># To ignore warnings<br>import warnings<br>warnings.filterwarnings(&#39;ignore&#39;)<br><br># Load training and test datasets<br>train = pd.read_csv(&#39;/kaggle/input/titanic/train.csv&#39;)<br>test = pd.read_csv(&#39;/kaggle/input/titanic/test.csv&#39;)<br><br># Show first 5 rows of training data<br>train.head()</pre><h3>Step 2: Exploring &amp; Cleaning the Data</h3><p>I first explored the dataset using train.info() and visualized missing values with a heatmap using Seaborn.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/0*u3TCFIZav_8_pOOE.png" /></figure><p><strong>Key missing values found:</strong></p><ul><li>Age: some missing values → filled with median</li><li>Embarked: 2 missing → filled with mode</li><li>Cabin: heavily missing → dropped</li></ul><pre># Fill missing Age with median (numerical)<br>train[&#39;Age&#39;].fillna(train[&#39;Age&#39;].median(), inplace=True)<br>test[&#39;Age&#39;].fillna(test[&#39;Age&#39;].median(), inplace=True)<br><br># Fill missing Embarked with mode (categorical)<br>train[&#39;Embarked&#39;].fillna(train[&#39;Embarked&#39;].mode()[0], inplace=True)<br><br># Fill missing Fare in test set with median<br>test[&#39;Fare&#39;].fillna(test[&#39;Fare&#39;].median(), inplace=True)<br><br># Drop Cabin column (too many missing values)<br>train.drop(columns=[&#39;Cabin&#39;], inplace=True)<br>test.drop(columns=[&#39;Cabin&#39;], inplace=True)</pre><h3>Step 3: Feature Engineering</h3><p>This is where you turn domain knowledge into features. I engineered:</p><ul><li><strong>FamilySize</strong> = SibSp + Parch + 1</li><li><strong>IsAlone</strong> = 1 if FamilySize == 1</li><li><strong>Title</strong> = extracted from Name (Mr, Miss, etc.)</li></ul><p>Then grouped rare titles to reduce noise.</p><pre># Create new feature: FamilySize<br>train[&#39;FamilySize&#39;] = train[&#39;SibSp&#39;] + train[&#39;Parch&#39;] + 1<br>test[&#39;FamilySize&#39;] = test[&#39;SibSp&#39;] + test[&#39;Parch&#39;] + 1<br><br># Create new feature: IsAlone<br>train[&#39;IsAlone&#39;] = (train[&#39;FamilySize&#39;] == 1).astype(int)<br>test[&#39;IsAlone&#39;] = (test[&#39;FamilySize&#39;] == 1).astype(int)<br><br># Extract Title from Name (e.g., Mr, Miss, etc.)<br>train[&#39;Title&#39;] = train[&#39;Name&#39;].str.extract(&#39; ([A-Za-z]+)\.&#39;, expand=False)<br>test[&#39;Title&#39;] = test[&#39;Name&#39;].str.extract(&#39; ([A-Za-z]+)\.&#39;, expand=False)<br><br># Simplify rare titles<br>for df in [train, test]:<br>    df[&#39;Title&#39;] = df[&#39;Title&#39;].replace([&#39;Lady&#39;, &#39;Countess&#39;, &#39;Capt&#39;, &#39;Col&#39;, &#39;Don&#39;, &#39;Dr&#39;,<br>                                       &#39;Major&#39;, &#39;Rev&#39;, &#39;Sir&#39;, &#39;Jonkheer&#39;, &#39;Dona&#39;], &#39;Rare&#39;)<br>    df[&#39;Title&#39;] = df[&#39;Title&#39;].replace([&#39;Mlle&#39;, &#39;Ms&#39;], &#39;Miss&#39;)<br>    df[&#39;Title&#39;] = df[&#39;Title&#39;].replace(&#39;Mme&#39;, &#39;Mrs&#39;)</pre><h3>Step 4: Encoding Categorical Data</h3><p>Machine learning models can’t work with strings — I used:</p><ul><li>map() to convert Sex to 0/1</li><li>get_dummies() for one-hot encoding Embarked and Title</li></ul><pre># Convert categorical columns to numeric using map() and get_dummies()<br>train[&#39;Sex&#39;] = train[&#39;Sex&#39;].map({&#39;male&#39;: 0, &#39;female&#39;: 1})<br>test[&#39;Sex&#39;] = test[&#39;Sex&#39;].map({&#39;male&#39;: 0, &#39;female&#39;: 1})<br><br>train = pd.get_dummies(train, columns=[&#39;Embarked&#39;, &#39;Title&#39;], drop_first=True)<br>test = pd.get_dummies(test, columns=[&#39;Embarked&#39;, &#39;Title&#39;], drop_first=True)</pre><h3>Step 5: Selecting Features</h3><p>I removed irrelevant or redundant columns:</p><ul><li>PassengerId, Name, Ticket, Cabin<br> And kept engineered features + numerics for training.</li></ul><pre># Define the target variable<br>y = train[&#39;Survived&#39;]<br><br># Drop columns we won&#39;t use for training<br>X = train.drop([&#39;PassengerId&#39;, &#39;Survived&#39;, &#39;Name&#39;, &#39;Ticket&#39;], axis=1)<br><br># Save PassengerId for the test set (needed for submission)<br>test_passenger_id = test[&#39;PassengerId&#39;]<br>X_test = test.drop([&#39;PassengerId&#39;, &#39;Name&#39;, &#39;Ticket&#39;], axis=1)</pre><h3>Step 6: Training the Random Forest</h3><p>Why Random Forest?</p><ul><li>Works well with tabular data</li><li>Handles missing values and outliers decently</li><li>No need for heavy preprocessing</li></ul><p>I split the data (80/20), trained the model, and got validation accuracy.</p><pre>from sklearn.ensemble import RandomForestClassifier<br>from sklearn.model_selection import train_test_split<br>from sklearn.metrics import accuracy_score<br><br># Split training data for evaluation (80% train, 20% validation)<br>X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2, random_state=42)<br><br># Initialize the RandomForest model<br>model = RandomForestClassifier(random_state=42)<br><br># Train the model<br>model.fit(X_train, y_train)<br><br># Predict on validation set<br>y_pred = model.predict(X_val)<br><br># Evaluate model accuracy<br>accuracy = accuracy_score(y_val, y_pred)<br>print(f&quot;Validation Accuracy: {accuracy:.4f}&quot;)</pre><p><strong>Validation Accuracy</strong>: ~0.81</p><p><strong>Kaggle Public Score</strong>: <strong>0.74641</strong></p><h3>What I Learned</h3><ul><li>How to clean and prepare structured data</li><li>Feature engineering matters a lot more than just choosing fancy models</li><li>Random Forest gives great results out of the box</li><li>Kaggle’s Titanic challenge is a fun &amp; confidence-boosting first project</li></ul><h3>What’s Next?</h3><ul><li>Try <strong>XGBoost</strong> or <strong>LightGBM</strong> for boosting accuracy</li><li>Add <strong>cross-validation</strong> for better generalization</li><li>Tune <strong>hyperparameters</strong> (like n_estimators, max_depth)</li><li>Publish more blogs like this 😉</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=042e21498697" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>