<?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 Immanuel Leon Salomo Sihombing on Medium]]></title>
        <description><![CDATA[Stories by Immanuel Leon Salomo Sihombing on Medium]]></description>
        <link>https://medium.com/@immanuel.leonsalomo?source=rss-9dea919fae51------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wkMtPQNFdXsuEa_tZvm3KQ.jpeg</url>
            <title>Stories by Immanuel Leon Salomo Sihombing on Medium</title>
            <link>https://medium.com/@immanuel.leonsalomo?source=rss-9dea919fae51------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 11:59:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@immanuel.leonsalomo/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[Understanding BERT Tokenizers: The Basics of WordPiece Tokenization and Its Role in Text Processing]]></title>
            <link>https://medium.com/@immanuel.leonsalomo/understanding-bert-tokenizers-the-basics-of-wordpiece-tokenization-and-its-role-in-text-processing-e7abbbe0dbb1?source=rss-9dea919fae51------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7abbbe0dbb1</guid>
            <category><![CDATA[bert]]></category>
            <category><![CDATA[tokenizer]]></category>
            <category><![CDATA[sentiment-analysis]]></category>
            <category><![CDATA[wordpiece]]></category>
            <dc:creator><![CDATA[Immanuel Leon Salomo Sihombing]]></dc:creator>
            <pubDate>Fri, 25 Jul 2025 08:49:31 GMT</pubDate>
            <atom:updated>2025-07-25T08:49:31.769Z</atom:updated>
            <content:encoded><![CDATA[<h3>BERT <strong>Pre-Training</strong> Phase:</h3><p>The BERT (Bidirectional Encoder Representations from Transformers) model is a transformer model that was first introduced by Google AI in 2018 by Devlin et al.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1ar-GXZNjip84g8Y6290rg.png" /><figcaption>The picture of BERT Paper by Devlin et. al from arxiv</figcaption></figure><p>The BERT model differs from previous text processing models in that it is capable of reading in two directions (bidirectional), rather than just left to right like GPT.</p><p>It is an unsupervised pre-trained model that is trained to perform two main tasks: Masked Language Modeling (MLM) and Next Sentence Prediction (NSP).</p><h4>Masked Language Modeling (MLM)</h4><p>A number of tokens in the sentence are masked (replaced with <strong>[MASK]</strong>).</p><p>The model is trained to predict the missing tokens based on the context to the left and right.</p><p>Example :</p><p>Given the sentence “The man went to the store to buy milk.”, suppose the word “store” is selected to be masked during the pre-training process. And the model trained using this following data :</p><blockquote>Input: “The man went to the [MASK] to buy milk.”<br>Target/label: “store”</blockquote><h4>Next Sentence Prediction (NSP)</h4><p>Given two sentences, the model guesses whether the second sentence is a continuation of the first sentence.</p><p>Example :</p><blockquote>Sentence A: “She opened the door.”<br>Sentence B: “The cat ran out.”<br>Label: IsNext</blockquote><blockquote>Sentence A = “He spent the entire weekend fixing his car engine.”</blockquote><blockquote>Sentence B = “Mount Everest is the highest mountain in the world.”</blockquote><p>Label = IsNotNext</p><blockquote>➡️ Sentence B is not related to A, so it is labeled ‘IsNotNext’. In the previous example, Sentence B is related to A, so it is labeled ‘IsNext’. BERT is trained to recognize the difference between natural and unnatural continuations</blockquote><h4>BERT for Sentiment Analysis (Specific Tasks (Fine-Tune))</h4><p>In this case, we see that BERT was initially pre-trained to perform two main tasks: predicting masked or empty words or selecting suitable words to insert (MLM), and predicting suitable words to appear next (NSP).</p><p>But the question that might arise is “<strong>how a pre-trained model that was not initially trained to perform tasks such as sentiment analysis can perform such tasks”</strong>.<br>The <strong>answer lies in ‘fine-tuning.’ </strong>The <strong>BERT model will be fine-tuned using a sentiment analysis dataset that already has labels</strong>, where the existing <strong>BERT parameters will be adjusted (fine-tuned)</strong> to perform the new task of sentiment analysis.</p><blockquote>The<strong> process in Fine-tune (Sentiment Analysis)</strong> is as follows:<br>1. Pre-trained BERT model -&gt;<strong> given an “additional layer” </strong>(e.g., linear classification layer).<br>2. BERT model <strong>trained with labeled dataset</strong> (e.g., positive, negative, neutral)<br>3. Finally, <strong>all BERT parameters are fine-tuned</strong> based on the<strong> new task</strong>.</blockquote><h4>The Role of Tokenizers in Pre-training</h4><p>Before the pre-training process begins, text in sentence form cannot be directly understood by the BERT model. Therefore:</p><p>The text must be <strong>broken down into tokens</strong>.</p><p>Tokens are<strong> converted into numbers (IDs)</strong> through vocab.</p><p>BERT <strong>uses the WordPiece tokenizer</strong> for this process because:</p><p>Vocabulary size can be controlled (around 30,000 tokens).</p><p>It can<strong> avoid OOV by breaking words</strong> into subwords.</p><p>It is flexible in handling new or uncommon words.</p><h4>How is the BERT Tokenizer Trained?</h4><p>-&gt; <strong>Dataset :</strong><br>WordPiece BERT tokenizer was trained using a massive corpus, namely:</p><p><strong>BooksCorpus</strong> <strong>(800M words)</strong></p><p><strong>English Wikipedia (2.5B words)</strong></p><p>-&gt;<strong> Tokenizer Training Process :</strong><br>Initial tokenization: using whitespace and punctuation marks.</p><p><strong>Compilation of n-gram frequencies</strong>: word segments are counted by frequency.</p><p><strong>Merging process</strong>: <strong>‘frequently’</strong> co-occurring token units are <strong>merged.</strong></p><p>Merge rules are stored as the tokenizer model.</p><p>Final result: the WordPiece vocabulary is constructed and ready for use.</p><p>Example:</p><blockquote>“<strong>playing</strong>” → [‘play’, ‘##ing’]</blockquote><blockquote>“<strong>unfamiliar</strong>” → [‘un’, ‘##fam’, ‘##iliar’]</blockquote><h4>When is WordPiece used in BERT?</h4><p><strong>Each time the model receives input</strong>, it goes through these stages:</p><p>Sentences are <strong>converted → tokens (WordPiece)</strong></p><p>Tokens are<strong> converted → numeric IDs (input_ids)</strong></p><p>The <strong>model receives input_ids and attention_mask</strong></p><p>The<strong> inference/training process is performed</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*ny2DoiYC3n86USL2aBTCkg.png" /><figcaption>The picture of WordPiece Tokenizer</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7abbbe0dbb1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Developed LLM-based chat-bot for instagram that runs locally]]></title>
            <link>https://medium.com/@immanuel.leonsalomo/developed-llm-based-chat-bot-for-instagram-that-runs-locally-4aaa0b6f864a?source=rss-9dea919fae51------2</link>
            <guid isPermaLink="false">https://medium.com/p/4aaa0b6f864a</guid>
            <category><![CDATA[llm-applications]]></category>
            <category><![CDATA[rags]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[retrieval-augmented-gen]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Immanuel Leon Salomo Sihombing]]></dc:creator>
            <pubDate>Tue, 22 Jul 2025 04:38:52 GMT</pubDate>
            <atom:updated>2025-07-22T04:38:52.361Z</atom:updated>
            <content:encoded><![CDATA[<p>When talking about recent developments in AI, most people nowadays will immediately mention LLMs (Large Language Models) like ChatGPT. With their benefits and significant role in supporting our daily productivity, from students who need help summarizing lessons, finding explanations for topics that are hard to research manually, employees needing assistance writing emails or proposals, to even asking for information or regulations that are often difficult to access or understand through regular browsing — LLMs have proven to be incredibly useful.</p><p>One of the most relevant AI development trends I’ve seen on social media, shared by someone experienced in this field (Edward S Honour, CEO of ‘Kinetic Seas’), is the use of <strong>supervised fine-tuning</strong> and <strong>Retrieval Augmented Generation (RAG)</strong>. This approach allows us to make AI systems work in a specific and customized way based on the tasks and resources we provide. It’s a game-changer in helping individuals or organizations accomplish their goals, whether it’s for information search or creating something meaningful.</p><p><a href="https://www.instagram.com/reel/DImGEdCO1-W/?utm_source=ig_web_copy_link&amp;igsh=MzRlODBiNWFlZA==">https://www.instagram.com/reel/DImGEdCO1-W/?utm_source=ig_web_copy_link&amp;igsh=MzRlODBiNWFlZA==</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Os5nq_WP4py0VVH8gkxCSA.png" /><figcaption>Picture of the instagram account of Edward S Honour <a href="https://medium.com/u/59fe665befa8">Edward Honour</a></figcaption></figure><p>Just imagine a large company that already has tons of documents covering rules A to Z — governing various stages of internal processes and serving as guidelines for employees. Now, things get really complicated when someone has to manually read through all of those documents, page by page, often with dense and unstructured language that’s hard to digest. This is exactly where <strong>Retrieval Augmented Generation (RAG)</strong> comes to the rescue — by using an LLM system to extract and summarize specific information from the documents we already own.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W5Ym4RGtkrYfh81TYukFpA.png" /><figcaption>Picture of RAG system visualization from ‘MarkovML’</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PQwShzGmVqH9e3-vTNvdRw.png" /><figcaption>Illustration Picture of how RAG works from ‘Pinecone’</figcaption></figure><p>A real-life example would be documents from institutions like <strong>Bank Indonesia</strong> or <strong>OJK (Indonesia Financial Services Authority)</strong> that explain how to exchange currency, register financial instruments, and so on. Of course, they have official documentation or guidelines outlining the steps and rules to follow — but someone who needs that information could easily get overwhelmed or confused, wasting a lot of time trying to search for it online or scanning PDFs without clear direction. And if they’re not focused, it could even lead to misinterpretation. This is where a RAG system steps in. By feeding it our documents (e.g., PDFs), going through processes like chunking, embedding, and storing in a <strong>vector database</strong>, the LLM can retrieve concise summaries or direct answers to the questions we ask — based on the exact content we own.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*9eqiEz4JoKcAmUxx4cEy1w.png" /><figcaption>The Picture of where i test (Postman) the system to answer based on the<strong> “Panduan_Pintar_BI.pdf” public document</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wL0jICRaDTrTpGMZj3fHng.png" /><figcaption>The picture of the document of<strong> “Panduan_Pintar_BI.pdf” </strong>that <strong>contain the information/answer</strong> about that question</figcaption></figure><h3>Tech Stack :</h3><ul><li><strong>LLM</strong>: ‘<strong>Mistral’</strong>(running locally with Ollama)</li><li><strong>PDF Loader</strong>: PyMuPDF, LlamaIndex</li><li><strong>Vector Store</strong>: ChromaDB</li><li><strong>Embedding Model</strong>: all-MiniLM-L6-v2 via SentenceTransformers</li><li><strong>Frameworks</strong>: LlamaIndex</li><li><strong>Backend : </strong>FastAPI</li><li><strong>In-memory database :</strong> Redis</li><li><strong>Relational Database :</strong> Sqlite</li><li><strong>Programming Language</strong>: Python</li><li><strong>Instagram Integration</strong>: <a href="https://github.com/adw0rd/instagrapi">instagrapi</a> – used to fetch and reply to Instagram DMs via automation</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*TsthD75z1Ygy6DDoK3dfKw.png" /><figcaption>The picture of my Chat-Bot Tools/Techs<strong> Architecture</strong></figcaption></figure><h4>📱Instagram DM Automation</h4><p>To make the RAG system accessible through a familiar interface, I integrated Instagram using the instagrapi Python client. This allows the system to:</p><ul><li><strong>Automatically log in </strong>to my Instagram account</li><li><strong>Listen to Direct Messages (DMs)</strong> from users</li><li><strong>Send user queries to the RAG pipeline</strong> (PDF + ChromaDB + Mistral)</li><li><strong>Return the answer</strong> via DM</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vgcZrcR08PyluSboDK58-w.png" /><figcaption>The picture of <strong>Python Library ‘instagrapi’ </strong>from Github</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6xxHKLArq1NW_spw_3XrBg.png" /><figcaption>Picture of the libraries that i import in the ‘instagram_service.py’</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kcdyNtj_StpXtwr7zYR3Hw.png" /><figcaption>The picture of the ‘Persistent Instagram Login with Session File’</figcaption></figure><p>*To avoid logging in every time, the script checks for a saved session file. If not found, it logs in and stores the session securely.</p><p>*This function ensures that login to Instagram is reused across runs by saving and loading a session file using pickle.</p><h4>📄 Step-by-Step Implementation</h4><p>🔧 Step 1: Install Required Packages</p><p>Make sure to install the following Python libraries before starting:</p><p><strong>‘pip install llama-index chromadb sentence-transformers’</strong></p><p>Also install and run your Ollama model locally:</p><p><strong>‘ollama run mistral’</strong></p><ul><li>make sure ollama already installed on your device :</li></ul><p><a href="https://ollama.com/download/windows">Download Ollama on Windows</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/1*XSPJKk86NgQlszQARBfV4A.png" /><figcaption>The ‘requierements.txt’ (all the tools or libraries that was installed)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-ivgZQv7xFBjvfdSljDDUA.png" /><figcaption>The libraries that i import from the ‘llm_service.py’</figcaption></figure><p>📁 Step 2: Prepare Your Documents</p><p>I Place my documents text, PDF files in a folder called data/docs-bot/.<br> These documents will be loaded and indexed to support semantic search and Q&amp;A.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FwFMfrQ_jYvHeThoWhyeJQ.png" /><figcaption>Picture of the <strong>documents or files in .pdf format</strong> that i am using <strong>related to BI and OJK</strong></figcaption></figure><p><a href="https://www.bi.go.id/id/publikasi/ruang-media/news-release/Documents/sp_249622_Panduan-PINTAR.pdf">sp_249622_Panduan-PINTAR.pdf</a></p><p><a href="https://www.academia.edu/9341004/Strategi_Nasional_Literasi_Keuangan_Indonesia">(PDF) Strategi Nasional Literasi Keuangan Indonesia</a></p><p><a href="https://shorturl.at/DeKyo">https://shorturl.at/DeKyo</a></p><p>⚙️ Step 3: Initialize Core Components</p><p>We configure the core components for our LLM pipeline:</p><ul><li><strong>LLM</strong>: Ollama running mistral locally</li><li><strong>Embedding Model</strong>: sentence-transformers/all-MiniLM-L6-v2</li><li><strong>Text Splitter</strong>: Sentence-level chunking</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gu5Ji8SxRTHmvEjrmi6yxA.png" /><figcaption>The picture of the <strong>‘core components’ </strong>that was used in this RAG System [Text Splitter-&gt;Embedding Model-&gt;LLM ]</figcaption></figure><p>🛠️ Step 4: Apply Global Settings</p><p>LlamaIndex allows you to set these components globally using Settings:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/1*netg60_C3PK-gmhDpILR1Q.png" /><figcaption>The picture of Global configuration for LLM, embedding model, and text splitter.”</figcaption></figure><p>🗃️ Step 5: Build the Vector Store with ChromaDB</p><p>I am using the chromadb.PersistentClient to persist the vector index locally.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZWTBEsH5cnUVZlHdezCrCA.png" /><figcaption>The picture of Initializing or retrieving the vector store collection in ChromaDB</figcaption></figure><p>🧱 Step 6: Create the Index</p><p>Load your documents and build the vector index from them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H2Kh_GUWjgtq1yXupHmBLA.png" /><figcaption>Reading documents from the ‘data/docs-bot’ directory for further processing.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*h3vIycvnUZoWCeDKtnHUtA.png" /><figcaption>Building a searchable vector index from loaded documents using Chroma as the vector store</figcaption></figure><p>🔍 Step 7: Run Queries Against the Index</p><p>Now that the<strong> index is built</strong>, use the query engine to <strong>ask natural language questions</strong> and <strong>retrieve relevant answers based on your documents</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/869/1*mOdS6ebuJnvKXQce59beJw.png" /><figcaption>Main function to handle user queries by passing them to the LLM through a query engine.</figcaption></figure><h3>✅ Final Output</h3><p>The function get_llm_response(&quot;...&quot;) lets you send natural language questions to your locally indexed documents and receive intelligent responses from your local LLM (mistral via Ollama).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*HN3kwxpwLsYhQ3YAp4WK-Q.jpeg" /><figcaption>The Picture of where the <strong>Chat-Bot System already integrated to Instagram Account</strong> and answer the DM questions based on the related documents of context (RAG)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nJI7E37g4xTRlfmkADfs7Q.png" /><figcaption>The source of context from the Bank of Indonesia<strong> Document that answer the above question</strong></figcaption></figure><p>📄This Project Repo : <a href="https://github.com/LeonsMetanoia/bot-pintarFinansial">LeonsMetanoia/bot-pintarFinansial</a></p><p>🔗My LinkedIn : <a href="https://www.linkedin.com/in/immanuel-leon-salomo-636763251/">Immanuel Leon Salomo | LinkedIn</a></p><p>🐈‍⬛My Github : <a href="https://github.com/LeonsMetanoia">https://github.com/LeonsMetanoia</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4aaa0b6f864a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a simple Local Chat-Bot UI with LLM integration — My Beginner Project]]></title>
            <link>https://medium.com/@immanuel.leonsalomo/building-a-simple-local-chat-bot-ui-with-llm-integration-my-beginner-project-58bf77b64715?source=rss-9dea919fae51------2</link>
            <guid isPermaLink="false">https://medium.com/p/58bf77b64715</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[llama-cpp]]></category>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[tinyllama]]></category>
            <dc:creator><![CDATA[Immanuel Leon Salomo Sihombing]]></dc:creator>
            <pubDate>Fri, 11 Jul 2025 07:52:04 GMT</pubDate>
            <atom:updated>2025-07-11T07:52:04.709Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a simple Local Chat-Bot UI with LLM integration — My Beginner Project</h3><h3>Introduction</h3><p>Right now, I am a Data Scientist intern at a company that operates in the ICT (Information and Communication Technology) field, delivering end-to-end digital development — such as internet development (Wi-Fi services (ICONNET)), application digitalization, and electric vehicles (Charging Port, Battery, B2B Vehicles Rent) (PLN Icon Plus).</p><p>And as an intern at a tech company like this in the 2025 era, you’ll always hear the word <strong>“AI” </strong>in any meeting or just normal everyday conversations. As we all know, the most popular form of AI right now is related to <strong>LLMs</strong> (like ChatGPT, Gemini, DeepSeek, etc.), and that really pushes me to start learning through experience — by building a simple chatbot integrated with an LLM model.</p><p>I believe the best way of learning is by <strong>jumping straight into the process of confusion and hard work</strong>, and this simple project might lead me — and maybe you too — to a big step in the world of <strong>Artificial Intelligence</strong>.</p><p>In this case, I want to show my progress from scratch in building this simple chatbot with LLM integration.</p><p>I wanted to explore how to build the UI from a frontend language, so I’m using <strong>React</strong> in this case to build a responsive UI frontend — with a little help from <strong>ChatGPT</strong> in generating some of the code for me :)</p><p>For the backend, I’m using <strong>FastAPI</strong>, which is a very efficient framework for building APIs (Application Programming Interfaces). By using FastAPI with Python, I can connect the LLM response for user questions from the backend endpoint to the user interface smoothly.</p><p>The LLM model I’m using in this part is a small model that I accessed from the Hugging Face platform: <strong>“TinyLlama-1.1B-Chat-v1.0.Q4_K_M.gguf”</strong>.</p><p><a href="https://huggingface.co/TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF">TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF · Hugging Face</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rwv7XJ3445RtPGmVk4gvEA.png" /><figcaption>Picture from Hugging Face “TinyLlama-1.1B-Chat-v1.0-GGUF”</figcaption></figure><p>This is a <strong>quantized</strong> or smaller version of the TinyLLaMA model — it only has <strong>1.1 billion parameters</strong>, which is <em>much</em> smaller compared to models like ChatGPT (<strong>175 billion parameters</strong>) or LLaMA-2 (<strong>7+ billion parameters</strong>).</p><p>The model is wrapped in <strong>.gguf (GGML Universal Format)</strong>, which makes it possible to run the LLM <strong>locally</strong> and efficiently — no need for a powerful device or GPU. It runs fast on the backend using <strong>llama.cpp</strong>, and yes, it can run on <strong>CPU only</strong>.</p><h3>Tech Stack :</h3><p>List of the tools/libraries:</p><ul><li><strong>FrontEnd</strong> : <strong>React</strong>(Vite)</li><li><strong>Backend (Communication)</strong> : REST API using <strong>FastAPI</strong> (localhost)</li><li><strong>Backend (LLM)</strong> : <strong>TinyLlama</strong> via llama.cpp</li></ul><h3><strong>The Flowchart :</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/142/1*DcQxB3HGxNeBlLwtcGEwag.jpeg" /><figcaption>The <strong>Flowchart</strong> of how the Chat-Bot work technically</figcaption></figure><h3>How it works :</h3><ol><li>The user types a message in the chat box (UI) to ask about anything</li><li>The question is sent to the system (backend)</li><li>The backend processes the user’s question and includes it as part of the prompt that will be processed by the LLM (TinyLLaMA)</li><li>The LLM (TinyLLaMA) processes the prompt and generates a response</li><li>The response is then sent back and displayed in the chat box on the UI frontend</li></ol><p>*just ignore the word “colorful” below, i ask claude AI to help me with creating the “colorful” UI for this chat bot, but turns out i still not able to figure this out why it’s still black and white :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zVnSq3QOZO_L7dcEUgQ8aA.png" /><figcaption>Picture from the UI of this Simple Chat-Bot with LLM Intergration (TinyLlama)</figcaption></figure><h3>How it works (*more technical way) :</h3><h4>Frontend (React): Where the User Interacts</h4><ul><li>User types a question in the chat input box.</li><li>After that that input is stored in state (<strong>useState</strong>) and shown in the chat bubble UI</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wz6w3frapcJ7q2PgZIXwUw.png" /><figcaption>The Picture of ‘useState’ part of code for shown the user chat in the UI</figcaption></figure><ul><li>Then, the <strong>sendMessage</strong> function triggers a <strong>POST request </strong>to the backend endpoint (http://localhost:8000/chat) with the message as <strong>JSON</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1sU-yB_U5MJ5yDav0i-t4g.png" /><figcaption>The Picture of ‘senMessage’ part of code request to backend local endpoint</figcaption></figure><ul><li>While the model processes the input, there’s a <strong>“typing…” animation</strong> shown to simulate response delay.</li><li>When the response comes back, it’s displayed as a chat bubble in the conversation thread.</li></ul><h4>Backend (FastAPI + llama.cpp): The Brain of the System</h4><ul><li>The backend receives the user message via the /chat POST endpoint, using the Message schema.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fRym33i88xWOpBXWHHiNug.png" /><figcaption>The Picture of code where the backend receives the user message</figcaption></figure><ul><li>The message is then embedded in a <strong>prompt template</strong>, like this:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gu9LER0IqREaiIGWzoFGZw.png" /><figcaption>The Picture of the prompt template</figcaption></figure><p>The prompt format follows the chat-style that expected by the models trained with conversational fine-tuning.</p><p>This prompt tells the model : “Here’s what the user said, now it’s your turn to answer”</p><ul><li>The prompt is sent into the llm() call using the llama_cpp Python binding, which runs the <strong>TinyLLaMA-1.1B-Chat-v1.0.Q4_K_M.gguf</strong> model locally — even without a GPU.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4sLA6bsbzriUXSCX3TNi_A.png" /><figcaption>The Picture of the prompt sent into the llm() call</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YNC6UqMMT7T8pZA06u0rJA.png" /><figcaption>The Picture of Llama model initialization</figcaption></figure><ul><li>After that the input was processed by the model and returns a raw output (a dictionary with token results)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*LEjkbpkxoUSolHWSDs8bQQ.png" /><figcaption>The Picture of the raw output</figcaption></figure><ul><li>The raw model output is <strong>cleaned</strong> from tags or unnecessary noise using regex, then returned to the frontend in a structured format like:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*irGGTdPYc40pJDAQ39x1Xw.png" /><figcaption>The Picture of where the raw output is cleaned</figcaption></figure><h3><strong>Challenges I Faced :</strong></h3><p>→ As a beginner, I faced a lot of technical problems — even during the initial setup of the project. I was confused about <strong>where to create the file structure</strong>, what folders or files to include, and how to organize everything properly.</p><p>→ By using <strong>ChatGPT</strong> to ask where and what to build in the project structure, I got a lot of help. It really guided me step-by-step in the process.</p><p>→ The next challenge I faced was when the <strong>frontend couldn’t connect to the backend</strong>. I had no idea what was wrong, and in order to debug this, I also had to ask ChatGPT to help me fix both my frontend code (App.jsx) and my backend (main.py).</p><p>→ Another issue I ran into was when <strong>llama.cpp didn’t work</strong> as expected. It turns out I hadn’t installed it correctly — I had to install it via pip in the virtual environment first. That part was tricky at first, but I managed to solve it with a bit of trial and error (and again, ChatGPT&#39;s help).</p><h3>Things that i learned from building this simple project :</h3><h4>Non-technical :</h4><p>→ Just do the thing that you really think is right and a priority at that moment. <strong>Don’t wait until the “right time” — because anytime is the right time to start.</strong></p><p>→ <strong>Don’t give up</strong> when you run into errors or bugs. There are so many resources on the internet today that can help you (especially in this era of AI — tools like ChatGPT are very helpful).</p><p>→ Try to <strong>divide the problems into smaller parts</strong>, like document chunking in RAG (something I’m also planning to explore later). Take it step by step, and solve it patiently.</p><p>→ <strong>Don’t hesitate to ask</strong> anyone you think could help. Sometimes a quick question can save hours of struggling.</p><h4>Technical :</h4><p>→ I just figured out that there are a lot of backend frameworks that can be used for building projects like this — such as <strong>FastAPI, Flask, Node.js, Django, Go</strong>, etc. In this case, I chose <strong>FastAPI</strong> because it’s an efficient and lightweight backend framework that fits perfectly for a small project like this.</p><p>→ The use of <strong>LLMs</strong> for development or research can actually be done <strong>locally</strong>, as long as you choose a model that fits your device’s resources. There are many options out there, like <strong>TinyLLaMA, Gemini, Mistral, DeepSeek</strong>, etc.</p><p>→ This project is a simple LLM integration that <strong>doesn’t use frameworks</strong> like <strong>Langchain, LlamaIndex, or SmolAI Agents</strong> — which are more commonly used when you want to build more specific applications, like <strong>RAG (Retrieval Augmented Generation)</strong> using your own documents or databases, often combined with <strong>vector databases</strong>.</p><p>→ I also realized that the <strong>UI or frontend part</strong> is actually really interesting to learn. There’s a lot of creativity and logic that goes into building a clean, responsive, and user-friendly interface — and yes, it’s <strong>very possible to learn and understand it</strong>, even as a backend- or AI-focused developer.</p><p>→ If you want to run something in Python with isolated dependencies, it’s <strong>highly recommended to use a virtual environment</strong>. That way, the packages or libraries you install won’t collide with global ones and won’t mess up other projects.</p><p>→ It’s also important to understand the backend part properly — especially <strong>how to set up APIs (Application Programming Interfaces)</strong> so that your backend can connect smoothly with the frontend.</p><p>→ I also started using <strong>GitHub</strong> to document and manage version control for my code. This helps a lot in tracking changes and continuing development. (Though I still need more experience with the branching system — like push, pull, merge, etc. — but I’m on it!)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*970AYCTy0mX9uE9SPnGYQw.png" /><figcaption>The Picture of the Simple Chat-Bot with Tinyllama Integration</figcaption></figure><h4>Github Link :</h4><p><a href="https://github.com/LeonsMetanoia/Simple-Chat-Bot---LLM-Integration---Tiny-LLMA-1.1B-Chat-v1-/blob/main/backend/main.py">Simple-Chat-Bot — -LLM-Integration — -Tiny-LLMA-1.1B-Chat-v1-/backend/main.py at main · LeonsMetanoia/Simple-Chat-Bot — -LLM-Integration — -Tiny-LLMA-1.1B-Chat-v1-</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=58bf77b64715" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Battle of Models: DistilBERT vs. Bi-GRU in Indonesian Sentiment Analysis]]></title>
            <link>https://medium.com/@immanuel.leonsalomo/battle-of-models-distilbert-vs-bi-gru-in-indonesian-sentiment-analysis-f5cd878ba216?source=rss-9dea919fae51------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5cd878ba216</guid>
            <category><![CDATA[transformer-model]]></category>
            <category><![CDATA[natural-language-processi]]></category>
            <category><![CDATA[rnn-architecture]]></category>
            <category><![CDATA[sentiment-analysis]]></category>
            <category><![CDATA[naturallanguageprocessing]]></category>
            <dc:creator><![CDATA[Immanuel Leon Salomo Sihombing]]></dc:creator>
            <pubDate>Mon, 23 Jun 2025 09:28:52 GMT</pubDate>
            <atom:updated>2025-06-23T09:28:52.227Z</atom:updated>
            <content:encoded><![CDATA[<h3>DistilBERT vs. Bi-GRU Who’s better at Sentiment Analysis</h3><blockquote>Context vs. Sequence: Who Wins the Sentiment Analysis Showdown?</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yBIpQ6n1bRdTJto71x9wMw.jpeg" /><figcaption>Photo by <strong>Bekky Bekks</strong> (Unsplash)</figcaption></figure><p>In this era where social media has become something we simply can’t separate from our lives, all kinds of content — videos, images, and especially <em>comments</em> — are shared by people from all over the world.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2BPsTy3iSnYTLMTLcvvkrg.jpeg" /><figcaption>Photo by<strong> Mariia Shalabaieva</strong> (Unsplash)</figcaption></figure><p>Sometimes we come across someone posting a video of themselves doing something <strong>“stupid”</strong> or unusual, and then that video goes <strong>viral</strong>. Of course, the comment section starts blowing up, and people begin tearing them down with their words. Sure, it’s good when people share their opinions and even give advice — but it can quickly turn into something else entirely: <strong>insults</strong>, <strong>mockery</strong>, and <strong>humiliation</strong>.</p><p>On TikTok, for example, you might see someone just casually posting a video of their daily life. Then suddenly, people start <em>commenting</em> on their physical appearance or even making racist remarks. That kind of thing becomes disturbing, especially for those who try to stay open-minded and think positively. Seeing hate like that makes you realize it could lead to serious long-term impacts if it’s left unchecked.</p><p>I once watched a live video of someone just selling stuff online. But in the live comment section, people started attacking him — mocking his religion, tribe, and skin color. That moment really made me think: if things like this aren’t handled properly, they can seriously affect someone’s mental health — especially the person being targeted by the hate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*93VQV6kbKSQ-1Mt9dLq9aw.jpeg" /><figcaption>Photo by<strong> Glenn Carrie </strong>(Unsplash)</figcaption></figure><p>This is where Sentiment Analysis using NLP (Natural Language Processing) can play an important role — filtering which comments deserve to be heard, and which ones are better left unsaid.</p><h3>Natural Language Processing</h3><p>Natural Language Processing (NLP) is a technique that bridges the interaction between computers and human language. The main goal is to enable machines to understand, analyze, and even represent human language in a meaningful way.</p><p>With NLP, we can build high-performing models that extract relevant features from large and complex text data. It helps systems understand the context, relationships, and meaning behind the words in a sentence — allowing them to pull out important information from narrative-style data like product reviews, social media comments, chat messages, or online discussion forums.</p><p>Today, we can see NLP being applied in many aspects of our daily lives — such as in <strong>sentiment analysis</strong>, <strong>hate speech detection</strong>, and various other <strong>text classification tasks</strong>. It’s becoming more and more integrated into the digital tools we use every day. ​(Danenas &amp; Skersys, 2022), (Cambria &amp; White, 2014)​</p><h3>Sentiment Analysis</h3><p>One of the most popular branches of Natural Language Processing (NLP) is <strong>Sentiment Analysis</strong>. It’s a technique used to detect the tone or emotion behind a piece of text — whether it’s <em>positive</em>, <em>negative</em>, or just <em>neutral</em>.</p><p>You’ve probably seen it in action without even realizing it. From product reviews on shopping apps, movie ratings, to the flood of comments on social media — Sentiment Analysis helps us understand what people are feeling. It’s commonly used to analyze customer feedback or to monitor public response toward a product, service, or even a viral post. (Mao et al., 2024), (Xing et al., 2020)</p><h3><strong>Transformer Model</strong></h3><p>From the paper with title <strong>“Attention is All You Need”</strong>, (Vaswani et al., 2017) introduced Transformers as a type of deep learning architecture designed to handle sequential data like text — but with a major advantage: they process information <strong>in parallel</strong>, making them much more efficient than older models like RNNs, which process data step-by-step.</p><p>First introduced in 2017, Transformers brought a big shift in how machines understand language. They’re built to focus on the most important parts of an input and learn the relationships between words or even entire sentences.</p><p>Transformers have become a major breakthrough in NLP, serving as the foundation for many powerful models we know today — like <strong>BERT</strong>, <strong>GPT</strong>, and more. (Vaswani et al., 2017)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/0*Oaaf2Duma0gdzaep" /><figcaption><strong>Transformer Architecture Diagram</strong></figcaption></figure><p>In the <strong>Transformer architecture diagram above</strong>, we can see two main parts: the <strong>Encoder</strong> and the <strong>Decoder</strong>. (<strong>Left </strong>side (<strong>Encoder</strong>) and <strong>Right </strong>side (<strong>Decoder</strong>)).</p><p>The <strong>Encoder</strong> takes in the input text, which is first converted into a sequence of tokens (numbers representing words or characters). These tokens are then turned into vectors through <strong>word embedding</strong>. Since vectors don’t understand word order, the model adds something called <strong>Positional Encoding</strong> so it knows the position of each word — even though the processing happens in parallel.</p><p>Once the embedding and position information are added, the data flows through multiple <strong>Encoder layers</strong>. One key step is <strong>Multi-Head Self-Attention</strong>, where the model learns the relationship between words in a sentence. For example, in the sentence “I like cats,” it understands how “like” connects to both “I” and “cats” to get the full meaning.</p><p>After that, the output goes through a <strong>Feed-Forward Neural Network</strong>, which helps the model understand the sentence at a deeper level. The result then moves to the next encoder layer.</p><p>The <strong>Decoder</strong> generates the final output based on what the encoder has learned. It starts with <strong>Masked Multi-Head Self-Attention</strong>, which ensures the model only looks at previous words when predicting the next one — this keeps the predictions accurate. Like the encoder, it also uses a feed-forward layer to improve the word representation.</p><p>At the end, the decoder produces a vector that gets turned back into words or sentences based on the task — like translating text or generating responses.</p><h3>Recurrent Neural Network (RNN) model</h3><p><strong>Recurrent Neural Networks (RNNs)</strong> are a type of deep learning model built to handle sequential data — like text, speech, or time series. What makes RNNs special is their ability to “remember” previous information in a sequence, which helps in understanding the context of what comes next. For instance, in the sentence <em>“I love watching movies”</em>, an RNN doesn’t just focus on the word <em>“movies”</em>, but also takes into account the earlier words to get the full meaning.</p><p>However, because RNNs process data one step at a time, they can be <strong>slower</strong> and may struggle with <strong>longer sequences</strong>. In contrast, <strong>Transformer-based models</strong> like BERT or DistilBERT are designed to process entire sequences <strong>in parallel</strong> and capture relationships between words more efficiently, making them more powerful for many modern NLP tasks.</p><h3>BERT</h3><p>(Devlin et al., 2019)​ introduced <strong>BERT (Bidirectional Encoder Representations from Transformers)</strong> is a powerful language model built on Transformer architecture, introduced with a unique <strong>bidirectional approach</strong>. It comes in two main versions: <strong>BERT Base</strong>, which has 12 layers and around 110 million parameters, and <strong>BERT Large</strong>, with 24 layers and a massive 340 million parameters.</p><p>What makes BERT special is its ability to understand the context of a word by looking at <strong>both directions</strong> in a sentence — thanks to a technique called <strong>Masked Language Modeling (MLM)</strong>. In MLM, some words in a sentence are randomly replaced with a [MASK] token, and the model is trained to guess the masked words based on the surrounding context. Interestingly, not all masked words are replaced with [MASK]—this trick helps the model learn better during fine-tuning when [MASK] tokens don’t actually appear in real-world data.</p><p>BERT also learns sentence relationships using another technique called <strong>Next Sentence Prediction (NSP)</strong>. This trains the model to understand whether one sentence naturally follows another. For example, during training, 50% of the time the second sentence is a real continuation (labeled <em>isNext</em>), and the other 50% it’s just a random sentence from elsewhere (labeled <em>NotNext</em>). This feature is especially useful for tasks like <strong>Question Answering</strong> and <strong>Natural Language Inference</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BzKunSzOCa3WF6Qc" /><figcaption><strong>Pre-Training and Fine-Tuning BERT</strong></figcaption></figure><p>BERT is trained in two main stages: <strong>Pre-training</strong> and <strong>Fine-tuning</strong>. During pre-training, the model learns from a large amount of unlabeled text using two key tasks: <strong>Masked Language Modeling (MLM)</strong> and <strong>Next Sentence Prediction (NSP)</strong>. MLM trains the model to predict missing words in a sentence, while NSP helps it understand relationships between two sentences. Once pre-training is done, the model is fine-tuned on labeled data specific to the task (like sentiment analysis or question answering), where all the parameters of BERT are adjusted for that specific goal. (Yao et al., 2025)</p><p>To prepare input for BERT, the text is first tokenized using <strong>WordPiece</strong>, which breaks down words into smaller subword units — helpful for handling unknown or rare words. Special tokens like [CLS] (for classification) and [SEP] (for separating sentences) are added to the sequence. Then, three types of embeddings are used: <strong>Token Embeddings</strong> to represent the meaning of each word, <strong>Segment Embeddings</strong> to distinguish between sentence A and B, and <strong>Positional Embeddings</strong> to show the order of tokens. These embeddings are summed together and passed into the BERT model for processing.</p><h3>DistilBERT</h3><p><strong>DistilBERT</strong> is a lighter and faster version of the original BERT model. It was created using a process called <strong>knowledge distillation</strong>, where a smaller model (called the <em>student</em>) learns from a larger, pre-trained model (the <em>teacher</em>). In this case, the teacher is BERT, and the student is DistilBERT. Despite being 40% smaller, DistilBERT manages to retain about <strong>97% of BERT’s performance</strong>, while being much more efficient in terms of computation.</p><p>DistilBERT has around <strong>66 million parameters</strong> compared to BERT’s 110 million, making it significantly lighter. It also offers up to <strong>60% faster inference time</strong>, and in some tasks — like mobile question answering — it can be <strong>up to 71% faster</strong>. The goal of this smaller model is to <strong>replicate the behavior and knowledge</strong> of the larger BERT model, including its prediction capabilities and internal representations, while being optimized for speed and resource use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/0*lsLyzox4aYmlTj9F" /><figcaption><strong>Teacher-Student Model for Knowledge Distillation</strong></figcaption></figure><p><strong>Knowledge Distillation</strong> is a machine learning technique where a smaller model (<em>student</em>) learns from a larger, more complex model (<em>teacher</em>) to become faster and lighter while maintaining similar performance. This idea was first introduced by Bucila et al. (2006) and later popularized by Hinton et al. (2015). Unlike traditional supervised learning that uses <em>hard labels</em> (e.g., class A = 1, all others = 0), the teacher provides <em>soft labels</em> — probability distributions across all classes (F.Y et al., 2017). For example, instead of predicting that an image is 100% a “cat”, the teacher might output: cat = 0.7, fox = 0.2, dog = 0.1. This tells the student model not only the most likely class but also which other classes are slightly similar, helping it learn more nuanced decision boundaries and not just memorizing the correct answer.</p><h3>GRU (Gated Recurrent Unit)</h3><p>To address limitations like the <strong>vanishing gradient problem</strong> and the difficulty of capturing <strong>long-term dependencies</strong> in standard RNNs, the <strong>Gated Recurrent Unit (GRU)</strong> was introduced as a simpler alternative to LSTM (Long Short-Term Memory) models (“Unveiling deep learning powers LSTM BiLSTM GRU BiGRU”). GRU uses two main gates — <strong>update gate</strong> and <strong>reset gate</strong> — to control how information is passed and forgotten, allowing it to handle sequential text data more efficiently. Compared to LSTM, GRU is <strong>faster and more lightweight</strong> due to having fewer parameters (Shaikh &amp; Ramadass, 2024). However, when compared to models like <strong>BERT</strong>, GRU still falls short in understanding deep contextual meaning, as it processes input <strong>unidirectionally</strong> (left to right), whereas BERT handles entire sentences in a <strong>parallel and bidirectional</strong> manner (Zhang, 2024).</p><h3>Bi-GRU</h3><p><strong>Bidirectional GRU (Bi-GRU)</strong> is an extension of the standard GRU that allows the model to process information in <strong>both directions</strong> — forward (from the beginning to the end of a sentence) and backward (from the end to the beginning). This bidirectional setup helps the model gain a <strong>more complete understanding of context</strong>, especially in sequential text data. In Bi-GRU, there are two GRU layers running in parallel: one reads the sequence from time step 1 to T (forward), and the other from T to 1 (backward). Compared to regular GRU, Bi-GRU offers better context awareness. And while it performs similarly to <strong>Bi-LSTM</strong>, Bi-GRU is generally <strong>simpler and faster</strong> because it uses fewer parameters, making it a more lightweight option for many NLP tasks.</p><h3>DistilBERT vs. Bi-GRU</h3><p>In this experiment, I compared two different NLP models: DistilBERT, which is a Transformer-based model known for its attention mechanism and parallel processing, and Bi-GRU, a simpler RNN-based model that processes text sequentially in both forward and backward directions.</p><h3>Datasets</h3><p>The dataset used to train the model in this case is, of course, <strong>social media data (comments)</strong>, since our main goal is to perform <strong>sentiment analysis on social media platforms</strong>. The training data contains <strong>text in Bahasa Indonesia</strong>, because another goal of this experiment is to build an efficient model that can perform sentiment analysis in Bahasa with <strong>high accuracy</strong>. Right now, it’s still quite rare to find a solid and reliable model for this task — most of the previous works still rely on <strong>traditional machine learning methods</strong>.</p><p>We collected the data from several sources across the internet, including Kaggle, HuggingFace, and GitHub:</p><ul><li>Cyberbullying text data from <strong>Kaggle</strong>, created by <strong>Cita Tiara Hanni</strong> in 2021.</li></ul><p><a href="https://www.kaggle.com/datasets/cttrhnn/cyberbullying-bahasa-indonesia">Cyberbullying Bahasa Indonesia</a></p><ul><li>A cyberbullying dataset from <strong>HuggingFace</strong>, uploaded by <strong>aditdwi123</strong> in 2024.</li></ul><p><a href="https://huggingface.co/datasets/aditdwi123/cyber-bullying-dataset/tree/main">aditdwi123/cyber-bullying-dataset at main</a></p><blockquote>(*This dataset is in Json format so we have to <strong>convert </strong>that first to match all the datasets.)</blockquote><ul><li>A dataset of Instagram comments from 2019, published by <strong>rizalespe</strong> on <strong>GitHub</strong>.</li></ul><p><a href="https://github.com/rizalespe/Dataset-Sentimen-Analisis-Bahasa-Indonesia/blob/master/dataset_komentar_instagram_cyberbullying.csv">Dataset-Sentimen-Analisis-Bahasa-Indonesia/dataset_komentar_instagram_cyberbullying.csv at master · rizalespe/Dataset-Sentimen-Analisis-Bahasa-Indonesia</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YA7qGfmipGMwTp7UQcC5BQ.png" /><figcaption><strong>A sample portion of the dataset in Bahasa Indonesia used for training</strong></figcaption></figure><h3>Experiment Stages</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/161/1*2k59pAUvh0PWRKbGMaWakg.png" /><figcaption><strong>Stages of the Experiment</strong></figcaption></figure><h3>DistilBERT</h3><p>In this case, we are using the &quot;cahya/distilbert-base-indonesian&quot; pre-trained DistilBERT model from Hugging Face, which is trained on Indonesian language data.</p><blockquote>This model is a distilled version of the <a href="https://huggingface.co/cahya/bert-base-indonesian-1.5G">Indonesian BERT base model</a>. This model is uncased.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dem-wbSoD3BEAdZs2nNb_Q.png" /><figcaption><strong>Distilled version of IndoBERT</strong></figcaption></figure><p><strong>Text Preprocessing Steps:</strong></p><p>In this project, multiple datasets were first combined into a single unified dataset to ensure consistency and ease of processing. The text data then underwent several preprocessing steps to clean and standardize the content. These steps included converting all text to lowercase to maintain uniformity, removing non-alphabetic characters such as symbols, numbers, and special characters, and eliminating unnecessary white spaces and line breaks.</p><p>After completing all preprocessing steps, the cleaned and standardized text was stored in a new column called clean_text. This version of the text is then ready for further steps such as tokenization and model training.</p><p>After the preprocessing stage, the cleaned text (clean_text) is tokenized using the tokenizer from the &quot;cahya/distilbert-base-indonesian&quot; model. Each text is converted into input IDs and attention masks with a fixed maximum length. These tokenized inputs, along with their labels, are then wrapped into a custom PyTorch dataset for training and evaluation.</p><p>Next, the pre-trained DistilBERT model is loaded for binary classification. Training settings such as batch size, number of epochs, and evaluation strategy are defined using Hugging Face’s TrainingArguments. The Trainer class is then used to manage the training process.</p><p>The DistilBERT model achieved a high accuracy of approximately<strong> 90.8%</strong> on the <strong>test set</strong>, indicating strong overall performance. The confusion matrix shows that the model correctly classified most samples, with only a small number of misclassifications between the “Bullying” and “Non-Bullying” classes. The classification report further confirms this with balanced precision, recall, and F1-scores around <strong>0.90–0.92 </strong>for both classes, suggesting that the model performs consistently well in identifying both types of text.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*KiGMquqDHlf98A6YztnoUw.png" /><figcaption><strong>The Results of the Evaluation Model (Accuracy, Recall, Preciion, F1-Score, Support) from the DistilBERT</strong></figcaption></figure><p>Below is the <strong>notebook</strong> of the DistilBERT model :</p><p><a href="https://colab.research.google.com/drive/1vtw3degva3OqHdjlfSbk_zOuWCBmXdC2?usp=sharing">https://colab.research.google.com/drive/1vtw3degva3OqHdjlfSbk_zOuWCBmXdC2?usp=sharing</a></p><h3>Bi-GRU</h3><p>The tokenization process begins by applying the multilingual spaCy model (xx_ent_wiki_sm) to each cleaned text in the dataset. This model is capable of handling texts in multiple languages, including Indonesian. Using nlp(x), spaCy processes each sentence and breaks it down into individual tokens (words or symbols). During this step, tokens that are punctuation marks (token.is_punct) or whitespace (token.is_space) are filtered out to retain only meaningful words. Each token is then converted to lowercase to maintain consistency. The final result is a list of clean, lowercase word tokens for each sentence, stored in a new column called tokens in the dataframe.</p><p>Neural networks can’t directly process raw text — they require <strong>numeric input</strong>. So we need to convert each word (token) into a number. This is done using a <strong>word-to-index mapping</strong>, commonly called word2idx. The word2idx process creates a mapping from each unique word (token) to a specific index number. First, all tokens from the dataset are collected and converted into a unique vocabulary.</p><p>After the text preprocessing and tokenization using the multilingual spaCy model, each sentence is converted into a sequence of word tokens. These tokens are then mapped to numerical indices using a custom word2idx dictionary that includes special tokens &lt;PAD&gt; and &lt;UNK&gt;. Each token sequence is padded or truncated to a fixed length using the encode() function, and the resulting sequences (input_ids) along with their labels are wrapped into a custom PyTorch Dataset class. The dataset is then split into training and testing sets, and data loaders are created to feed the data in batches during training.</p><p>The Bi-GRU model achieved an accuracy of <strong>83.8%</strong>, showing solid performance in classifying bullying and non-bullying texts. The confusion matrix indicates some misclassifications in both classes, but overall balance is maintained. The classification report shows that both precision and recall are approximately <strong>0.84</strong>, with F1-scores of <strong>0.85</strong> for “Bullying” and <strong>0.83</strong> for “Non-Bullying”. This suggests that the Bi-GRU model is effective, although slightly less accurate than the DistilBERT model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*lqzYPy6dioe1_RD-PdaoMw.png" /><figcaption><strong>The Results of the Evaluation Model (Accuracy, Recall, Preciion, F1-Score, Support) from Bi-GRU</strong></figcaption></figure><p>Below is the <strong>notebook</strong> of the Bi-GRU model :</p><p><a href="https://colab.research.google.com/drive/1d11y-x4YMg-kW_nEnYCFlhmX6eYEkQkk?usp=sharing">https://colab.research.google.com/drive/1d11y-x4YMg-kW_nEnYCFlhmX6eYEkQkk?usp=sharing</a></p><h3>Conclusion :</h3><p>The <strong>conclusion</strong> reached from the <strong>comparison</strong> experiment between the <strong>DistilBERT</strong> and <strong>Bi-GRU </strong>models<strong> for Sentiment Analysis </strong>using an Indonesian language dataset shows that DistilBERT, as a transformer-based model, clearly outperforms Bi-GRU, which is based on RNN architecture. This conclusion is drawn from the fact that DistilBERT, a distilled version of the BERT model, has been pre-trained on a large-scale word corpus, allowing it to <strong>better understand the context between words</strong>.</p><p>This advantage also stems from the nature of DistilBERT as a pre-trained model with significantly more parameters, compared to the Bi-GRU model which still relies on <strong>static embeddings</strong> — where words are represented using fixed vector values and thus cannot capture the dynamic meaning of words within sentences. In contrast, DistilBERT uses <strong>contextual embeddings</strong> generated through the Transformer architecture, which allows it to capture word meanings based on the full sentence context. This makes DistilBERT superior in handling complex tasks such as cyberbullying text classification in Indonesian.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5cd878ba216" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>