<?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 Albin Thomas on Medium]]></title>
        <description><![CDATA[Stories by Albin Thomas on Medium]]></description>
        <link>https://medium.com/@albint?source=rss-daf157bb0165------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8uvvyDQOXHjDyox2eSJdpA.jpeg</url>
            <title>Stories by Albin Thomas on Medium</title>
            <link>https://medium.com/@albint?source=rss-daf157bb0165------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 17:40:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@albint/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[OS, under the hood.]]></title>
            <link>https://albint.medium.com/os-under-the-hood-05f4ca39b4fd?source=rss-daf157bb0165------2</link>
            <guid isPermaLink="false">https://medium.com/p/05f4ca39b4fd</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[teaching-computer-scie]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[operating-systems]]></category>
            <dc:creator><![CDATA[Albin Thomas]]></dc:creator>
            <pubDate>Sat, 10 Oct 2026 21:16:57 GMT</pubDate>
            <atom:updated>2026-10-14T17:14:52.471Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gPH9aAMmyjZcZJMz" /><figcaption>Photo by <a href="https://unsplash.com/@diane_soko?utm_source=medium&amp;utm_medium=referral">Diane Picchiottino</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>We use operating systems every day without really thinking about what they are doing underneath. You open your laptop, launch a browser, play music, run some code and save a file, and everything somehow works together. But what if there was no Operating System at all? What would that actually look like?</p><p>Without an OS, every program would have to communicate directly with the hardware. Your browser would need to know how to interact with memory, your music application would need to understand the audio hardware, and every program would need to know the language spoken by every device it wanted to use. That already sounds painful, but there is an even bigger problem: who controls what each program is allowed to do?</p><p>If every program had the same permissions, nothing would stop one from interfering with another. Two programs might try to use the same resource at the same time, one program could overwrite memory being used by another, and everyone would essentially be fighting to get access to the CPU, memory and devices.</p><p>Imagine a group working together without anyone coordinating what each person is supposed to do. Everyone wants to lead, everyone wants access to the same resources and nobody has any restrictions. Eventually, you need someone who manages the group, decides who gets what and makes sure everyone stays within their boundaries.</p><p>That is essentially what the Operating System does.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tPQp5c2NZMi-MQbc2q665w.png" /></figure><h3>So, what exactly is an Operating System?</h3><p>At a very high level, an Operating System is a layer that sits between the applications the user interacts with and the hardware underneath. It abstracts the complexity of the hardware from applications and manages those hardware resources on their behalf.</p><p>Instead of every application knowing exactly how a storage device works or how memory should be allocated, the application can simply request something from the OS. The OS then figures out how to actually make it happen.</p><p>A simple way of looking at it is:</p><p><strong>Applications → Operating System → Hardware</strong></p><p>This abstraction is one of the most important things an OS gives us. It makes the complicated hardware underneath look much simpler to the applications running above it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RqTbJkUUyeLPh0ONr12YOw.png" /></figure><p>The Operating System mainly performs four important tasks: <strong>allocation, reclaiming, virtualization and protection</strong>.</p><p>Allocation is simply the OS deciding who gets access to resources. If multiple programs need CPU time or memory, the OS distributes those resources in an organized manner.</p><p>Reclaiming is the opposite. Once a process finishes using a resource, the OS takes it back so that another process can use it. Otherwise, programs could keep holding memory and other resources long after they actually need them.</p><p>Virtualization is where things get a little more interesting. The OS creates the illusion that processes have resources of their own. A process can behave as though it owns a large amount of memory even though many other processes are using the same physical machine.</p><p>Finally, protection prevents processes from interfering with one another. A normal application should not be able to casually overwrite another process’s memory or modify sensitive parts of the system.</p><p>So, in a way, the OS is basically the manager of the entire machine. It distributes resources, takes them back, hides hardware complexity and makes sure everyone behaves.</p><blockquote><strong><em>Tech Byte:</em></strong><em> Your applications are constantly asking for things — memory, CPU time, files, network access. The OS is the manager trying to make sure nobody steals someone else’s desk while doing it.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vZcQu04XlhE1N-EB8QO66A.png" /></figure><h3>How does the OS keep track of everything?</h3><p>If the OS is managing all these programs, it obviously needs a way to keep track of them.</p><p>This is where structures such as the <strong>process table</strong> come in. The process table contains information about the processes currently known to the OS. A process may be running, waiting, ready to run or completely finished, and the OS needs to know its current state along with the resources associated with it.</p><p>This information can include things such as the process state, CPU register information, memory details, open files, thread information and resources that the process currently owns.</p><p>Processes are constantly starting and stopping, so you can think of the process table as the OS’s giant tracking sheet for everything happening inside the system.</p><h3>But how does the OS actually communicate with hardware?</h3><p>Eventually, all this abstraction still has to reach the real hardware.</p><p>The computer contains buses that allow components to communicate, and devices usually have <strong>device controllers</strong> associated with them. These controllers can be thought of as the supervisors for individual devices. Instead of the OS understanding every low-level detail of every physical device directly, it can communicate through these controllers, usually with the help of device drivers.</p><p>A controller generally exposes registers that the OS can work with. A <strong>control register</strong> tells the device what operation should happen, a <strong>status register</strong> tells the OS what the device is currently doing, and a <strong>data register</strong> is used when transferring information.</p><p>This gives the OS a much cleaner way of communicating with different types of hardware.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KaOkqQegaZxnNh4jyuaFGg.png" /></figure><h3>Program vs Process</h3><p>Now let’s say you write a program and want to execute it.</p><p>A program is essentially just the instructions sitting somewhere on storage. I like to think of it as a recipe. The recipe exists, but nothing is actually happening yet.</p><p>Once you execute that program, it becomes a <strong>process</strong>. That is the recipe actually being cooked.</p><p>The process now needs resources from the OS. It needs memory, CPU time and possibly files or devices. The OS creates the necessary structures to keep track of it and gives it an <strong>address space</strong>.</p><p>The process therefore has things such as its address space, process table information, open files, thread state and whatever other resources it currently holds.</p><p>And this address space is where the virtualization part of the OS becomes much easier to understand.</p><h3>The address space: the memory the process thinks it owns</h3><p>Each process gets its own <strong>virtual address space</strong>. From the process’s perspective, this is its memory.</p><p>The important word there is <em>virtual</em>.</p><p>The process might access an address such as 0x4000, but that does not necessarily tell us where the data physically exists inside RAM. The translation from the virtual address to the physical memory location is handled using <strong>page tables</strong> and the <strong>Memory Management Unit</strong>, or MMU.</p><p>This means Process A could use virtual address 0x4000, while Process B could also use virtual address 0x4000, but both addresses can map to completely different locations in physical memory.</p><p>So each process effectively gets its own view of memory without needing to know where its data physically exists.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R69LsXmfrnB416tSp1A-ag.png" /></figure><p>A simplified address space normally contains several regions.</p><p>The <strong>text section</strong> contains the executable instructions of the program. The <strong>initialized data section</strong> stores global or static variables that already have values, while the <strong>uninitialized data section</strong>, often called BSS, stores variables that have been declared without an explicit initial value.</p><p>Then we have the <strong>heap</strong>, which is used for dynamically allocated memory through operations such as malloc() and free().</p><p>On the other side is the <strong>stack</strong>, which is heavily involved in function calls. Local variables, function parameters, return information and other function-related state are usually stored here.</p><p>In the simplified diagrams we normally see, the heap grows upward while the stack grows downward. If the stack grows beyond the amount of space available to it, you can get the famous <strong>stack overflow</strong>.</p><p>Yes, that Stack Overflow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NGk5U0CYyNzOisV_lUWVgQ.png" /></figure><p>Another interesting part of virtual memory is that this address space does not have to be physically contiguous.</p><p>A process may see three neighboring virtual pages, but those pages could actually be scattered across completely different locations in physical memory. The MMU and page tables take care of mapping one to the other.</p><p>The process does not need to know.</p><p>That is the whole point of the abstraction.</p><h3>But how does our code become a process?</h3><p>Now let’s go back even further.</p><p>Imagine you have written a C program and press Run.</p><p>The C source code cannot simply be handed directly to the CPU. It goes through multiple stages before becoming something executable.</p><p>The simplified journey looks like this:</p><p><strong>C Source → Compiler → Assembly → Assembler → Object File → Linker → Executable → Loader → Process</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l2WF-nVhugupd-MUMq0IGw.png" /></figure><p>The <strong>compiler</strong> takes the source code and translates it into lower-level instructions. Conceptually, one stage of this process can produce assembly code.</p><p>The <strong>assembler</strong> then converts that assembly into machine-code-containing <strong>object files</strong>.</p><p>At this point, it is reasonable to ask something I initially found confusing: if we ultimately want an executable, why bother creating an object file in between?</p><p>Why doesn’t the compiler just give us the final executable?</p><p>The answer is that the compiler does not necessarily know everything about the entire program.</p><p>Suppose your code calls a function that was defined in another file. The compiler can compile the file it is currently looking at, but the final location of that external function may not yet be known. Your program may also depend on libraries or symbols defined elsewhere.</p><p>Resolving all of that is the job of the <strong>linker</strong>.</p><p>The linker takes the different object files, resolves external symbols, connects the required libraries, handles relocation where necessary and finally produces the executable.</p><p>So the compiler focuses on compiling the code, while the linker focuses on connecting all the pieces together.</p><blockquote><strong><em>Tech Byte:</em></strong><em> The compiler basically says, “I have done my part. Whoever defined this function can deal with the rest.” The linker then gets called into the meeting.</em></blockquote><h3>What is actually inside an executable?</h3><p>An executable is not just one huge block of instructions.</p><p>It has a structure.</p><p>Conceptually, it contains things such as a <strong>header</strong>, code, data, symbol information and relocation information where required.</p><p>The header tells the system important information about the executable — what kind of file it is, how its sections are arranged, where execution begins and how different parts should be loaded into memory.</p><p>Different operating systems use different executable formats. Linux commonly uses <strong>ELF</strong>, macOS uses <strong>Mach-O</strong>, and Windows commonly uses <strong>PE</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B2pLUkfxJmLzItG6O2055Q.png" /></figure><h3>And finally, the loader</h3><p>Even after linking, the executable sitting on storage is still just a file.</p><p>To actually run it, the OS needs to turn that executable into a process.</p><p>This is where the <strong>loader</strong> comes in.</p><p>The loader uses the information stored in the executable to create the process, create its virtual address space, map the program’s code and data into that address space, prepare the stack and initialize the process state.</p><p>Once the process is ready, the scheduler can eventually give it CPU time.</p><p>The CPU then begins executing the instructions in the text section, while the <strong>program counter</strong> keeps track of the next instruction that needs to be executed.</p><p>So when you press Run, quite a lot happens before even the first line of your program actually executes.</p><h3>A little more linker magic</h3><p>In the simplified linker model we use in class, there are five reference types that help describe how an address should be interpreted.</p><p><strong>I — Immediate</strong> means the value is used directly as it is.</p><p><strong>A — Absolute</strong> refers to an absolute address according to the simplified memory model.</p><p><strong>R — Relative</strong> means the address is relative to where the current module is located. For example, if a module starts at location 800 and the instruction refers to relative address 40, the final address becomes:</p><p>800 + 40 = 840</p><p>This is what allows a module to be relocated depending on where it is eventually placed.</p><p><strong>E — External</strong> refers to symbols that are defined somewhere else, such as a function from another object file. The linker needs to resolve where that external symbol exists.</p><p>Finally, <strong>M — Module/Base</strong> refers to the base address of the current module in the simplified linker model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gYetp8XVe_xYyKndn1D7HQ.png" /></figure><p>These reference types are a simplified way of understanding some of the work the linker performs before the executable is ready.</p><h3>Wrapping Up</h3><p>We started by asking what would happen if there were no Operating System, and somehow ended up talking about device controllers, process tables, address spaces, virtual memory, MMUs, compilers, assemblers, linkers and loaders.</p><p>But that is exactly what makes Operating Systems interesting.</p><p>All of these layers exist so that the applications we use every day do not need to understand the enormous amount of complexity underneath them. A program can ask for memory without knowing which physical memory frame it receives. It can open a file without understanding how the storage controller works. It can run alongside hundreds of other processes without manually coordinating CPU access with any of them.</p><p>The Operating System makes an incredibly complicated machine look surprisingly simple.</p><p>And the next time you press <strong>Run</strong>, remember that your program has quite a journey ahead of it before anything actually appears on your screen.</p><p>Stay tuned for the next one, where we can go a little deeper into how the OS schedules processes and makes it seem like everything on your computer is running at the same time. 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=05f4ca39b4fd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Claude Code: How AI Agents Really Work Under the Hood]]></title>
            <link>https://albint.medium.com/understanding-claude-code-how-ai-agents-really-work-under-the-hood-01bb362f5399?source=rss-daf157bb0165------2</link>
            <guid isPermaLink="false">https://medium.com/p/01bb362f5399</guid>
            <category><![CDATA[claude-code]]></category>
            <category><![CDATA[autonomy]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[anthropic-claude]]></category>
            <category><![CDATA[ai-agent]]></category>
            <dc:creator><![CDATA[Albin Thomas]]></dc:creator>
            <pubDate>Sat, 17 Jan 2026 18:04:38 GMT</pubDate>
            <atom:updated>2026-01-17T18:19:24.263Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jON6uPG5fMUW-mP9" /><figcaption>Photo by <a href="https://unsplash.com/@rpianarosa?utm_source=medium&amp;utm_medium=referral">Ramiro Pianarosa</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3><strong>Introduction</strong></h3><p>The concept of an Agent CLI is going to change a lot of things for anyone looking to use an AI assistant and loves autonomy. Any CLI tool that has the ability to Read, Write, Bash, Grep can be used in so many creative ways.</p><p>This paired with Claude browser extension is a superpower for users. With these 2 capabilities you can automate just about any task that a user would do.</p><p>Let’s get into it.</p><h3><strong>What is Claude Code?</strong></h3><p>Claude Code is a pre-built agent that has access to your local system. Think of it as having an expert programmer in your terminal who can:</p><p>• Read and edit files</p><p>• Execute bash commands</p><p>• Search codebases</p><p>• Write and debug code</p><p>• Create git commits and pull requests</p><p>• And much more</p><h3>How Claude code works on your system</h3><p>Claude uses markdown for most of its capabilities. For any project that you create, when you type <em>claude</em> in the CLI to star up claude code, that creates a <em>.claude</em> folder in that directory. <br>This contains the following files/ folders:</p><ol><li>/agents</li><li>/commands</li><li>/skills</li><li>CLAUDE.md</li></ol><p>Basically this works in a way, that the Agent is trained to look for this folder if available and if not create it, and then follow all the instructions or commands that are created in the markdown files in each of these folders.</p><h3>The Agent Architecture</h3><p>Is Claude Code Already an Agent?</p><p>Yes! Claude Code is an agent system where:</p><p>• Primary Agent: The main Claude Code instance you interact with</p><p>• Subagents: Specialized agents you can create for specific tasks</p><p><strong>The Key Innovation: Context Isolation</strong></p><p>The brilliant part of Claude Code&#39;s architecture is that each subagent gets its own context window.</p><p>When the main agent delegates to a Code Reviewer Subagent, that subagent starts with a fresh context focused only on the review task. When it returns results, the main agent continues with clean context.</p><p>This prevents context pollution and allows for better task decomposition.</p><h3>Claude Code vs LangChain (Agents + Tools)</h3><h3>1) Creation Method</h3><ul><li><strong>Claude Code:</strong> Declarative (YAML + Markdown)</li><li><strong>LangChain:</strong> Imperative (Python/JS)</li></ul><p><strong>Meaning:</strong><br> Claude Code feels like configuring an agent. LangChain feels like programming a framework.</p><h3>2) Tool Definition</h3><ul><li><strong>Claude Code:</strong> Simple tool list (e.g., Read, Grep, Glob)</li><li><strong>LangChain:</strong> Tool objects + schemas + function wrappers</li></ul><p><strong>Meaning:</strong><br> Claude Code keeps tools lightweight and standardized. LangChain gives you more control, but you’ll write more glue code.</p><h3>3) Context Management</h3><ul><li><strong>Claude Code:</strong> Context is typically separated per sub-agent</li><li><strong>LangChain:</strong> Context is often shared (unless you design otherwise)</li></ul><p><strong>Meaning:</strong><br> Claude Code naturally encourages compartmentalized agents. LangChain can do either, but you must architect it.</p><h3>4) Invocation Style</h3><ul><li><strong>Claude Code:</strong> Can be automatic (or triggered by explicit mention)</li><li><strong>LangChain:</strong> Usually manual (you call the agent, route tools, manage steps)</li></ul><p><strong>Meaning:</strong><br> Claude Code tends to “just run” once configured. LangChain usually expects you to control the lifecycle.</p><h3>5) Learning Curve</h3><ul><li><strong>Claude Code:</strong> Lower — mostly configuration + prompt design</li><li><strong>LangChain:</strong> Moderate — writing code + understanding agent/tool wiring</li></ul><p><strong>Meaning:</strong><br> If you want fast iteration with less boilerplate, Claude Code is often simpler. If you want deep customization, LangChain is more flexible.</p><h3>6) Tool Execution / Control Loop</h3><ul><li><strong>Claude Code:</strong> Built-in execution (tool loop is handled for you)</li><li><strong>LangChain:</strong> You implement orchestration and state updates (explicit loop or framework runner)</li></ul><p><strong>Meaning:</strong><br> LangChain gives you maximum control at the cost of complexity. Claude Code optimizes for speed and ergonomics.</p><p><strong>LangChain Example (Imperative)</strong></p><p>With LangChain, you write code to define and orchestrate tools:</p><pre>from langchain.agents import create_react_agent<br>from langchain.tools import Tool<br>from langchain_anthropic import ChatAnthropic<br># YOU define tools with code<br>def read_file(file_path: str) -&gt; str:<br>with open(file_path) as f:<br>return f.read()<br># YOU create tool objects<br>tools = [<br>Tool(<br>name=&quot;read_file&quot;,<br>func=read_file,<br>description=&quot;Reads a file from disk&quot;<br>)<br>]<br># YOU initialize the agent<br>llm = ChatAnthropic(model=&quot;claude-sonnet-4-5&quot;)<br>agent = create_react_agent(llm, tools, prompt)<br># YOU implement the execution loop<br>while not done:<br>action = agent.plan(state)<br>result = execute_action(action)<br>state = agent.update(result)</pre><p><strong>Claude Code Example (Declarative)</strong></p><p>With Claude Code, you write a simple config file:</p><pre>---<br>name: code-searcher<br>description: Searches and analyzes code patterns<br>tools: Read, Grep, Glob<br>model: sonnet<br>---<br>You are a code search specialist.<br>When invoked, search for requested patterns and provide analysis.</pre><p>Then use it:</p><p>&quot;Use the code-searcher agent to find all API endpoints&quot;</p><h3>The Tool Loop, Demystified</h3><p>Tool-using agents feel magical until you realize they’re basically running the same simple cycle over and over. This cycle is often called the <strong>tool loop</strong> (or <strong>agentic loop</strong>) — and it’s the core mechanism that lets an agent move beyond “chat” into “do things.”</p><h3>The Tool Loop (Agentic Loop)</h3><p>The <strong>tool loop</strong> is the cycle that lets an agent complete tasks using tools:</p><p><strong>Task → Reason → Tool call (if needed) → Tool runs → Result → Reason → … until done</strong></p><h3>Example: “Fix the typo in README.md”</h3><ol><li><strong>Agent thinks:</strong> “I should read the file.”</li><li><strong>Agent requests:</strong> Read(README.md)</li><li><strong>Runtime runs it</strong> and returns content like: # Welcom to My Project</li><li><strong>Agent thinks:</strong> “Change ‘Welcom’ → ‘Welcome’.”</li><li><strong>Agent requests:</strong> Edit(old=&quot;Welcom&quot;, new=&quot;Welcome&quot;)</li><li><strong>Runtime applies the edit</strong> and confirms success</li><li><strong>Agent replies:</strong> “Typo fixed.”</li></ol><h4>LangChain / SDK-first approach: you implement it</h4><p>You typically write (or integrate) a loop that:</p><ul><li>calls the LLM</li><li>checks if it wants to use a tool</li><li>executes the tool</li><li>appends tool results back into the conversation/state</li><li>repeats until completion</li></ul><h4>Claude Code: it’s automatic</h4><p>Tool execution is handled by the Claude Code runtime. You define tools/agents and mostly see the final output (often with optional logs along the way).</p><h3>The Big Misconception: “LLMs Execute Tools”</h3><p>A common wrong mental model is:</p><blockquote><em>“The model calls a tool, so it must be running code.”</em></blockquote><p>That’s not true.</p><h4>Reality</h4><p>LLMs <strong>cannot execute code</strong> or directly access your filesystem.<br> They can only generate <strong>text</strong>, including structured text that <em>represents a tool request</em>.</p><p>So what looks like “tool use” is actually a collaboration:</p><ul><li><strong>Model:</strong> decides what should happen next and emits a structured tool request</li><li><strong>Runtime:</strong> parses that request, executes the real action, returns results</li><li><strong>Model:</strong> reads results and continues reasoning</li></ul><h4>The Real Architecture (Cloud Brain, Local Hands)</h4><h4>In the cloud (the LLM)</h4><p>Can:</p><ul><li>generate text tokens</li><li>reason over context</li><li>output structured tool calls</li></ul><p>Cannot:</p><ul><li>access your filesystem</li><li>run bash commands</li><li>execute Python/JS code</li><li>make network requests on its own</li></ul><h4>On your machine (the runtime)</h4><p>Can:</p><ul><li>read/write files</li><li>run commands</li><li>make network requests</li><li>enforce tool permissions and sandboxing</li><li>send tool results back to the model</li></ul><p>This separation is the key to understanding tool-based agents.</p><h3>Why This Separation Is Useful</h3><ul><li><strong>Security:</strong> you control what tools exist and what they can do</li><li><strong>Privacy:</strong> your repo isn’t automatically accessible; only tool outputs you provide get sent back</li><li><strong>Flexibility:</strong> tools are an interface; implementations vary per environment</li><li><strong>Performance:</strong> local file reads/search/commands are fast and don’t require uploading everything</li></ul><h3>Bottom Line</h3><p>If you want <strong>speed and simplicity</strong>, Claude Code’s declarative approach is often easier: define the agent + allowed tools and let the runtime handle the loop.</p><p>If you want <strong>maximum control and customization</strong>, LangChain is a better fit: you write the tooling, orchestration, memory, and execution flow yourself.</p><p>Both solve the same core problem — <strong>tool-using agents</strong> — but they optimize for different developer experiences.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=01bb362f5399" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Build a Multimodal Cooking Assistant with Watsonx & n8n]]></title>
            <link>https://albint.medium.com/build-a-multimodal-cooking-assistant-with-watsonx-n8n-41af0bd2f24b?source=rss-daf157bb0165------2</link>
            <guid isPermaLink="false">https://medium.com/p/41af0bd2f24b</guid>
            <category><![CDATA[multimodal]]></category>
            <category><![CDATA[generative-ai-use-cases]]></category>
            <category><![CDATA[n8n]]></category>
            <category><![CDATA[ibm-watson]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Albin Thomas]]></dc:creator>
            <pubDate>Fri, 26 Sep 2025 06:05:02 GMT</pubDate>
            <atom:updated>2025-09-26T06:05:02.780Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dBs6vm8QjsnfaqZU" /><figcaption>Photo by <a href="https://unsplash.com/@annapelzer?utm_source=medium&amp;utm_medium=referral">Anna Pelzer</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Ever wished your AI could look at the ingredients in your fridge and tell you what to cook? 🥦🍅🍗 Well, now it can! Using <strong>n8n</strong> (the low-code automation tool) and <strong>IBM Watsonx.ai</strong>, you can create a workflow where you upload a photo of ingredients, and the AI suggests recipes. Let’s go step by step — and yes, it’s fun and easy!</p><h3>Step 1: Set up your Webhook 📨</h3><p>First, we need a way to get the image and optional prompt (like “I want something spicy”) into n8n.</p><ul><li>Add a <strong>Webhook Node</strong> in n8n.</li><li>Method: POST</li><li>Body Type: Multipart/form-data</li><li>Fields:</li><li>data → the image (JPEG/PNG)</li><li>prompt → optional text</li></ul><p>💡 Tip: This node will give you <strong>binary data</strong> (your image) and <strong>JSON data</strong> (your prompt).</p><h3>Step 2: Extract the Image as Base64 🖼️</h3><p>Watsonx wants images in <strong>base64</strong>, so we need a <strong>Set Node</strong>.</p><ul><li>Node Name: Extract Image</li><li>Fields:</li><li>image_base64 → {{$binary[&quot;data&quot;].data}}</li><li>mimeType → {{$binary[&quot;data&quot;].mimeType}}</li></ul><p>This reads the uploaded image and prepares it for Watsonx.</p><h3>Step 3: Extract the Prompt 📝</h3><p>Next, we grab the user’s optional text prompt:</p><ul><li>Node Name: Extract Prompt</li><li>Fields:</li><li>prompt → {{$json[&quot;prompt&quot;] || &quot;What can I cook with this?&quot;}}</li><li>project_id → YOUR_WATSONX_PROJECT_ID</li></ul><p>This ensures we always have a prompt to feed into Watsonx.</p><h3>Step 4: Merge Image + Prompt 🔗</h3><p>We now have <strong>two separate streams</strong>: the image and the prompt. Let’s merge them into one object.</p><ul><li>Node Name: Merge Image + Prompt</li><li>Mode: <strong>Combine</strong> → <strong>Merge by Index</strong></li></ul><p>The output will look like:</p><pre>{<br>  &quot;image_base64&quot;: &quot;...&quot;,<br>  &quot;mimeType&quot;: &quot;image/jpeg&quot;,<br>  &quot;prompt&quot;: &quot;What can I cook with this?&quot;,<br>  &quot;project_id&quot;: &quot;YOUR_WATSONX_PROJECT_ID&quot;<br>}</pre><h3>Step 5: Call Watsonx Multimodal Model 🤖</h3><p>Time for the magic! Use an <strong>HTTP Request Node</strong> to call Watsonx:</p><ul><li>URL:<a href="https://us-south.ml.cloud.ibm.com/ml/v1/text/chat?version=2024-03-20">https://us-south.ml.cloud.ibm.com/ml/v1/text/chat?version=2024-03-20</a></li><li>Method: POST</li><li>Authentication: Bearer Token (from your Watsonx IAM node)</li><li>Body (JSON):</li></ul><pre>{<br>  &quot;model_id&quot;: &quot;meta-llama/llama-3-2-90b-vision-instruct&quot;,<br>  &quot;project_id&quot;: &quot;={{$json[&quot;project_id&quot;]}}&quot;,<br>  &quot;messages&quot;: [<br>    {<br>      &quot;role&quot;: &quot;system&quot;,<br>      &quot;content&quot;: &quot;You are a helpful chef assistant. Suggest recipes.&quot;<br>    },<br>    {<br>      &quot;role&quot;: &quot;user&quot;,<br>      &quot;content&quot;: [<br>        {<br>          &quot;type&quot;: &quot;text&quot;,<br>          &quot;text&quot;: &quot;={{$json[&quot;prompt&quot;]}}&quot;<br>        },<br>        {<br>          &quot;type&quot;: &quot;image_url&quot;,<br>          &quot;image_url&quot;: {<br>            &quot;url&quot;: &quot;data:={{$json[&quot;mimeType&quot;]}};base64,{{$json[&quot;image_base64&quot;]}}&quot;<br>          }<br>        }<br>      ]<br>    }<br>  ]<br>}</pre><p>This sends your image + prompt to Watsonx and gets a recipe suggestion back. 🍲</p><h3>Step 6: Respond to the User 📤</h3><p>Finally, add a <strong>Respond to Webhook Node</strong> and send the AI’s response back:</p><pre>={{$json[&quot;choices&quot;][0][&quot;message&quot;][&quot;content&quot;]}}</pre><h3>🎉 That’s It!</h3><p>Now, whenever someone sends a photo of their ingredients (and an optional prompt), Watsonx will suggest what to cook. You just built your <strong>own AI cooking assistant</strong> using <strong>n8n</strong> and <strong>multimodal AI</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41af0bd2f24b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Chatty with Watsonx in n8n (Even Without an Agent!)]]></title>
            <link>https://albint.medium.com/getting-chatty-with-watsonx-in-n8n-even-without-an-agent-8b7d18ac8d1b?source=rss-daf157bb0165------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b7d18ac8d1b</guid>
            <category><![CDATA[n8n]]></category>
            <category><![CDATA[ibm]]></category>
            <category><![CDATA[workflow-automation]]></category>
            <category><![CDATA[watsonx]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Albin Thomas]]></dc:creator>
            <pubDate>Sat, 20 Sep 2025 18:52:54 GMT</pubDate>
            <atom:updated>2025-09-20T18:52:54.579Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’ve been itching to make IBM Watsonx.ai respond to your prompts, but noticed there’s <strong>no official “agent” node</strong> in n8n yet… don’t panic! We can totally roll our own workflow and make it chat with you. Here’s a fun, beginner-friendly way to get started.</p><h3>Step 1: Setting Up the Webhook (aka “Your Chat Door”)</h3><p>Think of the <strong>Webhook node</strong> as your front door. It waits for messages from anywhere — a web form, Postman, or even your mobile app.</p><ul><li>Add a <strong>Webhook node</strong> in n8n.</li><li>Set the <strong>HTTP Method</strong> to POST and give it a path like /watsonx-chat.</li><li>Set <strong>Response Mode</strong> to Last Node. This just means whatever comes out last will go back to whoever asked.</li></ul><p>💡 <strong>Pro tip:</strong> Later, you can even add a Slack message or browser input to hit this webhook — fancy, right?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cstfw_BzYF3gF87wa-splQ.png" /></figure><h3>Step 2: Getting the IBM Token (aka “Your Secret Key”)</h3><p>Before Watsonx will talk to you, you need a <strong>token</strong>. Think of it like knocking politely at the Watsonx door and showing your invitation.</p><ol><li>Add an <strong>HTTP Request node</strong> called Get IBM Token.</li><li>Set <strong>Method</strong> to POST and URL to <a href="https://iam.cloud.ibm.com/identity/token.">https://iam.cloud.ibm.com/identity/token.</a></li><li><strong>Body Type:</strong> Form-Urlencoded</li><li>Add these parameters:</li></ol><ul><li>grant_type = urn:ibm:params:oauth:grant-type:apikey</li><li>apikey = your IBM Cloud API key (directly, or use n8n credentials if you’re fancy)</li></ul><p>5. Add a header: Content-Type: application/x-www-form-urlencoded</p><p>💡 <strong>Tip:</strong> If this works, you’ll get a JSON back with access_token. That’s the magic string we’ll pass to Watsonx next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*907ic52cXVlrsRvI2xOjUA.png" /></figure><h3>Step 3: Talking to Watsonx (aka “The Chat Node”)</h3><p>Now comes the fun part — actually chatting with the LLM.</p><ol><li>Add another <strong>HTTP Request node</strong> called Call Watsonx.</li><li><strong>Method:</strong> POST</li><li><strong>URL:</strong> Watsonx chat endpoint (something like https://&lt;region&gt;.ml.cloud.ibm.com/ml/v1/text/chat?version=2023-05-29)</li><li><strong>Headers:</strong></li></ol><ul><li>Authorization = Bearer {{$json[&quot;access_token&quot;]}}</li><li>Content-Type = application/json</li></ul><p><strong>5. Body Type:</strong> JSON</p><p>JSON Body example:</p><pre>{<br>  &quot;model_id&quot;: &quot;meta-llama/llama-3-3-70b-instruct&quot;,<br>  &quot;project_id&quot;: &quot;1b0ea6bb-745b-453c-a34f-0ffecd5c56c2&quot;,<br>  &quot;messages&quot;: [<br>    {<br>      &quot;role&quot;: &quot;system&quot;,<br>      &quot;content&quot;: &quot;You are a helpful assistant operating in standard mode.&quot;<br>    },<br>    {<br>      &quot;role&quot;: &quot;user&quot;,<br>      &quot;content&quot;: &quot; {{ $(&#39;Webhook&#39;).item.json.body.query }}&quot;<br>    }<br>  ],<br>  &quot;parameters&quot;: {<br>    &quot;decoding_method&quot;: &quot;greedy&quot;,<br>    &quot;max_new_tokens&quot;: 300<br>  }<br>}</pre><p>💡 <strong>Quick tip:</strong></p><ul><li>system role → sets the assistant’s personality.</li><li>user role → dynamically picks up whatever the webhook sends in query.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1HsM9fuTdfWnFL2QI09Kbg.png" /></figure><h3>Step 4: Sending the Response Back</h3><p>Remember how we set the <strong>Webhook response to Last Node</strong>? That means whatever Watsonx sends back will automatically go to the caller.</p><ul><li>Optional: You can add a <strong>Set node</strong> to clean up the response or pick only text if the JSON is big.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uM3-JfgNkJAESpDsVrvzMQ.png" /></figure><h3>Step 5: Test It Out! 🎉</h3><ol><li>Use Postman or a simple curl request:</li></ol><pre>curl -X POST &quot;https://jafoloc.app.n8n.cloud/webhook-test/watsonx-chat&quot; \<br>     -H &quot;Content-Type: application/json&quot; \<br>     -d &#39;{&quot;query&quot;: &quot;What is the capital of France?&quot;}&#39;</pre><p>2. Watch the response come back.</p><p>3. Celebrate — you just built your own Watsonx chat agent without any fancy built-in nodes! 🎈</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FTnuELcUVtQXHKFxGVALmA.png" /></figure><h3>Bonus Tips</h3><ul><li>Want to get really fancy? Connect the webhook to Slack, Teams, or even a web dashboard.</li><li>Always keep your API key secure. Using <strong>n8n credentials</strong> is safer than typing it directly in the node.</li><li>Add a <strong>Set node</strong> after Watsonx to strip metadata and only send the assistant’s reply.</li></ul><h3>TL;DR</h3><p>Even though n8n doesn’t have a “Watsonx agent” yet:</p><ul><li>Webhook = your input gate</li><li>Get IBM Token = secret handshake</li><li>Call Watsonx = actual chat</li><li>Response = what the user sees</li></ul><p>…and boom, you’ve got a workflow that talks! 💬</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b7d18ac8d1b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Problem to Practice: Implementing Ethical AI Governance in Hiring (Part 2)]]></title>
            <link>https://albint.medium.com/from-problem-to-practice-implementing-ethical-ai-governance-in-hiring-part-2-a617aa7a01d8?source=rss-daf157bb0165------2</link>
            <guid isPermaLink="false">https://medium.com/p/a617aa7a01d8</guid>
            <category><![CDATA[machine-learning-ai]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[governance]]></category>
            <category><![CDATA[ethical-ai]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Albin Thomas]]></dc:creator>
            <pubDate>Mon, 30 Jun 2025 18:17:42 GMT</pubDate>
            <atom:updated>2025-07-14T10:24:50.410Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dDd7qFrIo8o0P84V" /><figcaption>Photo by <a href="https://unsplash.com/@jeremythomasphoto?utm_source=medium&amp;utm_medium=referral">Jeremy Thomas</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In Part 1,</p><p><a href="https://medium.com/@albinthomas231/when-ai-isnt-fair-why-ethical-governance-is-no-longer-optional-4057d609b2a8">When AI Isn’t Fair: Why Ethical Governance Is No Longer Optional</a></p><p>we unpacked the urgent need for ethical AI governance in hiring — the risks of unchecked bias, the limitations of black-box AI systems, and the consequences when automation goes wrong.</p><p>Now, let’s roll up our sleeves and get into what responsible implementation actually looks like.</p><p>Because awareness alone doesn’t fix bias — action does. 💡</p><h3>Why It Matters: Real Stakes in Real Lives</h3><p>When AI makes a bad movie recommendation, it’s annoying.<br> When AI makes a biased hiring decision, it’s life-changing.</p><p>Hiring is a gateway — to financial security, career growth, even dignity. And when biased AI systems silently gatekeep opportunities, they don’t just affect individuals; they reshape workplaces.</p><p>Without proper governance:</p><ul><li>Qualified candidates can be filtered out simply because their resumes don’t “look like” past hires.</li><li>Entire demographics may be systematically underrepresented in interview pipelines — with no one realizing it.</li><li>Biases get amplified — not corrected — by algorithms designed to optimize for past success, not future fairness.</li></ul><p>And let’s not forget the ripple effect: reputational damage, legal risk, and lost diversity — all because the system wasn’t audited or understood.</p><p>That’s why ethical AI governance in hiring isn’t optional — it’s mission-critical.</p><h3>So Where Do We Start?</h3><p>Bias in AI hiring isn’t just an algorithmic glitch; it’s systemic. That means effective governance must be holistic — covering how we <strong>identify</strong>, <strong>mitigate</strong>, and <strong>monitor</strong> bias across the entire AI pipeline.</p><p>Here’s a practical blueprint for making AI hiring systems more fair, explainable, and compliant:</p><h3>1. Spot the Bias: Assessing Where It Hides</h3><p>Before you fix bias, you need to know it exists.</p><ul><li>🔍 <strong>Audit the data</strong>: Bias often starts with skewed historical datasets. Is your training data overly male? Favoring one geography? These are red flags.</li><li>📊 <strong>Use statistical fairness metrics</strong>:</li></ul><ol><li><strong>Disparate Impact Ratio (DIR)</strong>: Are selection rates consistent across groups?</li><li><strong>Equalized Odds</strong>: Are false positives and negatives fairly distributed</li><li><strong>Demographic Parity</strong>: Is selection independent of protected attributes?</li></ol><ul><li>🧠 <strong>Bring in Explainable AI (XAI)</strong>:</li></ul><ol><li><strong>SHAP</strong> and <strong>LIME</strong> can help decode why the model made a decision — and whether those reasons are valid or discriminatory.</li></ol><p>Bias detection isn’t just a dev task. These insights can help compliance, HR, and leadership understand how decisions are made — and where they break down.</p><h3>2. Break the Cycle: Mitigating Bias at Every Step</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*t5TDxMgynCcUtF85" /><figcaption>Photo by <a href="https://unsplash.com/@tuqui?utm_source=medium&amp;utm_medium=referral">Santiago Pazos Bordon</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Once you spot bias, it’s time to fix it. And that requires intervention at three levels:</p><h3>🔧 In-Processing: Fixing It at the Source</h3><ul><li><strong>Train on fair synthetic data</strong>: Use tools like LLMs to generate balanced datasets that reflect true diversity — not historical bias.</li><li><strong>Adversarial debiasing</strong>: Train a second model to catch when your AI is leaning on sensitive attributes. Then train the main model to fool it — in a good way.</li></ul><h3>🧹 Post-Processing: Cleaning Up the Output</h3><ul><li><strong>Equalized calibration</strong>: Make sure scores or recommendations are equally distributed across demographics.</li><li><strong>Re-ranking</strong>: Adjust final candidate lists to maintain top talent while ensuring fairness.</li></ul><h3>3. Build a Governance Backbone</h3><p>Technology alone isn’t enough. We need systems, policies, and accountability.</p><p>Here’s what a robust governance model includes:</p><h3>✅ Compliance Meets Code</h3><ul><li><strong>Compare against global standards</strong>: Look to frameworks like the EU AI Act, IEEE ethics, and GDPR to stay ahead.</li><li><strong>Evaluate real-world practices</strong>: How do companies like Google, IBM, and OpenAI structure their governance?</li></ul><h3>🧾 Policy in Practice</h3><ul><li><strong>Bias audits</strong>: Regular, independent checks on system performance.</li><li><strong>Compliance standards</strong>: Company-wide policies on fairness reporting, audit trails, and transparency.</li></ul><h3>4. Human in the Loop (And a Judge Too)</h3><p>AI should assist, not replace, human judgment — especially in high-stakes decisions like hiring.</p><ul><li><strong>Human oversight</strong>: Define clearly what actions the AI can take on its own vs. what needs human approval.</li><li><strong>Judge LLMs</strong>: Use a second LLM as a final checkpoint to catch any bias, toxicity, or harmful output — especially when deploying autonomous agents.</li></ul><h3>5. Perspectives Matter</h3><p>To ensure adoption and trust, governance must work for all stakeholders:</p><ul><li><strong>For developers</strong>: It’s about transparency, traceability, and collaboration with auditors.</li><li><strong>For users</strong>: Fairness and visibility in how they’re evaluated.</li><li><strong>For business leaders</strong>: Reputational safety, regulatory compliance, and better hiring outcomes.</li></ul><h3>Wrapping Up</h3><p>Ethical AI governance isn’t a checklist — it’s a mindset. It’s about embedding fairness, transparency, and accountability into every layer of your AI system.</p><p>And while the road isn’t always easy, the payoff is huge: more inclusive hiring, more trustworthy AI, and a future where automation works for <em>everyone</em>.</p><p>If you missed Part 1, here you go:</p><p><a href="https://medium.com/@albinthomas231/when-ai-isnt-fair-why-ethical-governance-is-no-longer-optional-4057d609b2a8">When AI Isn’t Fair: Why Ethical Governance Is No Longer Optional</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a617aa7a01d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When AI Isn’t Fair: Why Ethical Governance Is No Longer Optional]]></title>
            <link>https://albint.medium.com/when-ai-isnt-fair-why-ethical-governance-is-no-longer-optional-4057d609b2a8?source=rss-daf157bb0165------2</link>
            <guid isPermaLink="false">https://medium.com/p/4057d609b2a8</guid>
            <category><![CDATA[governance]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Albin Thomas]]></dc:creator>
            <pubDate>Mon, 30 Jun 2025 18:06:01 GMT</pubDate>
            <atom:updated>2025-07-14T10:22:13.860Z</atom:updated>
            <content:encoded><![CDATA[<h3>When AI Isn’t Fair: Why Ethical Governance Is No Longer Optional ( Part 1)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vL7xZ1qX_IYOlcsJ" /><figcaption>Photo by <a href="https://unsplash.com/@hautier?utm_source=medium&amp;utm_medium=referral">Christophe Hautier</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>AI has made its way into nearly every aspect of our lives — from filtering emails and summarizing documents to making hiring decisions and predicting creditworthiness. But here’s the thing: these systems aren’t just passive tools anymore.</p><p>They’re autonomous agents.<br> They’re decision-makers.<br> And increasingly, <strong>they’re acting on our behalf</strong> — whether we like it or not.</p><p>And that raises a big question: <strong>what happens when those decisions aren’t fair?</strong></p><h3>The Need for Ethical AI Governance</h3><p>AI systems are no longer just tools; they’re decision-makers. And when they start making decisions like who gets called for an interview or who gets rejected — we better make sure they’re doing it right.</p><p>Bias in hiring isn’t new. But when biased decisions are made by a system operating at scale, without transparency or human oversight, the damage multiplies. And let’s be real — no one wants a “smart” hiring system that’s unintentionally filtering out the very diversity companies say they value.</p><p>So how do we fix this? We start with governance. <strong>Ethical, enforceable, and proactive AI governance.</strong></p><p>Let’s break it down.</p><h3>The Stakes Are Higher Than Ever</h3><p>We’re not just talking about simple automation anymore. We’re talking about <strong>agentic AI systems</strong> — systems that can interpret goals, make decisions, and even take actions autonomously. That’s powerful… and risky.</p><p>Because with that autonomy comes real-world impact:</p><ul><li>Recommending who should be shortlisted for a job.</li><li>Deciding whether someone’s loan should be approved.</li><li>Flagging content that gets taken down — or letting harmful content stay up.</li></ul><p>When these decisions are influenced by <strong>biased data</strong> or <strong>flawed logic</strong>, the consequences aren’t just technical failures — they’re societal failures. And they disproportionately affect people who are already marginalized.</p><h3>Why Bias in AI Is Hard to Spot</h3><p>Here’s the tricky part: bias isn’t always loud.</p><p>It doesn’t always look like a slur in the output or an obviously unfair decision. Sometimes it hides:</p><ul><li>In training data that reflects historical inequalities.</li><li>In system behaviors that seem neutral, but consistently disadvantage certain groups.</li><li>In subtle patterns that no one questions — because the system is “working as expected.”</li></ul><p>And while we might expect humans to be biased and flawed, <strong>AI carries an illusion of objectivity</strong>. That’s what makes it dangerous — we often trust it more than we should.</p><h3>The Accountability Vacuum</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CaeJwRtibe5tLIza" /><figcaption>Photo by <a href="https://unsplash.com/@norevisions?utm_source=medium&amp;utm_medium=referral">No Revisions</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Despite their power, many AI systems are <strong>deployed without clear mechanisms for accountability</strong>. There are few guardrails, limited documentation, and often no answer to the question: “If this system makes a mistake, who is responsible?”</p><p>We wouldn’t accept this in any other domain. Imagine:</p><ul><li>An aircraft without maintenance logs.</li><li>A drug with no clinical trials.</li><li>A legal ruling with no explanation.</li></ul><p>But for AI? That’s still far too common. And it’s not just a technical issue — it’s a governance one.</p><h3>Governance Isn’t a Buzzword — It’s the Foundation</h3><p>When we say “ethical AI governance,” we’re not talking about a vague set of ideals. We’re talking about:</p><ul><li>Establishing <strong>guiding principles</strong>: transparency, fairness, accountability.</li><li>Defining <strong>roles and responsibilities</strong>: who builds, who audits, who decides?</li><li>Creating <strong>systems for oversight</strong>: audits, redressal mechanisms, feedback loops.</li><li>Ensuring <strong>humans remain in the loop</strong>, especially for high-stakes decisions.</li></ul><p>And importantly — governance isn’t just about preventing harm. It’s about <strong>building trust</strong>. It’s about showing users, regulators, and society at large that these systems are worthy of the responsibility they’ve been given.</p><h3>Wrapping Up</h3><p>We’re standing at a crossroads. On one side: rapid innovation, incredible possibilities, and real potential for good. On the other: growing risks, embedded biases, and widening gaps in accountability.</p><p>If we want AI that works <strong>for</strong> society — not against it — we need to do more than build smarter systems. We need to build <strong>responsible ones</strong>. And that starts with governance.</p><p>Because at the end of the day, it’s not just about what AI <em>can</em> do.<br> It’s about what we allow it to do — and who it serves in the process.</p><p><strong>More on Part 2</strong>, where we’ll explore what ethical governance can look like in practice — and how we can start building AI systems that are not just intelligent, but truly just.</p><p><a href="https://medium.com/@albinthomas231/from-problem-to-practice-implementing-ethical-ai-governance-in-hiring-part-2-a617aa7a01d8">From Problem to Practice: Implementing Ethical AI Governance in Hiring (Part 2)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4057d609b2a8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making Sense of Multimodal LLMs: Beyond just text]]></title>
            <link>https://albint.medium.com/making-sense-of-multimodal-llms-beyond-just-text-ea2ae9978bce?source=rss-daf157bb0165------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea2ae9978bce</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[multimodal]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[image-processing]]></category>
            <dc:creator><![CDATA[Albin Thomas]]></dc:creator>
            <pubDate>Mon, 30 Jun 2025 17:43:58 GMT</pubDate>
            <atom:updated>2025-06-30T17:43:58.054Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Zv3-03ogTcVRLvDx" /><figcaption>Photo by <a href="https://unsplash.com/@usgs?utm_source=medium&amp;utm_medium=referral">USGS</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>So far, we’ve relied on large language models (LLMs) to extract insights from plain text. But what happens when your data <em>isn’t</em> just text? Think invoices, forms, screenshots, or even scanned product manuals. That’s where <strong>multimodal LLMs</strong> enter the scene — and honestly, they change the game.</p><h3>👀 Wait, What Are Multimodal LLMs?</h3><p>Unlike traditional LLMs that only handle text, <strong>multimodal LLMs</strong> can take in images, too — sometimes even video or audio. They blend the strengths of language models and visual encoders, letting them understand the world a little more like humans do: both visually and contextually.</p><p>In simple terms: if a plain LLM would go blank looking at a receipt image, a multimodal model like <em>LLaMA Maverick</em> can extract the total amount, date, and vendor name without breaking a sweat.</p><h3>How Do They Work Internally?</h3><p>At the core of these models is a <strong>vision encoder</strong> (like a ResNet or Vision Transformer) that turns an image into dense vector embeddings — essentially, visual tokens. These tokens are then fed into the <strong>language model</strong>, which treats them just like any other input — blending visual context with text-based reasoning.</p><p>So, while the LLM itself hasn’t magically learned to “see,” it now collaborates with a visual brain to process and understand what’s going on.</p><h3>Multimodal Preprocessing: More Work Than You Think</h3><p>If you’re used to working with text LLMs, multimodal ones need a bit more care before you plug things in:</p><ol><li><strong>Convert PDFs to Images</strong><br> You can’t feed PDFs directly — you need to render each page into an image first (e.g., using pdf2image).</li><li><strong>Encode Images to Base64</strong><br> These images are then <strong>Base64-encoded</strong>, which is a format the vision encoder understands when passed via an API.</li><li><strong>Why Not Just Paste the Base64 in the Prompt?</strong><br> Because a single Base64 image string can take up <em>hundreds of thousands</em> of tokens. Including it directly in the prompt would explode your token limit.<br> The trick is: <strong>Base64 image data doesn’t count toward the model’s token limit</strong> because it’s handled <em>separately</em> by the vision encoder — outside of the tokenized prompt stream.</li><li><strong>Pass It All to the Model</strong><br> Once your image is encoded, you pass it along with the system message and user query using structured API inputs.</li></ol><h3>Using Multimodal LLMs for Extraction</h3><p>Let’s say you want to extract fields from a scanned invoice. Here’s how you’d do it using a model like meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8</p><p>Below is the example for the body that you will use to hit the apis for the model. You will prolly also need a bearer token to authenticate the api which you can generate with an api key. This is different for most platforms. The {encoded_invoice}variable contains the base 64 encoded image. The prompt that you want is the last message in the list.</p><pre>body = {<br>    &quot;messages&quot;: [<br>        {<br>            &quot;role&quot;: &quot;system&quot;,<br>            &quot;content&quot;: &quot;You are an expert at reading business documents.&quot;<br>        },<br>        {<br>            &quot;role&quot;: &quot;user&quot;,<br>            &quot;content&quot;: [{<br>                &quot;type&quot;: &quot;image_url&quot;,<br>                &quot;image_url&quot;: {<br>                    &quot;url&quot;: f&quot;data:image/jpg;base64,{encoded_invoice}&quot;<br>                }<br>            }]<br>        },<br>        {<br>            &quot;role&quot;: &quot;user&quot;,<br>            &quot;content&quot;: &quot;Extract invoice number, date, total amount, and vendor.&quot;<br>        }<br>    ],<br>    &quot;model_id&quot;: &quot;meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8&quot;,<br>    &quot;decoding_method&quot;: &quot;sample&quot;,<br>    &quot;temperature&quot;: 0.001,<br>    &quot;max_new_tokens&quot;: 15000<br>}</pre><p>And boom — you get back structured entities like:</p><pre>{<br>  &quot;invoice_number&quot;: &quot;INV-2024-0032&quot;,<br>  &quot;date&quot;: &quot;2024-12-01&quot;,<br>  &quot;total_amount&quot;: &quot;$1,200.00&quot;,<br>  &quot;vendor&quot;: &quot;Tech Supplies Inc.&quot;<br>}</pre><p>So that’s the end of this blog…<br>WAIT A MINUTE, here’s another interesting part. Take a quick breath, stay with me.</p><h3>🎯 Few-Shot Prompting — Not So Simple Anymore</h3><p>Text LLMs make few-shot prompting easy. Just paste in a couple of Q&amp;A pairs, and the model picks up the pattern.</p><p>But with multimodal LLMs, that doesn’t work the same way. You <strong>can’t inline Base64 image examples</strong> into your prompt — the string is way too big and will overflow your token limit.</p><p>Instead, you simulate few-shot examples by sending <strong>message pairs</strong>: one message with the image, and one with the assistant’s output. Like this:</p><pre>body = {<br>    &quot;messages&quot;: [<br>        {<br>            &quot;role&quot;: &quot;system&quot;,<br>            &quot;content&quot;: &quot;You are a document understanding assistant.&quot;<br>        },<br>        {<br>            &quot;role&quot;: &quot;user&quot;,<br>            &quot;content&quot;: [{<br>                &quot;type&quot;: &quot;image_url&quot;,<br>                &quot;image_url&quot;: {<br>                    &quot;url&quot;: f&quot;data:image/jpg;base64,{encoded_example1}&quot;<br>                }<br>            }]<br>        },<br>        {<br>            &quot;role&quot;: &quot;assistant&quot;,<br>            &quot;content&quot;: [{<br>                &quot;type&quot;: &quot;text&quot;,<br>                &quot;text&quot;: &quot;{example_output_1}&quot;<br>            }]<br>        },<br>        {<br>            &quot;role&quot;: &quot;user&quot;,<br>            &quot;content&quot;: [{<br>                &quot;type&quot;: &quot;image_url&quot;,<br>                &quot;image_url&quot;: {<br>                    &quot;url&quot;: f&quot;data:image/jpg;base64,{encoded_invoice}&quot;<br>                }<br>            }]<br>        },<br>        {<br>            &quot;role&quot;: &quot;user&quot;,<br>            &quot;content&quot;: &quot;Extract key fields from the invoice.&quot;<br>        }<br>    ]<br>}</pre><p>This structure gives the model context without bloating your token budget. And yes, some models even support <strong>multiple images per query</strong>, which is super handy when working with multi-page PDFs.</p><h3>✨ Wrapping Up</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*srnqPupr58SKER-1" /><figcaption>Photo by <a href="https://unsplash.com/@etiennegirardet?utm_source=medium&amp;utm_medium=referral">Etienne Girardet</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Multimodal LLMs aren’t just a fun upgrade — they’re becoming essential for working with modern data. From invoices and contracts to charts and product images, they give you the ability to <strong>understand structure, layout, and visual context</strong>, not just raw words.</p><p>The best part? You don’t need to build separate pipelines for OCR, rule-based logic, and post-processing. These models can <em>see</em>, <em>read</em>, and <em>reason</em> — all at once.</p><p>Next up: I’ll walk you through an actual use case using LLaMA Maverick to extract structured data from a multi-page PDF. Stay tuned! 🧾🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea2ae9978bce" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cracking the code: Judge LLM for Entity Extraction (Part 2- No Ground Truth!)]]></title>
            <link>https://albint.medium.com/cracking-the-code-judge-llm-for-entity-extraction-part-2-no-ground-truth-b5d8e5bf3e59?source=rss-daf157bb0165------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5d8e5bf3e59</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[evaluation]]></category>
            <category><![CDATA[entity-extraction]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Albin Thomas]]></dc:creator>
            <pubDate>Sun, 30 Mar 2025 15:06:37 GMT</pubDate>
            <atom:updated>2025-03-30T15:06:37.983Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gPub2lJKpt1G4HFW" /><figcaption>Photo by <a href="https://unsplash.com/@matdflo?utm_source=medium&amp;utm_medium=referral">Matt Flores</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In the previous post, we explored the importance of evaluating entity extraction without relying on manually curated ground truth. We also introduced some key evaluation metrics, such as self-consistency, contextual plausibility, hallucination plausibility, redundancy checks, and structure validation.</p><p>Now, let’s dive into the actual implementation! We’ll leverage an LLM to assess extracted entities by automating the evaluation process. Buckle up, because it’s time to put theory into action!</p><h3>Choosing the Right LLM for Evaluation</h3><p>Choosing the right evaluation model is crucial. Unlike extraction, which may require a large and complex LLM, evaluation focuses on <strong>consistency, redundancy, and hallucination detection</strong> — tasks that don’t demand a vast knowledge base. Instead, we need a <strong>deterministic, stable, and computationally efficient model</strong>.</p><p>Using a <strong>smaller, focused model</strong> can be just as effective, if not better. The evaluation LLM doesn’t need to “know everything” but should <strong>accurately judge extracted entities</strong> for stability and contextual relevance. This approach ensures a balance between <strong>resource efficiency</strong> and <strong>evaluation accuracy</strong> while preventing unnecessary complexity.</p><p>Additionally, if an LLM was used for entity extraction, it’s essential to use a <strong>different model for evaluation</strong> to avoid bias and self-reinforcement in scoring.</p><h3>The LLM-Powered Evaluation Framework</h3><p>To automate entity extraction evaluation, we employ a <strong>language model as a judge</strong>. Instead of manually verifying extracted entities, we let an LLM analyze the results and assign scores based on predefined metrics.</p><p>Here’s how we do it:</p><ol><li><strong>Self-Consistency Check:</strong> Running the same input multiple times and verifying if the extracted entities remain stable.</li><li><strong>Contextual Plausibility:</strong> Ensuring the extracted entities make sense within the document’s context.</li><li><strong>Hallucination Plausibility:</strong> Detecting if the model introduces entities that don’t exist in the original text.</li><li><strong>Redundancy Check:</strong> Verifying if the model extracts duplicate or unnecessary variations of entities.</li><li><strong>Structure Validation:</strong> Ensuring the extracted output follows a clean and structured format (e.g., JSON).</li></ol><h3>Setting Up the LLM Model</h3><p>We use IBM’s Watsonx LLM to perform evaluations programmatically. Here’s how we initialize our model:</p><pre>import os<br>from dotenv import load_dotenv<br>from langchain_ibm import WatsonxLLM</pre><p>With the model ready, let’s implement an EntityEvaluator class that handles all evaluation steps.</p><h3>Implementing Entity Extraction Evaluation</h3><p>Our EntityEvaluator class orchestrates multiple evaluations, leveraging prompts for the defined metrics.</p><p>Here’s the current implementation:</p><pre>import json<br>import re<br><br>class EntityEvalutor:<br>    def __init__(self, model_id: str) -&gt; None:<br>        &quot;&quot;&quot;<br>        Initialize the EntityEvaluator with an LLM model.<br>        <br>        :param llm_model: The language model used for evaluation.<br>        &quot;&quot;&quot;<br>        self.model_id = model_id<br>        <br>        parameters = {<br>            &quot;decoding_method&quot;: &quot;greedy&quot;,<br>            &quot;max_new_tokens&quot;: 512,<br>            &quot;repetition_penalty&quot;: 1<br>        }<br>        llm_model = WatsonxLLM(<br>            model_id=self.model_id,<br>            url=os.getenv(&quot;WATSONX_AI_URL&quot;),<br>            apikey=os.getenv(&quot;WATSONX_APIKEY&quot;),<br>            project_id=os.getenv(&quot;WATSONX_AI_PROJECT_ID&quot;),<br>            params=parameters<br>        )<br><br>        self.llm_model = llm_model<br>    <br>    def compute_consistency(self, extracted_entities: list, llm_runs: int=5):<br>        <br>        &quot;&quot;&quot;    <br>        Compute self consistency<br>        Check if multiple passes of the input to llm give the same consistent output <br><br>        Args:<br>            extracted_entities (list): List of outputs from multiple llm passes for consistency<br>            llm_runs (int, optional): Number of llm passes we are checking consistency for. Defaults to 5:int.<br>        &quot;&quot;&quot;<br>        <br>        extracted_entities = extracted_entities[:llm_runs]<br>        <br>        # Format the extracted entities list as a string<br>        formatted_entities = &quot;\n\n&quot;.join(<br>        [f&quot;Extraction {i+1}:\n{json.dumps(entities, indent=2)}&quot; for i, entities in enumerate(extracted_entities)])<br><br>        prompt = f&#39;&#39;&#39;<br>        &lt;system&gt;<br>        You are an expert in named entity recognition. Evaluate the extracted entities below based on the given text.<br>        &lt;/system&gt;<br><br>        Below is a list of extracted entities from multiple runs of the same input.<br><br>    Evaluate the consistency of the outputs. On a scale from 1 to 5:<br>    - A higher score (closer to 5) means all extracted entity outputs are identical.<br>    - A lower score (closer to 1) means there are significant differences in extracted keys or values.<br>    - The result should be a single number which is the score<br><br>    Extracted Entity Outputs:<br><br>    {formatted_entities}<br><br>    Provide a single **consistency score** (1-5).<br>    &lt;/user&gt;<br><br>    &lt;assistant&gt;<br>    Consistency score: <br>        &#39;&#39;&#39;<br>        <br>        response = self.llm_model.generate([prompt]).generations[0][0].text.strip()<br>        response = re.sub(r&#39;&lt;/assistant&gt;\s*$&#39;, &#39;&#39;, response)<br>        return response<br><br>    <br>        <br>    def evaluate_entity_extraction(self, context, extracted_entities):<br>        <br>        &quot;&quot;&quot;<br>        Evaluate extracted entities against the document using an LLM judge for contextual plausability, hallucination, redundancy and structure<br>        <br>        :param document: The extracted text from a document.<br>        :param entities: The named entities extracted.<br>        :return: LLM evaluation response.<br>        &quot;&quot;&quot;<br>            <br>        prompt = f&#39;&#39;&#39;<br>        &lt;system&gt;<br>        You are an expert in named entity recognition. Evaluate the extracted entities below based on the given text.<br>        &lt;/system&gt;<br><br>        &lt;user&gt;<br>        Given the text and the extracted entities, evaluate the entities with the text.<br><br>        Rate the extraction on:<br>        1. Contextual plausability (1-5): Do these entities fit the passage&#39;s meaning? or Can the extracted entity be inferred with high confidence? higher score for more fit to context<br>        2. Hallucination plausibility (1-5): Did the extraction introduce entities not present? higher score of lesser hallucination<br>        3. Redundancy check (1-5): if there are Duplicate or excessive extraction then the score will be lower<br>        4. Structure: If the structure of the extracted entities is correct as in json or yaml, only check structure <br><br>        Provide the aggregated score from 1-5 to 1 decimal place.<br><br>        Text:<br>        {context}<br><br>        Extracted Entities:<br>        {extracted_entities}<br>        &lt;/user&gt;<br>        <br>        &lt;assistant&gt;<br>            &#39;&#39;&#39;<br>    <br>        response = self.llm_model.generate([prompt]).generations[0][0].text.strip()<br>        response = re.sub(r&#39;&lt;/assistant&gt;\s*$&#39;, &#39;&#39;, response)<br>        match = re.search(r&#39;aggregated score[:=]\s*([\d\.]+)&#39;, response, re.IGNORECASE)<br>        final_score = float(match.group(1)) if match else None<br>        return response, final_score</pre><h3>Shortcoming of the current approach</h3><p>The current implementation still uses a <strong>monolithic prompt</strong> structure within evaluate_entity_extraction. While this provides results, it needs improvement to better align with our goal of modularity. We should refactor it to use <strong>individual prompts for each metric</strong>, ensuring:</p><p>✅ <strong>Clearer analysis</strong> — We get separate scores and explanations for each aspect of evaluation.</p><p>✅ <strong>More accurate assessments</strong> — The LLM focuses on one criterion at a time rather than making a general judgment.</p><p>✅ <strong>Easier debugging &amp; refinement</strong> — If one metric is off, we can tweak its specific prompt without affecting others.</p><h3>Wrapping Up</h3><p>We’ve now gone from <strong>theory to implementation</strong>, using an LLM to <strong>automate entity extraction evaluation</strong> across multiple criteria. However, we still need to refine our approach by <strong>splitting prompts into dedicated functions for each metric</strong> to fully leverage the benefits of modular evaluation.</p><p>What’s next? Stay tuned for <strong>Part 3</strong>, where we’ll evaluate Entity Extraction when there is ground truth available🚀</p><p>If you want to revisit Part 1:</p><p><a href="https://medium.com/@albinthomas231/evaluating-llm-entity-extraction-part-1-no-ground-truth-0443be16f91a">Evaluating LLM entity extraction — Part 1 ( no ground truth)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5d8e5bf3e59" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Evaluating LLM entity extraction — Part 1 ( no ground truth)]]></title>
            <link>https://albint.medium.com/evaluating-llm-entity-extraction-part-1-no-ground-truth-0443be16f91a?source=rss-daf157bb0165------2</link>
            <guid isPermaLink="false">https://medium.com/p/0443be16f91a</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[entity-extraction]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[evaluation]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Albin Thomas]]></dc:creator>
            <pubDate>Thu, 27 Mar 2025 13:35:52 GMT</pubDate>
            <atom:updated>2025-03-31T11:27:28.510Z</atom:updated>
            <content:encoded><![CDATA[<h3>Making Sense of AI: How to Evaluate Entity Extraction using LLM — Part 1 (No Ground Truth!)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VWcwYM1iJ_OMCaps" /><figcaption>Photo by <a href="https://unsplash.com/@bretkavanaugh?utm_source=medium&amp;utm_medium=referral">Bret Kavanaugh</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In today’s world of AI and NLP, testing is not just a nice-to-have; it’s essential. Whether you’re training a machine learning model, working with complex algorithms, or deploying AI systems, one thing is clear: <strong>Evaluation is key</strong>. Without evaluation, how do we know if our model is truly performing as expected? How can we trust the outputs if we haven’t properly assessed their accuracy, reliability, and consistency?</p><p>One way to do this is to sit and check if the output is correct, but manually checking and validating every entity extracted from a document? Well, that’s a nightmare! You’d be spending endless hours pouring over hundreds (if not thousands) of documents, painstakingly comparing outputs against what’s <em>really</em> correct. Not fun.</p><p><strong>Enter automated evaluation</strong>: a way to test the effectiveness of entity extraction without relying on manually curated gold-standard data. It’s like giving your model a mirror to check itself out. You can measure how consistent, relevant, and precise its extractions are, all with zero human intervention. How cool is that?</p><p>So, buckle up! In this blog, we’ll dive into the funky world of <strong>Entity Extraction Evaluation without ground truth </strong>and how we can automate this whole process. It’s time to leave the boring manual testing behind and embrace the future!</p><h3>What’s Entity Extraction?</h3><p>Imagine reading a document and picking out the names, dates, locations, or even job titles. That’s exactly what <strong>entity extraction</strong> does — it helps machines spot those important chunks of information that are hidden in a sea of text.</p><p>So, for example, if you hand over a document about a company, the LLM might extract “CEO,” “Jane Doe,” and “2025–01–01.” Simple, right?</p><p>But how do you know if the extraction is actually good? <strong>That’s where entity extraction evaluation comes into play</strong>. Without diving into code or technical jargon, let’s break it down.</p><h3>Evaluating Entity Extraction: No Ground Truth, No Problem!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ybymwRuqUMXN9ptx" /><figcaption>Photo by <a href="https://unsplash.com/@michaelcarruth?utm_source=medium&amp;utm_medium=referral">Michael Carruth</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Here’s the twist: usually, you’d compare what your model extracted to a set of “correct” answers. But who has the time for that when you’re dealing with tons of documents? Instead, let’s evaluate it the <em>fun</em> way — by focusing on how well the model performs in <strong>real-world scenarios</strong>.</p><p>Here are the key things you can check out:</p><ol><li><strong>Self-Consistency: Does It Stick to Its Guns?</strong></li></ol><p>Imagine the model running the same document through multiple times. Will it give you the same answers every time, or will it start changing things up? A model that keeps pulling out the same entities with each run scores higher on this front.</p><p><strong>2. Contextual Plausibility: Is It Making Sense?</strong></p><p>It’s not enough for the model to just pull out names or dates; it has to <em>make sense</em> in the context of the document. If your model pulls out “Alice” as a name but the text is all about a tech startup’s financial report which does not mention any names— well, that’s a bit off, right? Can the extracted entity be inferred with high confidence?</p><p><strong>3. Hallucination Plausibility: No Ghosts Allowed!</strong></p><p>We’ve all heard the term “hallucinating,” but here we mean it in a <em>very</em> specific way: a model pulling out information that <em>wasn’t even there</em>. If your entity extractor spits out a “John Doe” that doesn’t exist in the document, it’s officially a hallucination. And that’s a big no-no.</p><p><strong>4. Redundancy Check: One’s Enough, Thanks</strong></p><p>Nobody likes a copycat. If your model is pulling out the same entity twice when it only appears once, that’s redundancy. And redundant extractions? Not cool. Does the model extract <strong>too many variations of the same entity</strong>?Are there <strong>duplicates</strong> or overly broad extractions? Does it mistakenly split a single entity into multiple fragments?</p><p><strong>5. Structure: Keep It Neat and Tidy</strong></p><p>Extraction isn’t just about finding entities — it’s also about how the data is presented. Whether it’s in JSON, YAML, or some other format, keeping the structure neat and clear is key for readability.</p><h3>Here’s a Sample of Extracted Entities</h3><p>To see how these evaluation points work in action, let’s check out a sample of some entities that might be extracted from a document:</p><pre>{<br>  &quot;result&quot;: {<br>    &quot;startdate&quot;: &quot;2023-11-01&quot;,<br>    &quot;enddate&quot;: &quot;2024-11-01&quot;,<br>    &quot;product&quot;: &quot;Laptop&quot;,<br>    &quot;customer_name&quot;: &quot;John Doe&quot;,<br>    &quot;invoice_number&quot;: &quot;INV-1111&quot;,<br>    &quot;total_amount&quot;: &quot;$1,250.50&quot;,<br>    &quot;company_name&quot;: &quot;Tech Solutions Ltd.&quot;,<br>    &quot;address&quot;: &quot;xxxxxxxxxxxxxxxx&quot;<br>  }<br>}</pre><h3>Why This Is Important</h3><p>When we talk about evaluating LLMs, it’s easy to get caught up in the technicalities. But at the end of the day, you want your entity extraction system to work in the real world. It should be consistent, smart, and free of errors.</p><p>By using these evaluation methods, you can gauge how well your system is doing without needing to constantly rely on manually annotated datasets. Instead, you’re letting the model <em>self-reflect</em> and improve over time based on simple but effective checks.</p><h3>Wrapping Up</h3><p>So there you have it! Entity extraction is about pulling out important info from text, but <strong>evaluating that extraction</strong> is where the magic happens. Whether it’s checking for consistency, making sure the entities make sense in context, or ensuring the extraction doesn’t hallucinate information — it’s all about making sure your LLM’s output is as reliable as possible.</p><p>No ground truth? No problem! Just let your model evaluate itself, and you’ll be one step closer to an extraction system that’s both smart and reliable. 🚀</p><p>In Part 2, we’ll dive into the code:</p><p><a href="https://medium.com/@albinthomas231/cracking-the-code-judge-llm-for-entity-extraction-part-2-no-ground-truth-b5d8e5bf3e59">Cracking the code: Judge LLM for Entity Extraction (Part 2- No Ground Truth!)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0443be16f91a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Image ROI Segmentation with OpenCV — Part 2: Automating Region Detection]]></title>
            <link>https://albint.medium.com/image-roi-segmentation-with-opencv-part-2-automating-region-detection-1c74f83624b1?source=rss-daf157bb0165------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c74f83624b1</guid>
            <category><![CDATA[image-segmentation]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[opencv]]></category>
            <category><![CDATA[image-processing]]></category>
            <category><![CDATA[fintech]]></category>
            <dc:creator><![CDATA[Albin Thomas]]></dc:creator>
            <pubDate>Thu, 27 Mar 2025 11:56:20 GMT</pubDate>
            <atom:updated>2025-03-27T12:00:37.004Z</atom:updated>
            <content:encoded><![CDATA[<h3>Image ROI Segmentation with OpenCV — Part 2: Automating Region Detection</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kvqoRW6jBWazwPCo_UGfWQ.jpeg" /></figure><p>In our previous blog, we took a hands-on approach to extracting marked transactions from a bill using OpenCV. But let’s be honest — who wants to manually mark things when we have AI at our disposal? We live in an age of automation, and today, we’re cranking it up a notch! 🔥</p><p><em>Imagine this: No more highlighting or scribbling on bills. Instead, your system does the heavy lifting for you, automatically detecting and extracting the important bits like a digital Sherlock Holmes. Intrigued? Stick around, because we’re about to make that happen!</em></p><p>By the end of this blog, you’ll be able to segment regions of interest (ROI) without lifting a finger (except to write code, of course). We’ll swap out color-based segmentation for some grayscale wizardry and contour analysis, making the process smoother and smarter.</p><h3>Let’s Get Started</h3><p>First, install the necessary libraries:</p><pre>pip install opencv-python numpy matplotlib</pre><p>Then, import the required modules:</p><pre>import time<br>import cv2<br>import numpy as np<br>import matplotlib.pyplot as plt<br><br># Start timing execution<br>wall_st = time.time()<br>cpu_st = time.process_time()</pre><h3>Step 1: Load and Convert the Image to Grayscale</h3><p>Since grayscale images simplify contour detection, we first convert our input image to grayscale:</p><pre># Load the image<br>file_name = &#39;./Images/images-v3/file5-upgrade-v1.jpeg&#39;<br>image = cv2.imread(file_name)<br><br># Convert to grayscale<br>gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)<br>cv2.imshow(&#39;Display&#39;, gray_image)</pre><h3>Step 2: Apply Thresholding to Identify Potential ROI</h3><p>We’ll define lower and upper threshold values for grayscale intensity to isolate regions of interest:</p><pre># Define grayscale threshold boundaries<br>grayscale_lower = 50<br>grayscale_upper = 200<br><br># Apply thresholding<br>mask = cv2.inRange(gray_image, grayscale_lower, grayscale_upper)</pre><h3>Step 3: Detect Contours and Identify the Largest One</h3><p>Sometimes, the biggest contour isn’t the right one (size isn’t everything). If the detected contour is too small, we use black color segmentation for a second pass.:</p><pre># Find contours<br>contours, _ = cv2.findContours(mask, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)<br>print(len(contours), &quot;contours found&quot;)<br><br># Sort contours by area (largest first)<br>sorted_contours = sorted(contours, key=cv2.contourArea, reverse=True)<br><br># Find the most relevant contour<br>largest_contour = None<br>for first_contour in range(len(sorted_contours)):<br>    second_contour_end = min(4, len(sorted_contours) - first_contour)<br>    for second_contour in range(1, second_contour_end):<br>        fc_x, fc_y, fc_w, fc_h = cv2.boundingRect(sorted_contours[first_contour])<br>        sc_x, sc_y, sc_w, sc_h = cv2.boundingRect(sorted_contours[first_contour+second_contour])<br>        <br>        if sc_x-fc_x &lt;= 50 and sc_y-fc_y &lt;= 30 and fc_w-sc_w &lt;= 65 and fc_h-sc_h &lt;= 50:<br>            largest_contour = sorted_contours[first_contour]<br>            break<br>    if largest_contour is not None:<br>        break</pre><h3>Step 4: Handle Small Contours and Detect the ROI</h3><p>Sometimes, the biggest contour isn’t the right one (size isn’t everything). If the detected contour is too small, we use black color segmentation for a second pass.:</p><pre>if largest_contour is None or cv2.contourArea(largest_contour) &lt;= 3000:<br>    print(&quot;Refining detection using black color segmentation...&quot;)<br>    hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)<br>    lower_black = np.array([0, 0, 0])<br>    upper_black = np.array([180, 250, 30])<br>    mask = cv2.inRange(hsv, lower_black, upper_black)<br>    contours, _ = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)<br>    largest_contour = max(contours, key=cv2.contourArea) if contours else None</pre><h3>Step 5: Extract and Save the ROI</h3><p>Now comes the moment of truth: extracting the detected region and saving it for later use.</p><pre>if largest_contour is not None:<br>    x, y, w, h = cv2.boundingRect(largest_contour)<br>    x, y, w, h = x+5, y+10, max(w-10, 20), max(h-10, 20)<br>    cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)<br>    <br>    roi = image[y:y+h, x:x+w]<br>    extracted_output_directory = file_name.rsplit(&#39;/&#39;, 2)[0] + &#39;/output/&#39;<br>    extracted_output_filename = file_name.rsplit(&#39;/&#39;, 1)[1].rsplit(&#39;.&#39;)[0] + &#39;-extracted.png&#39;<br>    extracted_filename = extracted_output_directory + extracted_output_filename<br>    <br>    cv2.imwrite(extracted_filename, roi)<br>    cv2.imshow(&#39;ROI&#39;, roi)<br>    cv2.waitKey(0)<br>    cv2.destroyAllWindows()<br>else:<br>    print(&quot;No ROI detected.&quot;)</pre><h3>Step 6: Measure Execution Time</h3><p>Every tech enthusiast loves performance benchmarks, so let’s measure execution time:</p><pre>wall_et = time.time()<br>cpu_et = time.process_time()<br>execution_time = wall_et - wall_st<br>cpu_time = cpu_et - cpu_st<br>print(&#39;Execution time:&#39;, execution_time, &#39;seconds&#39;)<br>print(&#39;CPU time:&#39;, cpu_time, &#39;seconds&#39;)</pre><p>Today, we leveled up our automation game by replacing manual color-based segmentation with a fully automated ROI detection pipeline. Grayscale thresholding and contour analysis now handle everything behind the scenes, freeing you from the burden of marking transactions manually.</p><p>No more guesswork, no more extra effort — just smooth, automated transaction extraction. 🛠️💡</p><p>Got thoughts, questions, or an even crazier idea to improve this? Drop a comment — I’d love to hear from you! 🚀</p><p>Here’s the previous blog:</p><p><a href="https://medium.com/@albinthomas231/image-segmentation-with-opencv-for-finance-592ebfe46b55">Image segmentation with OpenCV for finance</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c74f83624b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>