<?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 Abdurrahman Elbuni on Medium]]></title>
        <description><![CDATA[Stories by Abdurrahman Elbuni on Medium]]></description>
        <link>https://medium.com/@aelbuni?source=rss-8d05031118f8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*JEwSpW7or4CaP7X1BNGFlg.png</url>
            <title>Stories by Abdurrahman Elbuni on Medium</title>
            <link>https://medium.com/@aelbuni?source=rss-8d05031118f8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 07:16:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aelbuni/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[Aigent.ly is the open-source layer that keeps your AI coding tool from shipping yesterday’s…]]></title>
            <link>https://aelbuni.medium.com/built-for-vibe-coders-bd10ba85aa07?source=rss-8d05031118f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd10ba85aa07</guid>
            <category><![CDATA[ai-security]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[vibe-coding]]></category>
            <category><![CDATA[mcp-server]]></category>
            <dc:creator><![CDATA[Abdurrahman Elbuni]]></dc:creator>
            <pubDate>Thu, 28 May 2026 21:41:53 GMT</pubDate>
            <atom:updated>2026-05-28T23:08:44.099Z</atom:updated>
            <content:encoded><![CDATA[<h3>Aigent.ly is the open-source layer that keeps your AI coding tool from shipping yesterday’s vulnerabilities</h3><h3>Vibe coding is a genuine shift in how software gets built.</h3><p>The combination of AI coding assistants — Cursor, Claude Code, Windsurf, Lovable — and an expanding generation of builders is compressing what once took teams and quarters into weekends and solo sprints. By most forecasts, the volume of software produced in the next decade will dwarf everything built before it. That’s a remarkable thing.</p><p>It also introduces a context problem that the industry hasn’t fully reckoned with yet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p-pIjZElMt5zT0lAwaAOxw.png" /></figure><h3>The gap isn’t skill. It’s information velocity.</h3><p>AI coding models are trained on a snapshot of the world. Security, by its nature, changes daily. New CVEs are published continuously. The CISA Known Exploited Vulnerabilities catalog grows every week. Attack surfaces shift as frameworks evolve.</p><p>The model in your IDE doesn’t know what changed yesterday — not because it’s inadequate, but because the threat landscape moves faster than any training cycle can track.</p><p>This is a structural challenge, not a criticism of the tools. And it’s exactly the kind of problem that infrastructure, not individual developer vigilance, is the right answer to.</p><p>What’s particularly interesting is that the security community is beginning to respond in kind. Tools like Mythos and emerging AI-assisted vulnerability research pipelines — including work coming out of Google Project Zero and academic security labs — are demonstrating that AI is genuinely effective at <em>finding</em> vulnerabilities at scale. The same intelligence that accelerates development can accelerate discovery of its own blind spots.</p><p>The question becomes: how does that signal reach the developer before the code ships?</p><h3>Context engineering is the answer.</h3><p>The best teams building on AI today aren’t just prompting better. They’re managing context — the structured information that shapes how the model behaves across every generation. Threat rules, security constraints, CVE patterns: these belong in context, not in post-commit review.</p><p>That’s the problem <a href="https://aigent.ly/">Aigent.ly</a> is built to solve.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*Gl5qTpZoBekc6VTcS-ngSQ.png" /></figure><h3>How it works:</h3><p>Every day, our pipeline ingests active threats from five public intelligence sources: NVD, GitHub Advisory Database (GHSA), CISA KEV, Google OSV, and npm Audit. Claude AI synthesizes each CVE into precise behavioral rules — concrete ALWAYS/NEVER directives grounded in real attack patterns. Those rules are clustered per stack and assembled into a single governing context file for each technology.</p><p>The result: one current, accurate, authoritative security context — updated every 24 hours — ready to be injected into any AI coding tool before it writes a line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EB8jEM5JSpi677cF6YTYhw.png" /><figcaption>Context Enrichment by Aigently MCP</figcaption></figure><p>When your IDE sees that file, it knows:</p><blockquote>“For Next.js: NEVER rely solely on middleware for authorization — CVE-2025–29927 demonstrates this is bypassable at the routing layer. ALWAYS enforce access control at the route handler.”</blockquote><p>The context travels with the code. The guardrail fires at generation time, not audit time.</p><h3>Two paths to integration — neither requires significant setup:</h3><p>The MCP server (Model Context Protocol) connects directly to Cursor, Claude Code, Windsurf, Copilot, and Cline via a single config line. Threat context is injected automatically on every generation.</p><p>For teams who prefer file-based context — or who use Claude Code’s CLAUDE.md memory, Cursor’s .cursor/rules, or Windsurf’s .windsurfrules — the Rule Composer generates your stack’s guardrail file in under 60 seconds. Drop it into your repository. Every AI assistant on the project picks it up. No server, no ongoing configuration. The rules live where they belong: alongside the code.</p><h3>Where the catalog is going:</h3><p>Today we cover the stacks that power most of the modern web: Next.js · Express · FastAPI · NestJS · Nuxt · React SPA</p><p>Coming next: Django · Ruby on Rails · Go · iOS · Android — and beyond.</p><p>Five threat sources today. The Go vulnerability database, RubyGems advisories, PyPI feeds, and Maven are on the roadmap. The catalog is open source and community-driven. Every new source means more signal. Every new stack means more developers covered.</p><p>The goal is straightforward: comprehensive threat context for every major application stack, maintained as open infrastructure, free to use and contribute to.</p><h3>Aigent.ly is open source. Apache 2.0. No API key. No account.</h3><p>The catalog data, the pipeline, and the MCP server are all public. The project is designed to grow with the community and with the threat landscape — not as a product that ships and stays static, but as infrastructure that compounds over time.</p><p>If you’re building with AI coding tools and thinking about how security context fits into that workflow, I’d be glad to hear your perspective.</p><p>🔗 Try the Rule Composer: <a href="http://aigent.ly/composer">aigent.ly/composer</a></p><p>⭐ Explore the catalog: <a href="http://github.com/aelbuni/aigently-catalog">github.com/aelbuni/aigently-catalog</a></p><h3>A note on contribution:</h3><p>Every application built on better security context is one less breach, one less exposed user, one less incident report at 2am.</p><p>If you work in security research, application engineering, or AI development — there is meaningful work to do here. Add a stack your ecosystem depends on. Sharpen a CVE pattern that’s too generic. Propose a new threat source. Write a rule that reflects what you’ve seen in the field.</p><p>The catalog improves fastest when people who understand the real threat landscape help shape it. If that’s you, the repo is open and the contribution guide is straightforward.</p><p>The next application that doesn’t get compromised might be built by someone who has never thought about security once. That’s exactly who this is for — and exactly why it needs the sharpest minds contributing to it.</p><p>#ContextEngineering #VibeCoding #AppSec #OpenSource #AICode #MCP #DevSecOps #SecurityEngineering #ClaudeCode #Cursor #SoftwareDevelopment</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd10ba85aa07" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Revolutionizing Healthcare: Part 1 — Advanced Machine Learning Empowering Multilingual…]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://aelbuni.medium.com/revolutionizing-healthcare-advanced-machine-learning-empowering-multilingual-question-answering-550c98ac03e6?source=rss-8d05031118f8------2"><img src="https://cdn-images-1.medium.com/max/738/1*5Ir6IhmlAAAcCBzW_rTpsw.jpeg" width="738"></a></p><p class="medium-feed-snippet">Utilizing Advanced Multilingual AI Models to Break Language Barriers for Semantic Search</p><p class="medium-feed-link"><a href="https://aelbuni.medium.com/revolutionizing-healthcare-advanced-machine-learning-empowering-multilingual-question-answering-550c98ac03e6?source=rss-8d05031118f8------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://aelbuni.medium.com/revolutionizing-healthcare-advanced-machine-learning-empowering-multilingual-question-answering-550c98ac03e6?source=rss-8d05031118f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/550c98ac03e6</guid>
            <category><![CDATA[healthcare]]></category>
            <category><![CDATA[genai]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[retrieval-augmented]]></category>
            <category><![CDATA[multilingualism]]></category>
            <dc:creator><![CDATA[Abdurrahman Elbuni]]></dc:creator>
            <pubDate>Tue, 20 Feb 2024 00:46:26 GMT</pubDate>
            <atom:updated>2024-03-14T22:54:17.696Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Quick Start Guide — Submit Spark (2.4) Jobs on Minikube/AWS]]></title>
            <link>https://aelbuni.medium.com/apache-spark-2-4-3-running-jobs-in-kubernetes-cluster-ebd7a28b99cd?source=rss-8d05031118f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/ebd7a28b99cd</guid>
            <dc:creator><![CDATA[Abdurrahman Elbuni]]></dc:creator>
            <pubDate>Sun, 14 Jul 2019 22:47:56 GMT</pubDate>
            <atom:updated>2024-02-20T05:27:55.283Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D-BC6phMMPOnm5GtKjlrng.jpeg" /></figure><p>Day over day, containerization is still proving to us that it is the guiding star that a lot of industry leaders have sought and still seeking to improve software build and deployment process. Consequently, utilizing container orchestration platforms for Big Data processing is no exception, in a Big Data world where we seek to optimally schedule jobs and allocate resources.</p><p>In the near future kubernetes will be the middle-ware to BigData compute jobs with smart auto-scaling capabilities according to data workload and resource requirement. To apply or monitor the progress of cluster autoscaling for kubernetes you can follow this project <a href="https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler">Cluster Autoscaler</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wyMoY1rGC3wWA80bnxFOfA.jpeg" /><figcaption>Fig 1— Scheduling Spark Jobs</figcaption></figure><p>Now, for sake of brevity I am not going to talk about kubernetes as a technology, but, I would rather focus on providing an instructional tutorial that will help you run your first spark job in any kubernetes cluster.</p><h3>Spark Job Execution</h3><h4>Typical Job Submission Process</h4><p>Just to refresh the readers mind, here is a beautiful diagram (Fig 1) that I borrowed from <a href="https://data-flair.training/blogs/how-apache-spark-works/">DataFlair</a>, which depicts the sequence of operations that will be triggered by submitting a Spark job to a cluster manager.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R9ngnhW2QaeHAdQEF8NkYg.jpeg" /><figcaption>Fig 2 — Internal Job Execution in a regular Cluster Manager (Mesos, Yarn, or Standalone)</figcaption></figure><h4>Kubernetes Job Submission Process</h4><p>Briefly, in cluster mode submission we want to submit a job to a kubernetes master with a pre-defined docker image to derive the driver container from and run it inside of a pod. Then, we should always remember to give the driver the right permission to access the k8s cluster through (apiserver) and be able to create and manage other pods as it deems necessary corresponding to configuration, see(Fig 3)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*tkWi16Clt_6RjLJNmyLVkg.png" /><figcaption>Fig 3 — Internal Job Execution in a Kubernetes Cluster</figcaption></figure><h3>Installation &amp; Environment Setup</h3><ul><li>EC2 Instance [t2.xlarge] — (ubuntu-xenial-16.04-amd64-server)</li><li>Docker v18.09.7</li><li>minikube v1.2.0 — (Kubernetes v1.15.0)</li><li>Apache Spark 2.4.3</li><li>Java 1.8.0</li><li>Scala 2.11</li></ul><p><strong>Note</strong>: You can use you laptop machine just fine instead of EC2, especially for Mac and Ubuntu users. Windows have some caveats in configuration as usual :)</p><h4>1) Installing Docker, Java &amp; Scala</h4><p>It make sense to start with installing docker as a containerization layer using a the following command</p><pre>// 1) Install docker<br>&gt;&gt; sudo apt-get update &amp;&amp; sudo apt-get install docker.io -y</pre><pre>// Check for the version<br>&gt;&gt; docker version </pre><pre>// 2) Install Java (openjdk)<br>&gt;&gt; sudo apt-get install default-jdk<br>&gt;&gt; java -version<br>openjdk version &quot;1.8.0_212&quot;</pre><pre>// 3) Install Scala<br>&gt;&gt; sudo apt-get install scala<br>&gt;&gt; scala -version<br>Scala code runner version 2.11.6 -- Copyright 2002-2013, LAMP/EPFL</pre><h4>2) Installing Minikube</h4><p><a href="https://kubernetes.io/docs/setup/learning-environment/minikube/#installation">Minikube</a> is a tool that makes it easy to run Kubernetes locally. <a href="https://kubernetes.io/docs/setup/learning-environment/minikube/#installation">Minikube</a> runs a single-node Kubernetes cluster inside a Virtual Machine (VM) on your host for users looking to try out Kubernetes or develop with it day-to-day.</p><p>For this tutorial, we don’t need to install virtualbox as the selected AWS kernel doesn’t support virtualization, or doesn’t include vboxdrv kernel module</p><pre>&gt;&gt; curl -Lo minikube <a href="https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64">https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64</a> &amp;&amp; chmod +x minikube</pre><pre>&gt;&gt; chmod +x .minikube /usr/local/bin</pre><pre>&gt;&gt; sudo mv ./kubectl /usr/local/bin/kubectl</pre><pre>// Make sure it is ready<br>&gt;&gt; minikube version</pre><h4>3) Building Docker Image for Spark Driver</h4><p>Download your desired Spark distribution package, at time of writing this post, the latest version available is v2.4.3</p><pre>&gt;&gt; wget <a href="https://www.apache.org/dyn/closer.lua/spark/spark-2.4.3/spark-2.4.3-bin-hadoop2.7.tgz">https://www.apache.org/dyn/closer.lua/spark/spark-2.4.3/spark-2.4.3-bin-hadoop2.7.tgz</a></pre><pre>&gt;&gt; tar -xvf spark-2.4.3-bin-hadoop2.7.tgz</pre><pre>// move spark folder to a better location<br>&gt;&gt; mv spark-2.4.3-bin-hadoop2.7 /opt/spark</pre><p><strong>Optional: </strong>Not suitable for production use. You should switch to root to be able to run docker command freely</p><pre>&gt;&gt; sudo -i</pre><p><strong>Otherwise:</strong> You will have to create docker user/group as it is described <a href="https://docs.docker.com/install/linux/linux-postinstall/">here</a></p><p>Now you are ready to build the spark driver image by going to `/opt/spark` directory and running the following command</p><pre>&gt;&gt; cd /opt/spark<br>&gt;&gt; ./bin/docker-image-tool.sh -r k8s -m build</pre><p>Alright, here you go; the script has generated the necessary image for us now. <strong>Note </strong>we only need to use k8s/spark for our exercise</p><pre>&gt;&gt; docker images<br>REPOSITORY     TAG IMAGE ID     CREATED  SIZE<br>k8s/spark-r    latest           20 seconds ago      739MB<br>k8s/spark-py   latest           30 seconds ago      445MB<br>k8s/spark      latest           43 seconds ago      354MB</pre><h4>4) Running the spark job</h4><p>I am going to build a bash script and call it `run-spark.sh` to be able to easily manipulate the file for testing purposes. I will change the command to apply the following simple configuration</p><ul><li>Number of executors = 3</li></ul><p>So that when the job runs, it will distribute the workload across 3 different executors</p><ul><li>Deploy mode = cluster</li></ul><p>If you want to tweak the configuration and play around with job, then the following link will be your best reference (<a href="https://spark.apache.org/docs/latest/running-on-kubernetes.html">Spark Documentation</a>)</p><pre>#!/bin/bash</pre><pre>spark-submit \<br>   --master k8s://https://{k8s-master-ip}:8443 \<br>   --deploy-mode cluster \<br>   --name spark-pi \<br>   --class org.apache.spark.examples.SparkPi \<br>   --conf spark.executor.instances=3 \<br>   --conf spark.kubernetes.container.image=k8s/spark \<br>   --conf spark.kubernetes.namespace=default \<br>   local:///opt/spark/examples/jars/spark-examples_2.11-2.4.3.jar</pre><p>After you save the file, make sure to change its mode to executable</p><pre>&gt;&gt; chmod +x run-spark.sh</pre><p>You don’t have to change the</p><p>Now, before you go ahead and run the script there are two missing steps:</p><ul><li><strong>Run minikube cluster</strong></li></ul><pre>&gt;&gt; minikube start --vm-driver=none --cpus=5 --memory=4048</pre><p>Running the minikube single node cluster will take sometime, and right after it starts you should confirm that kubectl command does communicate with the master</p><pre>&gt;&gt; kubectl get nodes<br>NAME       STATUS   ROLES    AGE    VERSION<br>minikube   Ready    master   131m   v1.15.0</pre><ul><li><strong>Identify the IP Address of the k8s master</strong></li></ul><p>Now that you have ran the cluster and your kubectl cli is working, run the following command to get the IP address of the minikube, which in AWS EC2 case it should point to our localhost</p><pre>&gt;&gt; kubectl cluster-info<br>Kubernetes master is running at <a href="https://172.31.31.99:8443/">https://172.31.22.11:8443</a><br>KubeDNS is running at <a href="https://172.31.31.99:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy">https://172.31.22.11:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy</a></pre><ul><li><strong>Running kubernetes dashboard</strong></li></ul><p>If you don’t use EC2 as a host, and you are using your personal PC, then I recommend you run the Kubernetes Dashboard, so you can monitor what is going on using the <a href="https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/">k8s Dashboard GUI</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sD0LKJ3JeGZ-2AQT7HjdSg.png" /></figure><p>Finally, now that you got the k8s master IP address, you can go back to `run-spark.sh` script and update it with the right IP address and port</p><pre>#!/bin/bash</pre><pre>spark-submit \<br>   --master k8s://https://<a href="https://172.31.31.99:8443/">172.31.22.1</a>1:8443 \<br>   --deploy-mode cluster \<br>   --name spark-pi \<br>   --class org.apache.spark.examples.SparkPi \<br>   --conf spark.executor.instances=3 \<br>   --conf spark.kubernetes.container.image=k8s/spark \<br>   --conf spark.kubernetes.namespace=default \<br>   local:///opt/spark/examples/jars/spark-examples_2.11-2.4.3.jar</pre><h3>Run the Spark Job</h3><p>Try to run the script now and see what happens</p><pre>./run-spark.sh</pre><pre>// Check for the running <br>&gt;&gt; kubectl get pods<br>NAME                            READY   STATUS<br>spark-pi-1562465263980-driver   1/0     Failed </pre><p><strong>Oops</strong>, the driver fails for some reasons, let’s figure out why by accessing the logs</p><pre>&gt;&gt; kubectl logs -f spark-pi-1562465263980-driver</pre><p>Looking at the Driver’s log, you will clearly see that the driver is failing to create executors, because it doesn’t have create access to k8s cluster through apiserver. This problem is very common, but with the right troubleshooting it should be easy to identify.</p><h4><strong>Assign the Right Role to Driver’s Pod</strong></h4><p>I am not going to deeply talk about kubernetes Role Based Access Control (RBAC ). We can solve this issue in two ways, the right long way and the hacky quick way, and for demonstration purposes I will explain the ideal solution, but apply a quick hack to circumvent the issue!</p><p>The right approach to solve permission issue, is to create a new <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/">ServiceAccount</a> object and assign it a cluster access role. Then we can modify the existing driver’s pod definition to use the new service account through kubrctl cli.</p><p>The hacky approach is to check what ServiceAccount object is the current driver referencing, which will most likely be the default ServiceAccount, and then authorize it for cluster access. Please “do not do that in production” 👍</p><pre>// Extract the pod definition file from driver&#39;s pod<br>&gt;&gt; kubectl get pod spark-pi-1562465263980-driver -o yaml &gt; driver-pod.yaml</pre><p>Now by reading the driver-pod.yaml, you can confirm that its using the default serviceAccount</p><p>Let’s authorize default ServiceAccount to access the cluster (the lazy panda way). Right after, create authorize.yaml file and load the following definition into it</p><pre>apiVersion: rbac.authorization.k8s.io/v1beta1<br>kind: ClusterRoleBinding<br>metadata:<br>  name: spark-driver-rbac<br>subjects:<br>  - kind: ServiceAccount<br>    name: default<br>    namespace: default<br>roleRef:<br>  kind: ClusterRole<br>  name: cluster-admin<br>  apiGroup: rbac.authorization.k8s.io</pre><p><strong>Hurray, </strong>last step is to apply it through kubectl cli</p><pre>&gt;&gt; kubectl apply -f authorize.yaml</pre><pre>// Clean-out all pods for clarity<br>&gt;&gt; kubectl delete pod --all</pre><p>Right, now run the spark-run.sh script again and if you don’t have k8s dashboard running in a browser, just open another ssh session and check for the running pods during the job execution</p><pre>&gt;&gt; kubectl get pod</pre><pre>NAME                            READY   STATUS    RESTARTS   AGE<br>spark-pi-1562465263980-driver   1/1     Running   0          10s<br>spark-pi-1562465263980-exec-1   1/1     Running   0          4s<br>spark-pi-1562465263980-exec-2   1/1     Running   0          4s<br>spark-pi-1562465263980-exec-3   0/1     Pending   0          4s</pre><p>This look much better! Once the job finishes we can check the driver’s log the same way we did before and confirm the results.</p><h3>You are good to go!</h3><p>Now you can go back and play around with configuration and Spark job source code until you get the outcome you need.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ebd7a28b99cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Modeling Topics in Quran using Machine Learning & NLP]]></title>
            <link>https://aelbuni.medium.com/modeling-topics-in-quran-using-machine-learning-nlp-b88ca23fb44d?source=rss-8d05031118f8------2</link>
            <guid isPermaLink="false">https://medium.com/p/b88ca23fb44d</guid>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[word2vec]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[quran]]></category>
            <dc:creator><![CDATA[Abdurrahman Elbuni]]></dc:creator>
            <pubDate>Sun, 02 Dec 2018 07:05:05 GMT</pubDate>
            <atom:updated>2021-05-28T20:52:03.127Z</atom:updated>
            <content:encoded><![CDATA[<h3>Modeling Topics from The Nobel Quran using Machine Learning &amp; NLP</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*RE-P3xNt-u74Yw21HR-Dgw.png" /></figure><p>Have you ever wanted to learn more about Natural Language Processing (NLP), or been interested to learn how to train a Topic Modeling algorithm on a set of paragraphs to predict Topics from words and vice-versa? If your answer is yes, then hopefully this article will help you in your NLP learning journey.</p><p>In this article I am going to employ one of the contemporary algorithms published by Google researchers (Mikolov, Tomas, et al). “<a href="https://arxiv.org/pdf/1310.4546">Distributed representations of words and phrases and their compositionality</a>” (2013). The paper presents a word embedding model using a shallow Neural Network with one hidden layer that can be trained to reconstruct linguistic context of words.</p><p>To put this exercise in context, we are going to build an unsupervised learning algorithm to model topics from multiple verses from the Holy Book of Quran. To achieve that I will use a word2vec from <a href="https://radimrehurek.com/gensim/">Gensim </a>library to configure, train and build a model by scanning the entire Quran Bible end-to-end, verse by verse, and word by word.</p><p>The algorithm uses a moving window of 7 words to scan verses and identify the co-occurrence of words based on their frequency of appearance as neighbors, to accomplish that I used different hyperparameters for word embedding window and learning rate.</p><p>Let’s dive into the code. I will explain the process backwardly this time to share the results first and make it more interesting to follow. So, let’s start with showing you some results of the algorithm; then, we will continue to know how the model was trained and deployed.</p><p>The following results was been generated from running the algorithm to find a context based on passing a single word as an input, which is a technique that is also called <a href="https://towardsdatascience.com/word2vec-skip-gram-model-part-1-intuition-78614e4d6e0b">skip-gram</a> method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4OBt7kNX_765jgvQ6NwpKA.png" /></figure><p>In the following examples, for each input word we will print a <strong>wordcloud </strong>that contains the top 80 words occurred in a similar context.</p><h3>Example 1 — Passing `موسى` `moses` to the trained model</h3><p>When the algorithm reads `<strong>Moses</strong>` as an input word word to our model, the algorithm acquired set of neighboring words (80) that was mentioned frequently in similar context. To mention few of them (Israel, Noah, Merry, Lot, John, Believers, Righteous, Tribes, etc). Again, the illustrated <strong>wordcloud </strong>below contains all of the words in the Quran that has the highest likelihood to appear around the word ‘<strong>Moses</strong>’ .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XS9adNgOWTrWT0dwYMX2RA.png" /><figcaption>Passing `Moses` as an input word</figcaption></figure><h3>Example 2— Passing `جنة` `heaven` to the trained model</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2AhliKMKP3hKV1eW1LaQFw.png" /><figcaption>Passing `heaven` as a word</figcaption></figure><h3>Prerequisites for building the project</h3><ul><li>You need to have Python installed</li><li>Download csv digital version of the <a href="https://www.kaggle.com/zusmani/the-holy-quran#Arabic-Original.csv"><strong>Holy Quran</strong></a></li><li>Install (<a href="https://radimrehurek.com/gensim/"><strong>gensim</strong>)<strong> </strong></a>library to be able to use word2vec algorithm</li><li>Install Natural Language Toolkit for Python (<a href="https://www.nltk.org/"><strong>nltk</strong></a>) for download stop-words for Arabic, and use its Arabic word stemmer.</li><li>Install <a href="https://pypi.org/project/python-bidi/"><strong>bi-directional</strong></a> and <a href="https://pypi.org/project/arabic-reshaper/"><strong>arabic_reshaper </strong></a>libraries to support Arabic Text visualization</li><li>Install (<strong>pandas</strong>)<strong> </strong>for loading and transforming data using Dataframe libraries</li><li>Install (<a href="https://scikit-learn.org/stable/"><strong>scikit</strong>)<strong> </strong></a>library to be able to visualize embedding using PCA algorithm</li><li>Install (<a href="https://github.com/amueller/word_cloud"><strong>wordcloud</strong></a>) plugin to visualize word similarities in a form of cloud.</li><li>All you need to do is to checkout the opensource python project and install dependencies from requirements.txt file</li></ul><h3>Explaining the Code &amp; Machine Learning Pipeline</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*6fA7hg2VHX55dK4MCkSTGw.png" /><figcaption>ML Pipeline for Building the Word Representation Model</figcaption></figure><p><strong>1. Reading the verses from a digitized version of the Quran as a Dataframe</strong></p><pre># Download Arabic stop words Dataset from NLTK library <br>nltk.download(&#39;stopwords&#39;)</pre><pre># Extract Arabic stop words<br>arb_stopwords = set(nltk.corpus.stopwords.words(&quot;arabic&quot;))</pre><pre># Initialize Arabic stemmer<br>st = ISRIStemmer()</pre><pre># Load Quran from csv into a dataframe<br>df = pd.read_csv(&#39;data/arabic-original.csv&#39;, sep=&#39;|&#39;, header=&#39;infer&#39;);</pre><p><strong>2. Verse tokenization</strong></p><p>Breakout words from each verse and map each verse to a vector with set of corresponding word elements</p><pre># Tokinize words from verses and vectorize them<br>df[&#39;verse&#39;] = df[&#39;verse&#39;].str.split()</pre><p><strong>3. Removing stop words to only select words with important meaning</strong></p><pre># Remove Arabic stop words<br>df[&#39;verse&#39;] = df[&#39;verse&#39;].map(lambda x: [w for w in x if w not in arb_stopwords])</pre><p><strong>4. Remove Harakat (Hyphenation)</strong></p><p>Removing Harakat will help us reduce the combination of words that belong to the same verb.</p><pre># Remove harakat from the verses to simplify the corpus<br>df[&#39;verse&#39;] = df[&#39;verse&#39;].map(lambda x: re.sub(&#39;[ًٌٍَُِّۙ~ْۖۗ]&#39;, &#39;&#39;, x))</pre><p><strong>5. Start training and building the Word2vec model</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*kaY8HUOuNqcBp6ypEIrheA.png" /><figcaption>Presentation of the last state of verses variable after filtering our words and before we pass it to the model</figcaption></figure><p>In the above figure you can see the last state of the List variable verses after the vectors passed to the filtration pipeline (Verse Tokinization, Remove Stop Words, &amp; Remove Harakaat), so now verses list is in its last reduced form, and ready to be passed to our model for training.</p><p>Feel free to play around with hyperparameters, as they might impact the model either negatively or positively. The best parameters I personally found is used in the following code snippet. To understand the parameters more, please read the (<a href="https://radimrehurek.com/gensim/models/word2vec.html#gensim.models.word2vec.Word2Vec">Documentation</a>). Note I am passing min_count=15, which dictate the model to ignore all of the words that has frequency count less than 15. Feel free to change it to increase or decrease the size of the generated vocabulary.</p><pre># You can filter for one surah too if you want!<br>verses = df[&#39;verse&#39;].values.tolist()</pre><pre># train the model<br>model = Word2Vec(verses, min_count=15, window=7, workers=8, alpha=0.22)</pre><h3>Custom Model Visualization Library</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ww_s_H1uPoxdDlkLeaOqNw.png" /><figcaption>Visualizing Word Vectors after applying PCA</figcaption></figure><p>The model generated should contain the vector representation of all words we input. To be able to visualize the vector representation and see which word is closer in terms of co-occurrence and context to other words, we need to reduce the dimensions we have from a matrix of size (549x100)model[model.wv.vocab]. Accomplishing that requires dimensionality reduction algorithm like PCA, and the next snippet of code shows you exactly how I used PCA to reduce a vector representation with the size of (549x100) into (549x2) to be able to visualize the entire vocabulary in a (2-D) graph shown above.</p><pre># fit a 2d PCA model to the vectors<br>X = model[model.wv.vocab]<br>pca = PCA(n_components=2)<br>result = pca.fit_transform(X)</pre><pre># create a scatter plot of the projection<br>plt.scatter(result[:, 0], result[:, 1])<br>words = list(model.wv.vocab)</pre><pre># Pass list of words as an argument<br>for i, word in enumerate(words):<br>    reshaped_text = arabic_reshaper.reshape(word)<br>    artext = get_display(reshaped_text)<br>    plt.annotate(artext, xy=(result[i, 0], result[i, 1]))<br>plt.show()</pre><h3>Code in Github</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/0*McIXvRzX4AKQCeKn.png" /></figure><p><a href="https://github.com/aelbuni/quran-nlp">https://github.com/aelbuni/quran-nlp</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b88ca23fb44d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>