<?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 Ibrahim LAHLOU on Medium]]></title>
        <description><![CDATA[Stories by Ibrahim LAHLOU on Medium]]></description>
        <link>https://medium.com/@IbLahlou?source=rss-2d2b091f1f66------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*NkKJjMc0REPeoQE7ENAv1A.jpeg</url>
            <title>Stories by Ibrahim LAHLOU on Medium</title>
            <link>https://medium.com/@IbLahlou?source=rss-2d2b091f1f66------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 11:47:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@IbLahlou/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[The Machine Under ML Workload: What Really Happens When You Run a Neural Network]]></title>
            <link>https://medium.com/@IbLahlou/the-machine-under-ml-workload-what-really-happens-when-you-run-a-neural-network-4a1842bd2554?source=rss-2d2b091f1f66------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a1842bd2554</guid>
            <category><![CDATA[cuda]]></category>
            <category><![CDATA[gpu]]></category>
            <category><![CDATA[compilers]]></category>
            <dc:creator><![CDATA[Ibrahim LAHLOU]]></dc:creator>
            <pubDate>Wed, 03 Jun 2026 16:49:22 GMT</pubDate>
            <atom:updated>2026-06-03T16:52:56.376Z</atom:updated>
            <content:encoded><![CDATA[<p><em>You write three lines of PyTorch. Then an iceberg moves.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*L_yDGaZsGLIwrbzT" /></figure><blockquote>There’s a moment every ML practitioner knows. You call model.fit(), your terminal prints some reassuring numbers, and somewhere in the back of your mind a quiet question forms — <em>what is actually happening right now?</em></blockquote><p>The honest answer is: a lot. More than most tutorials let on.</p><p>Modern ML tooling is a masterclass in hiding complexity. Decades of systems engineering — operating systems theory, computer architecture, high-performance networking — all compressed behind an API so clean it almost feels like cheating. And most of the time, that’s fine. The abstraction works.</p><p>Until it doesn’t.</p><p>When your GPU sits at 3% utilization during training, when VRAM explodes on a batch size you’ve run a hundred times before, when scaling to four machines makes everything <em>slower</em> — you’ve hit the bottom of the abstraction. And at that point, “just use PyTorch” won’t save you.</p><p>Here’s what will: understanding the stack underneath.</p><p>This isn’t a history lesson. Every layer in this post is a place where bugs hide, where performance silently collapses, where a version mismatch can cost you three days. The engineers who debug fast aren’t the ones who know more PyTorch — they’re the ones who know which layer to look at.</p><p>Let’s walk it, ground up.</p><h3>The Stack Nobody Teaches You</h3><p>ML infrastructure didn’t appear from nowhere. It’s built on foundations that predate deep learning by decades — Unix process models, virtual memory, PCIe bus architecture, distributed systems primitives from the HPC world. PyTorch didn’t replace any of that. It <em>inherited</em> it, wrapped it in new abstractions, and repurposed it for matrix multiplication at scale.</p><p>The stack, from bottom to top, looks like this:</p><pre>┌─────────────────────────────────┐<br>│         Your Python Code        │<br>├─────────────────────────────────┤<br>│      PyTorch / JAX / TF         │<br>├─────────────────────────────────┤<br>│   nvcc / NVRTC / Triton DSL     │<br>├─────────────────────────────────┤<br>│       CUDA Toolkit + Driver     │<br>├─────────────────────────────────┤<br>│     OS Kernel + GPU Driver      │<br>├─────────────────────────────────┤<br>│    PCIe / NVLink / Interconnect │<br>├─────────────────────────────────┤<br>│         GPU Silicon             │<br>└─────────────────────────────────┘</pre><p>Each layer owns something specific. Each layer can fail independently. And when something goes wrong — which it will — the bug lives in exactly one of these floors. The skill is knowing which one.</p><h3>1. The Driver: Your OS Learning to Speak GPU</h3><p>Before your code can run a single matrix multiply, the operating system needs to <em>know your GPU exists</em>. That’s the driver’s job — and it’s more interesting than it sounds.</p><p>A GPU driver isn’t just software you install to make games work. It’s a <strong>kernel module</strong>: code that runs in the deepest, most privileged part of your OS and teaches it to speak a new hardware dialect. On Linux, when the system boots, the kernel walks the PCIe bus — think of it as the highway connecting your CPU to all expansion devices — finds a GPU with a matching hardware signature, and loads the corresponding driver module. From that moment on, your GPU is accessible as a simple file: /dev/nvidia0.</p><p>What people call “the NVIDIA driver” is actually <strong>four cooperating modules</strong>, each owning one concern:</p><p>Module Responsibility nvidia.ko Core: command submission, on-GPU scheduler, VRAM management nvidia_uvm.ko Unified Virtual Memory — CPU and GPU share one address space nvidia_drm.ko Hooks into Linux&#39;s display rendering stack nvidia_modeset.ko Resolution, refresh rate, multi-monitor configuration</p><p>AMD takes a cleaner approach: everything lives in a single amdgpu.ko. Same result, fewer moving parts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CrJEA6AuCKIde9KD" /></figure><p>You can inspect all of this directly from your terminal:</p><pre>lsmod | grep nvidia          # which modules are loaded right now<br>ls /dev/nvidia*              # device nodes userspace can open<br>nvidia-smi topo -m           # full GPU-to-GPU topology map<br>cat /proc/driver/nvidia/version  # driver self-report</pre><h3>The CUDA Version Trap</h3><p>One thing trips up almost everyone at some point, so let’s be explicit about it. <strong>“CUDA” is actually two separate things with two separate version numbers.</strong></p><p>There’s the <strong>CUDA toolkit</strong> — the headers, compiler, and runtime library you install on your machine. And there’s the <strong>kernel-mode driver</strong> — the compute engine baked into the GPU driver itself. They version independently, and there’s exactly one rule:</p><blockquote><strong><em>Driver version ≥ Toolkit version. Always. Without exception.</em></strong></blockquote><p>Newer driver, older toolkit — fine. Older driver, newer toolkit — broken, often in ways that look like model bugs.</p><pre>nvidia-smi      # shows the driver&#39;s maximum supported CUDA version<br>nvcc --version  # shows the toolkit version your code compiles against</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WV_P4KwyF6SGul_Z" /></figure><p>One more operational detail worth knowing: by default, NVIDIA’s driver unloads itself when no CUDA process is running, and reloads when the next one starts. During a long training run, you’ll never notice. But if you’re serving a model endpoint with sporadic traffic — say, a low-traffic internal tool — every cold request pays a 1–3 second reload penalty. Fix it once:</p><h3>1.1 A Field Guide to GPU Names</h3><p>Driver output will eventually print something like NVIDIA A100-SXM4-80GB at you, and it helps to know what you&#39;re reading. These strings aren&#39;t arbitrary — they encode the generation, market segment, board form factor, and memory tier.</p><p>NVIDIA names its architectures after mathematicians and physicists. Here’s the modern lineage that matters for ML:</p><p>Architecture Year Datacenter Consumer Volta 2017 V100 Titan V Turing 2018 T4 RTX 20xx Ampere 2020 A100, A40, A10 RTX 30xx Ada Lovelace 2022 L4, L40, L40S RTX 40xx Hopper 2022 H100, H200 <em>(datacenter-only)</em> Blackwell 2024 B100, B200 RTX 50xx <strong>Rubin</strong> <strong>2026</strong> <strong>R100 (VR200)</strong> <em>(datacenter-only, H2 2026)</em></p><blockquote><em>📸 </em><strong><em>[ILLUSTRATION 4 — ARCHITECTURE TIMELINE]</em></strong><em> </em>Place after the table. Full-width horizontal timeline.</blockquote><blockquote><strong><em>Qwen prompt:</em></strong><em> </em><em>Horizontal timeline illustration of NVIDIA GPU architectures, left to right. Each generation is a glowing circle node connected by a line. Node labels, top line (architecture + year): &quot;Volta 2017&quot;, &quot;Turing 2018&quot;, &quot;Ampere 2020&quot;, &quot;Ada 2022&quot;, &quot;Hopper 2022&quot;, &quot;Blackwell 2024&quot;, &quot;Rubin 2026&quot;. Bottom line (flagship model): &quot;V100&quot;, &quot;T4&quot;, &quot;A100&quot;, &quot;H100&quot;, &quot;H200&quot;, &quot;B200&quot;, &quot;VR200&quot;. Color gradient from cool steel blue on the left to warm bright amber on the right. Dark background, clean sans-serif font, last node (Rubin) slightly larger and glowing to indicate &quot;current frontier&quot;. Editorial style.</em></blockquote><p>A few naming patterns worth internalizing before reading any benchmark or job posting:</p><p><strong>A/H/B/R-series (datacenter):</strong> the architecture letter brands the chip. A100 = Ampere, H100 = Hopper, B200 = Blackwell, and now VR200 = Vera Rubin. The trailing number is the tier — 100/200 is flagship, 40 is midrange, 10 is inference-focused.</p><p><strong>RTX (consumer):</strong> from Turing onward. The decade digit tells you the generation — RTX 4090 = Ada Lovelace (40-series), RTX 5090 = Blackwell (50-series).</p><p><strong>L-series (Ada inference):</strong> the L4 runs at 72W in a single PCIe slot and sits in half the cloud inference fleet you interact with daily. Remarkable price-per-token for smaller models.</p><p><strong>-800 suffix:</strong> China-export variants (A800, H800) with NVLink bandwidth capped to comply with US export controls. Same die, constrained interconnect — meaningfully different at scale.</p><p><strong>SXM vs PCIe:</strong> not a GPU difference but a board form factor. SXM is a proprietary socket enabling NVLink and higher power delivery. An H100-SXM5 and an H100-PCIe have the same GPU but very different interconnect bandwidth — which matters enormously for multi-GPU training.</p><p><strong>AMD:</strong> the compute split is clean. Everything consumer is <strong>RDNA</strong> (gaming-optimized). Everything datacenter is <strong>CDNA</strong> — it drops the graphics hardware entirely and uses that die area for more compute and HBM controllers. The MI300X (CDNA3, 192GB HBM3) is genuinely competitive with H100. The MI355X (CDNA4) is shipping now.</p><p><strong>Apple Silicon:</strong> its own category. No discrete driver — GPU and CPU share unified memory on the same die, accessed through Metal or MLX. An M4 Max with 128GB unified memory holds a 70B model in 4-bit quantization with every weight accessible at ~500 GB/s. No consumer NVIDIA card matches that memory capacity at any price. Different tradeoffs, but real ones for inference at the edge.</p><h3>2. The Compiler Layer: From Python to Machine Code</h3><p>Making the GPU addressable was step one. Step two is getting your <em>code</em> to actually run on it — and this is where things get genuinely interesting.</p><p>GPUs run their own instruction set. Your CPU speaks x86 or ARM. Your GPU speaks something completely different. There’s a compiler chain that crosses the gap, and for NVIDIA, three tools participate — often simultaneously in the same training run.</p><blockquote><em>📸 </em><strong><em>[ILLUSTRATION 5 — THREE COMPILERS]</em></strong><em> </em>Place before the compiler descriptions. Medium width.</blockquote><p><strong>nvcc</strong> — the classic ahead-of-time compiler. Invoked at build time when you compile a CUDA project. If you&#39;ve ever run make on a CUDA repo, you&#39;ve used nvcc.</p><p><strong>NVRTC</strong> — a runtime compiler baked into a library (libnvrtc.so). Takes a CUDA C++ string <em>in memory</em> and compiles it to GPU code while your program is running. This is how torch.compile can generate a new kernel for each unique tensor shape without you ever restarting Python.</p><p><strong>Triton DSL</strong> — a Python-embedded language for writing GPU kernels without touching CUDA C++ directly. Flash Attention, Mamba, most of vLLM’s custom ops — these are Triton kernels. It’s where most novel ML kernel work happens today.</p><p>A modern PyTorch training run touches all three, often without you noticing.</p><h3>2.1 How nvcc Actually Works — The Host/Device Split</h3><p>A .cu file contains two completely different things living in the same text file: <strong>host code</strong> (regular C++ that runs on your CPU, sets up data, launches kernels) and <strong>device code</strong> (functions marked __global__ that run on the GPU). The CPU and GPU have different instruction sets and different memory spaces. Neither compiler understands the other&#39;s half. nvcc plays traffic cop:</p><p>Two intermediate forms appear in that pipeline constantly — in error messages, profiler output, and documentation:</p><p><strong>PTX</strong> (Parallel Thread eXecution) — NVIDIA’s virtual instruction set, architecture-independent. Like LLVM IR or JVM bytecode: not what the hardware runs, but a portable intermediate that can be compiled to anything.</p><p><strong>SASS</strong> (Streaming Assembler) — actual GPU machine code, specific to one GPU architecture. This is what the silicon executes.</p><p><strong>fatbin</strong> — a “fat binary” container wrapping multiple SASS targets plus a PTX fallback in one artifact, allowing one binary to run across multiple GPU generations.</p><p>PTX exists for <strong>forward portability</strong>: SASS compiled for an A100 cannot run on an H100. But PTX can be JIT-compiled at runtime to SASS for whatever GPU is present. This is why a PyTorch wheel built against CUDA 11.8 still runs on a Blackwell GPU — the driver finds the embedded PTX, compiles it on the fly (a one-time 1–5 second pause), and caches the result.</p><p>Each GPU architecture has a <strong>compute capability</strong> version:</p><p>GPU Compute Capability V100 sm_70 T4 / RTX 20xx sm_75 A100 sm_80 RTX 4090 / L40S sm_89 H100 / H200 sm_90 B100 / B200 sm_100 RTX 50xx sm_120</p><p>A production build embeds native SASS for every GPU you care about, plus a PTX fallback for future hardware:</p><pre>nvcc -O3 \<br>  -gencode arch=compute_80,code=sm_80 \       # A100 native SASS<br>  -gencode arch=compute_90,code=sm_90 \       # H100 native SASS<br>  -gencode arch=compute_90,code=compute_90 \  # PTX fallback for future GPUs<br>  kernel.cu -o app</pre><p>One flag that pays dividends during kernel tuning: -Xptxas -v. It prints per-kernel <strong>register count</strong> and <strong>shared memory footprint</strong>, which directly determines <strong>occupancy</strong> — the ratio of active warps to the maximum the SM can hold.</p><p>A warp is 32 threads executing the same instruction simultaneously (this is called SIMT — Single Instruction, Multiple Threads). High occupancy means more warps available to cover memory latency: when one warp stalls waiting for a memory fetch, another runs. Low occupancy means the SM sits idle. Register pressure and shared memory usage are the two knobs that control it.</p><pre>nvcc -Xptxas &quot;-v,-O3&quot; kernel.cu   # prints reg count + shared mem per kernel</pre><h3>2.2 NVRTC: Compiling Kernels While Your Program Runs</h3><p>nvcc works great for code that’s fixed at build time. The problem is that modern frameworks aren’t fixed — torch.compile synthesizes a different kernel for every unique combination of tensor shapes and dtypes. You can&#39;t know at build time what kernels you&#39;ll need.</p><p>NVRTC solves this. It takes a CUDA C++ string, compiles it to PTX in-process — no subprocess, no temp files — and hands it back so the driver can JIT-compile to SASS for the current GPU.</p><p>The cost is one compilation per unique kernel per process, ranging from milliseconds to seconds. Both PyTorch and CUDA cache these aggressively:</p><pre>~/.cache/torch/inductor      # PyTorch kernel cache<br>~/.nv/ComputeCache           # CUDA JIT cache</pre><p>If you’ve ever noticed that the first epoch after a PyTorch upgrade runs noticeably slower — that’s the cache cold-starting. Every kernel that was compiled against the old version gets recompiled for the new one. It’s not a bug. It’s expected. It only hurts once.</p><h3>2.3 Triton: The Right Level of Abstraction</h3><p>CUDA C++ forces you to manage warps, shared memory, and tensor cores by hand. It’s powerful and exhausting. PyTorch ops are convenient but too coarse — you can’t fuse operations across operator boundaries or implement custom attention variants without dropping all the way down to CUDA C++.</p><p>Triton (originally from OpenAI, now widely used across the ecosystem — distinct from NVIDIA’s Triton Inference Server) sits in the middle. You write kernels as operations on <em>tiles</em> of data, and the compiler handles warp scheduling, shared memory allocation, and tensor core dispatch.</p><pre>import triton<br>import triton.language as tl</pre><pre>@triton.jit<br>def add_kernel(x_ptr, y_ptr, out_ptr, n_elements, BLOCK_SIZE: tl.constexpr):<br>    pid = tl.program_id(axis=0)<br>    offsets = pid * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)<br>    mask = offsets &lt; n_elements<br>    x = tl.load(x_ptr + offsets, mask=mask)<br>    y = tl.load(y_ptr + offsets, mask=mask)<br>    tl.store(out_ptr + offsets, x + y, mask=mask)</pre><p>Under the hood: Triton IR → PTX → SASS. Same backend as nvcc. The abstraction just hides the warp-level machinery.</p><p>Flash Attention’s reference implementation, Mamba, the bulk of vLLM’s custom kernels, most of what torch.compile generates — all Triton. If you&#39;re writing a custom attention mechanism, a fused normalization layer, or anything that doesn&#39;t fit neatly into existing PyTorch ops, Triton is the right tool.</p><h3>3. The Stack in 2026: Where Each Layer Is Heading</h3><p>The architecture you just read isn’t static. Right now, in the middle of 2026, every layer of this stack is moving — and the movements are large enough to matter for anyone making infrastructure decisions.</p><h3>The Datacenter: Vera Rubin and the End of Blackwell’s Reign</h3><p>Blackwell shipped in 2025 and was sold out through mid-2026 with a backlog of millions of units. Its successor, <strong>Vera Rubin</strong>, is now confirmed for H2 2026 — and the performance jump is not incremental.</p><p>The Rubin R100 GPU packs 336 billion transistors across a dual-die design, moves from HBM2e/HBM3 to <strong>HBM4</strong>, delivers up to 288GB of memory per GPU, and hits 22 TB/s of memory bandwidth — compared to roughly 3.35 TB/s on an H100. That’s not a refinement. It’s a different class of machine.</p><p>The NVL72 rack-scale system pairs 72 Rubin GPUs with 36 Vera CPU dies (88 ARM cores each) connected by NVLink 6, targeting training runs and long-context inference workloads that need to treat hundreds of GPUs as one logical device.</p><p>For the ML practitioner: <strong>the architecture concepts in this post — driver modules, compute capability, PTX forward compatibility — all carry forward to Rubin</strong>. The sm_XX number changes (Rubin introduces sm_100+ variants), the JIT pipeline remains the same, the fatbin approach remains the same. What changes is the performance envelope and the memory bandwidth at which the bottlenecks shift.</p><h3>The Laptop/Edge: RTX Spark and the Unified Memory Bet</h3><p>The RTX Spark (chip codename N1X) is NVIDIA’s answer to Apple Silicon — an ARM-based SoC combining a 20-core Grace CPU, a Blackwell GPU with 6,144 CUDA cores, and up to 128GB of unified LPDDR5X memory on TSMC’s 3nm process, delivering 1 petaflop of FP4 AI performance locally.</p><p>The key architectural difference from everything else in this post: there’s no discrete GPU with its own VRAM. CPU and GPU share one memory pool over NVLink C2C, much like Apple’s approach — except with full CUDA compatibility. A 70B model in 4-bit quantization fits entirely in memory, with no PCIe bandwidth bottleneck between compute and weights.</p><p>Laptops from Dell, HP, Lenovo, ASUS, MSI, and Microsoft’s Surface Laptop Ultra ship fall 2026. Jensen Huang also hinted at “a surprise new product” for H2 2026 that hasn’t been announced yet.</p><h3>The Software Stack: NemoClaw and the CUDA Moat</h3><p>The least-discussed but strategically most significant announcements are on the software side. CUDA’s 18-year head start is one competitive moat. NVIDIA is now adding three more:</p><p><strong>NemoClaw</strong> — an open-source blueprint for building agentic AI workflows, positioning NVIDIA as the infrastructure layer for the “always-on AI agent” wave.</p><p><strong>DSX (Data Center Software Experience)</strong> — an AI factory operating system, open-sourced, with DSX MaxLPS claiming 40% more effective GPU utilization within the same power budget. For operators running large clusters, that’s a meaningful efficiency unlock without new hardware.</p><p><strong>CUDA 13</strong> — shipping on Jetson Orin now, with broader rollout as Rubin-class hardware hits. The compiler pipeline described in §2 gains new intrinsics for HBM4 memory access patterns and Rubin’s updated tensor core architecture.</p><h3>The Point</h3><p>None of this is trivia.</p><p>Every layer described in this post is a place where performance collapses silently, where a version mismatch burns a debugging day, where a hardware decision made six months ago constrains what your software can do today.</p><p>The ML abstraction is extraordinarily well-built. But it’s still an abstraction. When it leaks — and it will — knowing the names and responsibilities of the layers underneath is the difference between a five-minute fix and a three-day debugging session.</p><blockquote>And as of 2026, that infrastructure is in its fastest period of change since CUDA launched in 2007. Vera Rubin rewrites the datacenter performance envelope. RTX Spark collapses the CPU-GPU boundary on the edge. NemoClaw turns software into a moat. The stack is moving — and now you know which floors are shifting.</blockquote><p><em>Next: memory hierarchy, NUMA topology, and why your A100 is sometimes waiting on your CPU.</em></p><p><em>If this was useful, follow for the next part. The deeper you go, the more control you get.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a1842bd2554" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Entanglement in Machine Learning Models and the “CACE Principle”]]></title>
            <link>https://medium.com/@IbLahlou/entanglement-in-machine-learning-models-and-the-cace-principle-e9734405f74f?source=rss-2d2b091f1f66------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9734405f74f</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[entanglement]]></category>
            <category><![CDATA[mlops]]></category>
            <category><![CDATA[correlation]]></category>
            <category><![CDATA[causation]]></category>
            <dc:creator><![CDATA[Ibrahim LAHLOU]]></dc:creator>
            <pubDate>Thu, 21 Nov 2024 21:04:04 GMT</pubDate>
            <atom:updated>2024-11-21T21:04:04.670Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>There’s a problematic approach to improvement where people seeking result-oriented solutions, like using LLMs, wish to have their code ready in a single prompt. However, they face changes frequently, and when they do, they may let their model overfit to a result due to memorization. The problem isn’t just with the code or what they consistently want — did they use a better approach to update their code? For this, there are solutions like modular design or abstraction that can express strong invariance and allow prompts to span multiple sessions.</p><p>When we move to machine learning, we can effectively use ensemble boosting or multitask learning to help with modular design. However, with abstraction, we encounter problems, particularly with highly imbalanced datasets or when data is very detailed. We typically use ML when the task is too complex or dynamic to be handled by traditional if-then rules, and when we have data that can teach the system the right behavior.</p><p>This is because software logic depends on external data — that’s the exhaustive set of rules where we have everything in its designated spot. However, in reality, items often belong in multiple categories, serve multiple purposes, or don’t fit neatly anywhere.</p><p>We can say that the best model isn’t one that simply achieves the highest easy-to-calculate metric, but rather one that allows us to improve gradually through explanation. This enables data scientists to understand its behavior and decisions, leading to better explanations regardless of the problem. Mathematics and mathematical modeling are the best solutions, not just an arbitrary set of neural networks that can’t be understood or consciously improved.</p><h3>In Literature</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*pHW_GpMHJrDKY4Bl50VxwQ.png" /><figcaption>Visual distinction between Entanglement, Correlation, and Causality using colored ball , Same state (Entanglement), Change together (Correlation), One causes other (Causality)”</figcaption></figure><p>Entanglement often describes complex, intertwined relationships or situations characters can’t easily escape from — like a romantic entanglement between lovers who keep getting drawn back to each other despite trying to separate, or families entangled in generations-old feuds. Correlation typically appears in describing subtle patterns or echoes in narrative, like how weather might mirror a character’s mood. Causation is the most straightforward, used to trace how one event leads to another in plot development, like how a character’s childhood trauma causes their adult behavior or how a small decision snowballs into major consequences.</p><h3>In Machine Learning</h3><p>In machine learning, entanglement refers to the complex inter-dependencies between features, where modifying one feature can affect the behavior of others. This phenomenon is captured by the “CACE Principle” (Changing Anything Changes Everything) also called “cake” principle 🎂, which highlights how altering any feature can influence the model’s overall predictions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8fYsYIe88nXBBB0U" /></figure><p>Machine learning models use a set of features x1, x2, … , xn , and the relationships between them are often non-linear. Any change, such as shifts in input distribution, adding new features, or removing existing ones, can disrupt the model’s learned dynamics.</p><h3>Types of Feature Changes:</h3><ul><li><strong>Input Distribution Change</strong>: A shift in how feature values are distributed can alter the model’s weighting of other features.</li><li><strong>Adding a New Feature </strong>: Introducing new data alters the balance of the model, potentially impacting existing features.</li><li><strong>Removing a Feature</strong>: Excluding a feature forces the model to redistribute its reliance on remaining features, often unpredictably.</li></ul><h3>Mitigation Strategies:</h3><ul><li><strong>Feature Interaction Monitoring</strong>: Track how features affect one another to detect potential issues early.</li><li><strong>Regularization</strong>: Use techniques like L1/L2 regularization to control feature influence.</li><li><strong>Retraining</strong>: Regularly retrain the model after any changes to ensure stability.</li></ul><p>By recognizing and addressing feature entanglement, models can maintain accuracy and predictability even as features evolve.</p><h3>Workshop :</h3><p>1. Model Development</p><pre>import numpy as np<br>import pandas as pd<br>from sklearn.tree import DecisionTreeClassifier<br>from sklearn.model_selection import train_test_split<br>from sklearn.metrics import accuracy_score<br>  <br># Generate synthetic dataset<br>np.random.seed(42)<br>n_samples = 1000<br><br># Features: x1, x2, x3<br>x1 = np.random.normal(loc=0, scale=1, size=n_samples)  # Normally distributed feature<br>x2 = np.random.uniform(0, 1, size=n_samples)           # Uniformly distributed feature<br>x3 = np.random.poisson(lam=3, size=n_samples)          # Poisson distributed feature<br><br># Target variable (binary classification)<br>y = (x1 + x2 + x3 &gt; 3).astype(int)<br><br># Create a DataFrame<br>df = pd.DataFrame({&#39;x1&#39;: x1, &#39;x2&#39;: x2, &#39;x3&#39;: x3, &#39;y&#39;: y})<br><br># Train-test split<br>X = df[[&#39;x1&#39;, &#39;x2&#39;, &#39;x3&#39;]]<br>y = df[&#39;y&#39;]<br>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)<br><br># Train initial model<br>model = DecisionTreeClassifier(random_state=42)<br>model.fit(X_train, y_train)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*I3hvESTjmaEPtpYr" /></figure><h4>Initial Loss Function (Cross-Entropy Loss)</h4><p>The cross-entropy loss for a classification problem can be represented as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*COuD3z5U4SexXYCOgbTz3A.png" /></figure><p>2. Model Evaluation</p><pre>y_pred = model.predict(X_test)<br>print(f&quot;Initial Accuracy: {accuracy_score(y_test, y_pred):.4f}&quot;)</pre><pre>Initial Accuracy: 0.9433</pre><h4>Loss After Feature Modification</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1mmAM_h9EYcqvkdPvaoU2Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-DTMaw1Lo-feFOWzRseRKw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fswHfMxNvF5WDqQYVRbFrA.png" /></figure><p>3. Change 1: Shift in input distribution of x1</p><pre>X_test_shifted = X_test.copy()<br>X_test_shifted[&#39;x1&#39;] = X_test_shifted[&#39;x1&#39;] + 1  # Shift the distribution of x1<br><br>y_pred_shifted = model.predict(X_test_shifted)<br>print(f&quot;Accuracy after shifting x1: {accuracy_score(y_test, y_pred_shifted):.4f}&quot;)</pre><pre>Accuracy after shifting x1: 0.7833</pre><p>4. Change 2: Add a new feature (x4)</p><pre>X_train[&#39;x4&#39;] = np.random.normal(loc=0, scale=1, size=len(X_train))  # New feature x4<br>X_test[&#39;x4&#39;] = np.random.normal(loc=0, scale=1, size=len(X_test))<br><br>model_with_new_feature = DecisionTreeClassifier(random_state=42)<br>model_with_new_feature.fit(X_train, y_train)<br><br>y_pred_new_feature = model_with_new_feature.predict(X_test)<br>print(f&quot;Accuracy after adding new feature x4: {accuracy_score(y_test, y_pred_new_feature):.4f}&quot;)</pre><pre>Accuracy after adding new feature x4: 0.9433</pre><p>5. Change 3: Remove a feature (x2)</p><pre>X_train_reduced = X_train.drop(columns=[&#39;x2&#39;])<br>X_test_reduced = X_test.drop(columns=[&#39;x2&#39;])<br><br>model_with_removed_feature = DecisionTreeClassifier(random_state=42)<br>model_with_removed_feature.fit(X_train_reduced, y_train)<br><br><br>y_pred_removed_feature = model_with_removed_feature.predict(X_test_reduced)<br>print(f&quot;Accuracy after removing feature x2: {accuracy_score(y_test, y_pred_removed_feature):.4f}&quot;)</pre><pre>Accuracy after removing feature x2: 0.9200</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dn1dqExPtw13-2yezplWqA.png" /></figure><h3>Reference :</h3><ul><li>D. Sculley et al. « Hidden Technical Debt in Machine Learning Systems ». In : Advances in Neural Information Processing Systems (2015), p. 2503–2511.</li><li>Claude Sonnet 3.5</li><li>Myself designing the diagram in excalidraw</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9734405f74f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Virtualization in Unix-based system]]></title>
            <link>https://medium.com/@IbLahlou/virtualization-in-unix-based-system-a308b98c94d5?source=rss-2d2b091f1f66------2</link>
            <guid isPermaLink="false">https://medium.com/p/a308b98c94d5</guid>
            <category><![CDATA[unix]]></category>
            <category><![CDATA[gnu-linux]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[containerization]]></category>
            <category><![CDATA[virtualization]]></category>
            <dc:creator><![CDATA[Ibrahim LAHLOU]]></dc:creator>
            <pubDate>Mon, 24 Jun 2024 15:20:46 GMT</pubDate>
            <atom:updated>2024-06-24T16:17:30.938Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Virtualization in Unix-based systems, including Linux, involves creating and managing virtual instances of computing resources, such as hardware, storage, and network, allowing multiple isolated environments to run on a single physical machine. This process is achieved through a combination of kernel features, hypervisors, and various user-space tools. Here’s a detailed explanation of how virtualization works under the hood:</p><h3>0. What’s Virtualisation</h3><p>Virtualization is a technology that allows for the creation of multiple simulated environments or dedicated resources from a single physical hardware system. It involves the abstraction of physical resources — such as servers, storage devices, and network infrastructure — into virtual counterparts, which can be used and managed independently.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*_J3YeyU3Rd2P9Tg84YUMWw.png" /></figure><p>In Unix-based systems, virtualization enables the concurrent running of multiple isolated instances, often referred to as virtual machines (VMs) or containers, on a single physical machine, optimizing resource utilization and providing robust isolation and security. This process is facilitated by a combination of hardware-assisted features, hypervisors, kernel modules, and user-space tools.</p><h3>1. Hardware-Assisted Virtualization</h3><p>Modern processors support hardware-assisted virtualization features (Intel VT-x and AMD-V) that allow the efficient execution of multiple virtual machines (VMs).</p><ul><li><strong>VMX (Virtual Machine Extensions) and SVM (Secure Virtual Machine)</strong>: These extensions add new CPU modes to facilitate virtualization. The processor can switch between the host (root mode) and guest (non-root mode) execution contexts efficiently.</li><li><strong>VMCS (Virtual Machine Control Structure)</strong>: A data structure used by the CPU to manage the state of each virtual machine.</li></ul><h3>2. Hypervisors</h3><p>A hypervisor (virtual machine monitor) is software that creates and runs VMs. There are two types of hypervisors:</p><ul><li><strong>Type 1 (Bare-Metal)</strong>: Runs directly on the host’s hardware (e.g., VMware ESXi, Xen).</li><li><strong>Type 2 (Hosted)</strong>: Runs on a host operating system (e.g., VMware Workstation, VirtualBox).</li></ul><p><strong>KVM (Kernel-based Virtual Machine)</strong> is a Type 2 hypervisor integrated into the Linux kernel.</p><h4>KVM Workflow</h4><ol><li><strong>Loading the KVM Module</strong>:</li></ol><pre>sudo modprobe kvm sudo modprobe kvm_intel  # For Intel processors</pre><ol><li><strong>Creating a Virtual Machine</strong>:</li></ol><ul><li><strong>QEMU</strong>: A user-space emulator that works with KVM to provide hardware emulation.</li></ul><pre>qemu-system-x86_64 -enable-kvm -m 1024 -smp 2 -hda /path/to/disk_image.img</pre><p><strong>2. VMX Operations</strong>:</p><ul><li><strong>VMXON</strong>: Enables VMX operation.</li><li><strong>VMLAUNCH</strong>: Starts the guest execution.</li><li><strong>VMEXIT</strong>: Transfers control back to the hypervisor.</li></ul><h4>Creating virtual machines using CLI</h4><p>To create a VM using virt-install utility , you should first enable virtualization in the host system</p><p>Check if you have</p><ul><li>Good RAM memory amount and quality</li><li>Good CPU cores and frequency</li><li>Enough Disk Space</li><li>Other Driver needed</li></ul><p>All those resources values may vary significantly depending on the intended tasks and workload on the VMs</p><p>You should also let some resources to your host OS if you’re using an invited mode</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/1*RG_Jc0rnukWRhy6a9k6qYA.png" /></figure><h3>3. Containers</h3><p>Containers are a lightweight form of virtualization that provides process isolation through namespaces and resource control via cgroups (control groups).</p><h4>Namespaces</h4><p>Namespaces provide isolation for various system resources.</p><ul><li><strong>PID Namespace</strong>: Isolates process IDs.</li><li><strong>Network Namespace</strong>: Isolates network interfaces.</li><li><strong>Mount Namespace</strong>: Isolates file system mounts.</li><li><strong>User Namespace</strong>: Isolates user and group IDs.</li><li><strong>IPC Namespace</strong>: Isolates inter-process communication resources.</li></ul><p>Example using unshare:</p><pre>sudo unshare --mount --uts --ipc --net --pid --fork --user --map-root-user /bin/bash</pre><h4>Control Groups (cgroups)</h4><p>cgroups limit and isolate resource usage (CPU, memory, disk I/O, etc.).</p><ul><li><strong>Creating a cgroup</strong>:</li></ul><pre>sudo mkdir /sys/fs/cgroup/cpu/my_cgroup echo 50000 | sudo tee /sys/fs/cgroup/cpu/my_cgroup/cpu.cfs_quota_us echo $$ | sudo tee /sys/fs/cgroup/cpu/my_cgroup/tasks</pre><h4>Docker</h4><p>Docker simplifies container management and provides tools to build, ship, and run containers.</p><ul><li><strong>Running a Docker Container</strong>:</li></ul><pre>docker run -it ubuntu /bin/bash</pre><h3>4. Virtual Filesystems and Networking</h3><ul><li><strong>OverlayFS</strong>: A union mount filesystem that allows the creation of layers, which is used in Docker to provide image layering.</li><li><strong>Bridged Networking</strong>: Allows VMs and containers to be on the same network as the host, providing them with virtual network interfaces.</li></ul><h3>5. Memory Management</h3><p>Virtualization involves sophisticated memory management techniques:</p><ul><li><strong>Extended Page Tables (EPT) / Nested Page Tables (NPT)</strong>: Hardware features that map virtual memory addresses used by VMs to physical memory addresses, reducing the overhead of memory translation.</li></ul><h3>6. I/O Virtualization</h3><ul><li><strong>Virtio</strong>: A virtualization standard for network and disk device drivers, providing efficient and high-performance I/O operations in virtualized environments.</li></ul><h3>Example: Setting Up a KVM Virtual Machine</h3><p>Here’s a step-by-step example of setting up a VM using KVM and QEMU:</p><ol><li><strong>Install KVM and QEMU</strong>:</li></ol><pre>sudo apt-get install qemu-kvm libvirt-bin</pre><ol><li><strong>Verify Installation</strong>:</li></ol><pre>kvm-ok  # Check if your system supports KVM</pre><ol><li><strong>Create a Disk Image</strong>:</li></ol><pre>qemu-img create -f qcow2 /var/lib/libvirt/images/myvm.qcow2 10G</pre><ol><li><strong>Install an Operating System</strong>:</li></ol><pre>virt-install --name myvm --ram 1024 --disk path=/var/lib/libvirt/images/myvm.qcow2 --vcpus 1 --os-type linux --network bridge=virbr0 --graphics none --console pty,target_type=serial --location &#39;http://archive.ubuntu.com/ubuntu/dists/bionic/main/installer-amd64/&#39; --extra-args &#39;console=ttyS0,115200n8 serial&#39;</pre><h3>Conclusion</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*bAX-RH8xwTdIP6FCLD30sg.png" /></figure><p>Virtualization in Unix-based systems involves a complex interplay of hardware features, kernel modules, and user-space tools. It leverages hardware support for virtualization, kernel features like namespaces and cgroups, and powerful user-space tools like QEMU, KVM, and Docker to create isolated, efficient, and scalable computing environments. This architecture enables multiple virtual environments to coexist on a single physical machine, optimizing resource utilization and providing robust isolation and security.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a308b98c94d5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Overview of the Field of Artificial Intelligence]]></title>
            <link>https://medium.com/@IbLahlou/overview-of-the-field-of-artificial-intelligence-9a59d694866b?source=rss-2d2b091f1f66------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a59d694866b</guid>
            <category><![CDATA[overview]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[introduction]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Ibrahim LAHLOU]]></dc:creator>
            <pubDate>Fri, 21 Jun 2024 11:38:26 GMT</pubDate>
            <atom:updated>2024-06-21T11:38:26.395Z</atom:updated>
            <content:encoded><![CDATA[<p>Since its introduction in 1956, the term “Artificial Intelligence (AI)” has become familiar to many. However, the use and discussion of AI were primarily confined to scientific research or fiction films until the rapid rise of ChatGPT. Today, AI, particularly generative AI, has become a hot topic for everyone.</p><figure><img alt="Hierarchical Order of AI Domains" src="https://cdn-images-1.medium.com/max/392/1*Rs32u3ZJQ6OrUzGPlqAO_Q.png" /><figcaption><em>Figure 1: Hierarchical Order of AI Domains</em></figcaption></figure><p>Generative AI is a subset of deep learning, which itself is a subset of machine learning and symbolic AI. These are all subsets of AI, as illustrated below.</p><h4>Artificial Intelligence (AI)</h4><p>AI is a scientific and technological field aimed at creating machines capable of performing tasks that normally require human intelligence. These tasks can span various domains or types of data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VXQfuzxkhOI73anPrhmybA.png" /><figcaption><em>Figure 2: Classification of Data Types by Domain</em></figcaption></figure><h4>Symbolic AI</h4><p>Symbolic AI, also known as rule-based AI, is one of the oldest paradigms in AI. It uses formal rules and logic to manipulate symbols and solve problems. Expert systems, which use knowledge bases and human-defined rules, are an example of symbolic AI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*LXmfACbgnTHF-SVNJpovZg.png" /><figcaption>Figure 3: Diagram Explaining Rule-Based AI</figcaption></figure><h4>Expert Systems Overview</h4><p><strong>Definition</strong>: An expert system is a type of artificial intelligence designed to emulate the decision-making abilities of a human expert. It solves complex problems by reasoning through bodies of knowledge, primarily represented as if-then rules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*P745PiRY3Xfe_zSln9Ib4Q.png" /></figure><p><strong>Key Components :</strong></p><ul><li><strong>Knowledge Base</strong>: Contains domain-specific facts and rules.</li><li><strong>Inference Engine</strong>: Applies logical rules to the knowledge base to draw conclusions or make decisions.</li><li><strong>User Interface</strong>: Allows users to interact with the system, input data, and receive outputs.</li><li><strong>Explanation Facility</strong>: Explains the reasoning process and decisions of the system.</li><li><strong>Knowledge Acquisition Module</strong>: Assists in updating and maintaining the knowledge base.</li></ul><p><strong>How They Work :</strong></p><ol><li><strong>Input</strong>: User provides data or a query.</li><li><strong>Processing</strong>: The inference engine uses the knowledge base to process the input through reasoning.</li><li><strong>Output</strong>: The system provides a solution or recommendation and can explain the rationale.</li></ol><blockquote><strong>Advantages :</strong></blockquote><ul><li><strong>Consistency</strong>: Provides uniform answers to repetitive tasks.</li><li><strong>Efficiency</strong>: Handles large volumes of information and complex decisions.</li></ul><p><strong>Limitations :</strong></p><ul><li><strong>Knowledge Acquisition</strong>: Difficult and time-consuming to gather expert knowledge.</li><li><strong>Rigidity</strong>: Struggles with new, unforeseen situations.</li><li><strong>Maintenance</strong>: Keeping the knowledge base up to date can be challenging.</li></ul><p><strong>Example Process :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*G9H7J80d2yZpVBnEDZq1EA.png" /></figure><p>The process of transforming logical formulas in expert systems involves several key steps to enable automated reasoning. Starting with well-formed formulas, which naturally represent the knowledge provided by human experts, these formulas are initially expressed in a human-readable format, capturing complex logical relationships.</p><p>Next, the formulas are converted into prenex form, where all quantifiers are moved to the front, simplifying their structure for subsequent processing. Skolemization follows, eliminating existential quantifiers by introducing Skolem functions, thus reducing the logical expressions to a form that only contains universal quantifiers.</p><p>The final step is converting the formulas into clausal form, a standard format of conjunctions of disjunctions, which is essential for applying efficient automated reasoning techniques like resolution.</p><p>This transformation process ensures that the expert system can effectively reason about the knowledge base, facilitating decision-making in domains such as medical diagnosis or legal advice.</p><h4>Machine Learning</h4><p>Machine learning is a subset of AI that focuses on developing algorithms that enable machines to learn from data and improve their performance over time without being explicitly programmed for each specific task. It can be divided into several categories, including:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*q1kBJNx3YuCbbFmijyOzKg.png" /></figure><ul><li><strong>Supervised Learning</strong>: Models are trained on labeled data. For example, to predict product sales, a model is trained on a dataset containing product features (price, season, promotions, etc.) and corresponding sales (labels). The algorithm learns from this relationship to predict future sales of new products or products under different conditions</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*t6fII91gWLVlouHD0GD1uA.png" /></figure><ul><li><strong>Unsupervised Learning</strong>: Models find hidden structures in unlabeled data. For example, a clustering algorithm can segment products into different groups based on their sales characteristics without knowing the categories in advance. This can help identify trends or common behaviors among different products.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*8UiSvpEEaNx1yZWcl7AtiA.png" /></figure><ul><li><strong>Semi-Supervised Learning</strong>: Models use both labeled and unlabeled data to improve learning. For example, a model can be trained on a small labeled dataset of product sales (with known sales volumes) and a large unlabeled dataset of products. This allows the model to learn from known product trends and apply this knowledge to less known or new products.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/1*H4QeHGFAjBKmheduUzj5ig.png" /></figure><ul><li><strong>Reinforcement Learning</strong>: Models learn to make decisions by receiving rewards or punishments. For example, a stock replenishment agent in a store can learn to optimize stock levels based on past sales and demand forecasts. The agent receives rewards for maintaining optimal stock levels (reducing stockouts and minimizing excess) and penalties for decisions leading to sales losses or overstocking.</li></ul><h4>Deep Learning</h4><p>Deep learning uses artificial neural networks with many layers to model complex representations of sales data. For example, a convolutional neural network (CNN) can analyze product images to predict their popularity and future sales.</p><p>Similarly, a recurrent neural network (RNN) can be used to analyze seasonal trends and predict sales fluctuations over time. These techniques help businesses better understand the factors influencing sales and optimize their marketing strategies.</p><p>But wait a minute is any Neural Network model is a Deep Learning model ?</p><h4>Neural Network Models</h4><p>Neural networks are a class of models inspired by the human brain, designed to recognize patterns. They consist of layers of interconnected nodes (neurons), where each connection has an associated weight. Neural networks can be simple or complex, depending on the number of layers and neurons.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CO-8y2BZ9Sixrb6MfLPf5g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0y-wR6LXUenc2olDBRYv7Q.png" /></figure><h4>Deep Learning Models</h4><p>The main characteristics of deep learning models include:</p><ul><li><strong>Depth</strong>: They have multiple hidden layers (more than one or two). This depth allows them to learn more complex representations of the data.</li><li><strong>Complexity</strong>: They are capable of handling large amounts of data and complex tasks such as image recognition, natural language processing, and more.</li><li><strong>Computation</strong>: They require substantial computational power, often utilizing GPUs for training.</li></ul><h4>Differences</h4><ol><li><strong>Shallow Neural Networks</strong>: Neural networks with only one or two hidden layers are generally not considered deep learning models. These are often referred to as “shallow” neural networks.</li><li><strong>Deep Neural Networks</strong>: Neural networks with multiple hidden layers (typically more than three) are considered deep learning models. These models can learn hierarchical representations of data.</li></ol><h4>Examples</h4><ul><li><strong>Shallow Neural Network</strong>: A network with an input layer, one hidden layer, and an output layer. This might be used for simpler tasks like basic regression or binary classification.</li><li><strong>Deep Learning Model</strong>: A network with an input layer, several hidden layers (e.g., convolutional layers in CNNs, recurrent layers in RNNs), and an output layer. This might be used for complex tasks like image classification, language translation, or game playing (e.g., AlphaGo).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*566bclc8XvB_mbJZvmHmFg.png" /><figcaption><em>Figure 5: the Difference Between Neural Networks and Deep Learning Models</em></figcaption></figure><h4>Generative AI</h4><p>Generative AI creates new content based on existing data, which can be useful for predictive sales analysis. For example, generative adversarial networks (GANs) can generate product images to test consumer reactions before launching a product.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*fEda0zaHObk_ozt7qf1riw.png" /><figcaption><em>Figure 6: Example of a Generative Model (Generative Adversarial Network)</em></figcaption></figure><p>Transformers, such as GPT-4, can analyze customer reviews to generate optimized product descriptions that attract more customers. These applications allow businesses to test new ideas and adjust their offerings based on customer preferences.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a59d694866b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Parsing for Data Science Part | Web Scraping overview]]></title>
            <link>https://medium.com/@IbLahlou/data-parsing-for-data-science-part-web-scraping-overview-dc3ef9ded7eb?source=rss-2d2b091f1f66------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc3ef9ded7eb</guid>
            <category><![CDATA[web]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[data-scraping]]></category>
            <dc:creator><![CDATA[Ibrahim LAHLOU]]></dc:creator>
            <pubDate>Mon, 08 Jan 2024 20:54:20 GMT</pubDate>
            <atom:updated>2024-01-09T17:36:49.939Z</atom:updated>
            <content:encoded><![CDATA[<h3>Data Parsing for Data Science | Web Scraping overview</h3><h3>Introduction :</h3><p>Every data scientist requires data to perform their work. The process of collecting data can be challenging, especially when dealing with incompatible software or when a quick search for the required data is needed ,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*Zo4oeprnrUASaADYJX5fXg.png" /></figure><p>sometime we deal about some source of information like Kaggle , Google dataset search ,UCI machine learning repository and more</p><ul><li>What would be a viable solution to streamline this data acquisition process?</li></ul><p>One of the solution is to do data scraping, web scraping and data scraping or data parsing are often confused with each other, even though these two terms refer to distinct practices. In this dedicated article, we explore the true definition of web scraping and its various key stages: crawling, fetching, parsing, and storage.</p><h3>Domain-Specific Data Collection:</h3><p>Data scraping is employed across a wide range of domains to gather domain-specific datasets. Some common examples include:</p><h4>1. E-commerce :</h4><ul><li>Scraping product details, prices, and customer reviews from online marketplaces to analyze market trends, monitor competitors, or build recommendation systems.</li></ul><h4>2. Social Media:</h4><ul><li>Extracting posts, comments, and user information from social media platforms for sentiment analysis, user behavior studies, or identifying trending topics.</li></ul><h4>3. Research :</h4><ul><li>Collecting scientific papers, articles, and publications from academic websites to create datasets for research purposes.</li></ul><h4>4. Real Estate :</h4><ul><li>Scraping property listings, prices, and location details to analyze real estate market trends, assess property values, or build property recommendation systems for example we can use it in marketing or e-reputation .</li></ul><h4>5. Finance:</h4><ul><li>Retrieve financial data, stock prices, and economic indicators from various sources for market analysis, predictive modeling, or algorithmic trading.</li></ul><h3>What’s really Datascraping ?</h3><p>Datascraping is a rapid method for extracting information from a computer-program-generated, human-readable source. It serves as an interface to access data without an API, swiftly extracting and locally storing relevant information. This technique proves valuable when specific data is required from online sources without API access, offering an efficient way for automated data collection.</p><p>There are several types of data scraping :</p><ul><li><strong>Screen scraping </strong>:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fzWmQ3_l6NuB9Ckix9ZZ2Q.png" /><figcaption>How Screen Scraping works</figcaption></figure><p>This is a technique where a computer program extracts data from the display output of another program. It’s often used to capture old screens and transfer the data to modern front-ends. Screen scraping is normally associated with the programmatic collection of visual data from a source, instead of parsing data as in web scraping.</p><p>Like Blackbox , it’s an extension that extracts code from videos, preserving indentation and allowing code selection from anywhere on the screen. It’s useful for developers watching coding tutorials.</p><ul><li><strong>Report mining :</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f7CJAqZflpgDebhdp194Aw.png" /><figcaption>How Report Mining works</figcaption></figure><p>Report mining is a process that involves extracting and analyzing data from reports, typically in text file format. The goal is to transform the data from a static, unstructured format into a dynamic, structured format that can be easily understood and used for decision-making.</p><p>In the context of data mining, report mining can be seen as a specific application where the data to be mined is contained in reports. These reports could be in various formats such as PDFs, Word documents, or even web pages.</p><p>The extracted data can then be used for various purposes, such as identifying trends, making predictions, or informing strategic decisions. This makes report mining a valuable tool in fields like business intelligence, market research, and many others.</p><p>Like PBRS for Power BI that is a tool for scheduling your organization’s Power BI and SSRS Reports.</p><p><a href="https://www.capterra.com/reporting-software/">https://www.capterra.com/reporting-software/</a></p><ul><li><strong>Webscraping :</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cSE0xOOTGBq9ahGleEtdpg.png" /><figcaption>How Web Scraper works</figcaption></figure><p>Web scraping automates data extraction from websites using tools like DOM parsers. It involves retrieving text and media, This applies to various web page technologies, including JSP, Blade, JSX, etc, It’s possible to extract the data in HTTP or HTTPS and maybe also other protocols like FTP , The procedure of webscraping have 4 steps :</p><ul><li><strong>Crawling :</strong></li></ul><p>Web crawling is the process of systematically and automatically browsing the internet, typically performed by a program or script known as a web crawler or spider. The main purpose of it is to gather information from various websites by navigating through their pages, following links, and extracting relevant data.</p><p>It’s a fundamental step in web scraping, which involves extracting specific information from websites for various purposes such as data analysis, research, or creating datasets. The collected data can include text, images, links, and other structured or unstructured information present on web pages.</p><ul><li><strong>Fetching :</strong></li></ul><p>Fetching refers to the process of obtaining additional data from a server, either on the server side using a programming language like Python or on the client side using JavaScript and AJAX, to update and enhance the content of a webpage without requiring a full page reload.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R_Aw6MIQPHxWPdAioiPYCA.png" /><figcaption>How web client fetch html for the DOM</figcaption></figure><p>Web frameworks on the server side generate HTML responses that are sent to the browser. The browser, in turn, parses the HTML to create a DOM tree, which represents the structure of the webpage. This DOM can be manipulated using JavaScript or Frontend Framworks, providing dynamic and interactive user experiences on the client side.</p><ul><li><strong>Parsing :</strong></li></ul><p>Parsing in the context of web development refers to the process of analyzing a markup language, such as HTML or XML, and converting it into a structured representation that can be easily manipulated by a program. In Python, one popular library for parsing HTML is BeautifulSoup (bs4).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*vEaUpfIHtSuhO_MLYjdKaQ.png" /><figcaption>How parsing is done in the DOM</figcaption></figure><pre>import requests<br>from bs4 import BeautifulSoup as bs<br><br>u = &#39;https://example.com&#39;<br>r = requests.get(u)<br><br>if r.status_code == 200:<br>    soup = bs(r.content, &#39;html.parser&#39;)<br>    t = soup.find(&#39;h1&#39;).text<br>    print(f&quot;Title: {t}&quot;)<br><br>    links = soup.find_all(&#39;a&#39;)<br>    for link in links:<br>        print(f&quot;Link: {link[&#39;href&#39;]} - Text: {link.text}&quot;)<br>else:<br>    print(f&quot;Failed. Status Code: {r.status_code}&quot;)</pre><p>This is an example of Parse tree</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aU7JtDZhHcliPTKMaP86GA.jpeg" /><figcaption><a href="https://nqo.wikipedia.org/wiki/File%3APython_add5_parse.png">How Parse Tree (pruned) is used to retreive data for python add5 method</a></figcaption></figure><ul><li><strong>Storage :</strong></li></ul><p>It involves saving the parsed data in a structured manner for future use or reference.</p><p>For example once data is fetched and parsed, it might need to be stored for various purposes. In web development, this could involve saving user preferences, caching data for faster retrieval, or persisting data in databases for long-term storage. Storage mechanisms can include local storage, session storage, databases (SQL or NoSQL), or file systems.</p><p>This is an overview about all the webscraping mechanisme :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2MQcWprJ0bbfkIf48W1gyg.png" /></figure><h3>Watch out web scraping is not always legal ?</h3><p>Web scraping is a complex issue when it comes to legality , While the aim can be just to programmatically collect data for analysis or research. , <strong><em>Ethical and legal concerns arise when scraping is done without proper consent </em></strong>or violates a site’s terms of service.</p><p>To prevent issues like website overload or legal problems, ethical and lawful web scraping practices are crucial, ensuring compliance with permissions and site terms.</p><h3>How to deal with webscraping ?</h3><p>The legality of web scraping depends on various factors, including the website’s terms of service, the nature of the data being scraped, and the jurisdiction.</p><p>Generally, web scraping is legal when:</p><ul><li><strong>Website Rules: </strong>Check the website’s rules or use its API if allowed for scraping Respect the website owner’s preferences by following the guidelines in the “robots.txt” file.</li><li><strong>Public Data:</strong> If data is public and no security measures are bypassed, it might be legal.</li><li><strong>Rate Limiting: </strong>Even if a website allows scraping, it may have rate limits to prevent overload. Respecting these limits is crucial to avoid being blocked.</li><li><strong>Data Usage: </strong>How the scraped data is used can also impact legality. For example, using scraped data for commercial purposes could be more likely to result in legal issues.</li><li><strong>Geographical Location:</strong> Laws vary by location. What’s legal in one country might not be in another.</li><li><strong>Consent: </strong>In some cases, explicit consent may be required to scrape personal data, especially under data protection regulations like GDPR.</li></ul><p>Conversely, web scraping may be illegal if it involves:</p><ul><li>Don’t access private or password-protected parts of a website without permission; it’s usually illegal.</li><li>If web scraping goes against a website’s rules (terms of service), it could be considered illegal.</li><li>Scraping copyrighted content without permission can get you into legal trouble.</li></ul><p>Otherwise , when encountering web scraping challenges, consider these steps:</p><ol><li>Use a fake useragent string with a UserAgent to potentially bypass connection rejections, although success isn’t guaranteed.</li><li>Address issues where extracted HTML appears blank by incorporating a delay, such as using time.sleep(), to ensure the complete loading of the page before scraping.</li><li>Adjust the scraping pace to prevent server overload and potential blocking, implementing time delays between requests.</li></ol><p>If server blocks persist, explore Ip rotating as a potential solution to mitigate continuous blocking issues.</p><p>Thanks for reading my article , make sure to understand well the Legal issue of webscraping</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc3ef9ded7eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Programmation Socket TCP/IP en Python : Un Guide Pratique]]></title>
            <link>https://medium.com/@IbLahlou/programmation-socket-tcp-ip-en-python-dans-virtualbox-un-guide-pratique-942dc7b1e845?source=rss-2d2b091f1f66------2</link>
            <guid isPermaLink="false">https://medium.com/p/942dc7b1e845</guid>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[network]]></category>
            <category><![CDATA[socket-programming]]></category>
            <category><![CDATA[virtual-networks]]></category>
            <dc:creator><![CDATA[Ibrahim LAHLOU]]></dc:creator>
            <pubDate>Sun, 07 Jan 2024 18:05:28 GMT</pubDate>
            <atom:updated>2024-01-07T23:39:40.772Z</atom:updated>
            <content:encoded><![CDATA[<h3>1. Introduction</h3><p>Dans le domaine des réseaux et des systèmes distribués, la programmation de sockets joue un rôle crucial en facilitant la communication entre différentes machines. Cet article explore la création d’un programme de communication par socket en utilisant Python, en se concentrant spécifiquement sur l’interaction entre deux instances de serveur Ubuntu, VM1 et VM2.</p><h3>2. Architecture Réseau pour l’Exercice</h3><ul><li>NAT Network</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7TlV8fAnQ6PHwoNSKFbXOg.png" /><figcaption>Architecture de réseaux virtuel Nat dans virtuelle box pour 2 machine virtuelle</figcaption></figure><p>VM1 et VM2 sont configurées avec les adresses IP privées respectives 192.168.100.4 et 192.168.100.5. Au démarrage, les deux machines envoient des demandes DHCP au serveur DHCP, qui attribue dynamiquement les adresses IP et fournit d&#39;autres informations réseau, telle que la passerelle par défaut (adresse du serveur NAT, ILDNAT).</p><p>Ainsi, VM1 obtient l’adresse 192.168.100.4 et VM2 obtient l&#39;adresse 192.168.100.5. Les deux machines utilisent maintenant l&#39;adresse IP du serveur NAT comme passerelle par défaut pour accéder à Internet. Lorsqu&#39;elles envoient des paquets vers Internet, le serveur NAT (ILDNAT) remplace l&#39;adresse IP source de chaque machine par son adresse IP publique respective. Le serveur NAT maintient une table de traduction pour garantir le bon acheminement des réponses du côté Internet vers les machines virtuelles appropriées.</p><ul><li>Les modèles d’architecture de communication</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*pOqn8FlGlQmx0GZjzcqvJA.png" /><figcaption>Dans le cas d’un réseau local (Local host)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*lLPK-Oaopb17NLdxYrODIw.png" /><figcaption>Dans le cas d’une architecture client serveur</figcaption></figure><p>Pour cet exercice, nous utiliserons l’interface réseau Ethernet “eth0” pour la communication par socket.</p><h3>3. Rappel de certain concept réseau</h3><h4>1. Les Sockets ou prises</h4><p>Les sockets sont des points de terminaison de communication dans les systèmes informatiques, utilisés pour établir des connexions entre des applications sur un réseau .</p><p>Par exemple le serveur bdd mysql au port 3306 et le serveur web apache tomcat au port 8080</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oM4MU13OEBefcaEX1kJkTg.png" /></figure><p>Il existe différents types de sockets en fonction de leurs caractéristiques et de leur utilisation. Voici une liste concernant les types de sockets les plus classiques:</p><ul><li><strong>Stream Socket (SOCK_STREAM): </strong>Facilite une communication bidirectionnelle, fiable et continue, adaptée au protocole TCP.</li><li><strong>Datagram Socket (SOCK_DGRAM):</strong>Propose une communication sans connexion et non fiable avec l’utilisation de datagrammes, généralement associé à UDP.</li><li><strong>Raw Socket (SOCK_RAW): </strong>Permet un accès de niveau inférieur, offrant une personnalisation avancée, mais nécessite des privilèges élevés pour son utilisation.</li><li><strong>Sequential Packet Socket (SOCK_SEQPACKET): </strong>Assure un flux avec des paquets séquentiels, garantissant l’ordre des données transmises.</li><li><strong>Reliable Datagram Socket (SOCK_RDM):</strong> Fournit une communication fiable basée sur des datagrammes, avec des garanties d’ordre.</li><li><strong>Packet Socket (SOCK_PACKET):</strong> Utilisé pour une interaction directe au niveau de la liaison de données.</li></ul><p><strong><em>Remarque :</em></strong></p><p>La mise en place de la transition de TCP à UDP, tout en intégrant des mécanismes de sécurité tels que TLS/SSL, peut représenter un défi supplémentaire. Cette démarche nécessite une planification minutieuse et une mise en œuvre adaptée pour assurer la sécurité continue de la communication malgré le passage entre ces deux protocoles distincts.</p><h4>2. Three way <em>handshake :</em></h4><p><strong>SYN (Synchronized) :</strong> Le client envoie un paquet SYN au serveur avec un numéro de séquence aléatoire <em>A</em>.</p><p><strong>SYN-ACK (Synchronize, Acknowledge) :</strong> Le serveur répond avec un paquet SYN-ACK, ayant un numéro de séquence égal à <em>A + 1</em>, et un numéro de séquence aléatoire <em>B</em>.</p><p><strong>ACK (Acknowledgment) :</strong> Le client envoie un paquet ACK au serveur, avec un numéro de séquence augmenté de 1 <em>(A + 1)</em>, et un numéro de ACK égal à <em>B + 1</em>, finalisant ainsi la connexion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/0*URwBDfw13uC0OUGV.png" /><figcaption>Schéma de l’établissement d’une connexion TCP.</figcaption></figure><p>Une fois le <em>three-way handshake</em> effectué, le client et le serveur ont reçu un acquittement de la connexion. Les étapes 1 et 2 définissent le numéro de séquence pour la communication du client au serveur et les étapes 2 et 3 définissent le numéro de séquence pour la communication dans l’autre sens. Une communication <em>full-duplex</em> est maintenant établie entre le client et le serveur .</p><p><a href="https://fr.wikipedia.org/wiki/Three-way_handshake">Three-way handshake — Wikipédia (wikipedia.org)</a></p><h3>4. Mode de communication et Implementation avec Python</h3><p>Le module socket de Python fournit une interface à l’API des sockets de Berkeley.</p><p>Python fournit une API pratique et cohérente qui mappe directement aux appels système, leurs homologues C.</p><p>Voir la docummentation de python-socket :<br>[Programmation de sockets en Python (Guide) — Real Python](<a href="https://realpython.com/python-sockets/">https://realpython.com/python-sockets/</a>)</p><h4>1. Mode Connecté</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*EL-DUtx7isD8s9lMZoLMTA.png" /><figcaption>Architecture client-serveur pour le mode connecté</figcaption></figure><p>Dans le module socket de python</p><ol><li>Etablissement de connection (3-vay handshake)liason à trois voies</li><li>Transfère de donnée entre client et server</li><li>Fermeture de la communication entre client et server</li></ol><p>Au mode Connecté , on spécifie un socket de flux. pour une communication fiable , vous pouvez consulté ce lien github pour consulté le code</p><p><a href="https://github.com/IbLahlou/CommunicationSD/tree/master/Programmation%20socket/Mode%20Connect%C3%A9">CommunicationSD/Programmation socket/Mode Connecté at master · IbLahlou/CommunicationSD (github.com)</a></p><h4>2. Mode non Connecté</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*NHkHuJnHOjX-oMy6paYw6g.png" /></figure><p>1 et 2 Transfère de donnée entre client et server</p><p>Au mode non Connecté , on spécifie un socket de datagramme .les données sont envoyées sous forme de paquets indépendants sans qu’une connexion persistante soit établie au préalable.</p><p><a href="https://github.com/IbLahlou/CommunicationSD/tree/master/Programmation%20socket/Mode%20Non%20Connect%C3%A9">CommunicationSD/Programmation socket/Mode Non Connecté at master · IbLahlou/CommunicationSD (github.com)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=942dc7b1e845" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>