<?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"><channel><title><![CDATA[LLM In the Actual World Dataflow]]></title><description><![CDATA[LLM In the Actual World Dataflow]]></description><link>https://llm-in-the-actual-world-dataflow.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 10 Sep 2026 02:04:13 GMT</lastBuildDate><atom:link href="https://llm-in-the-actual-world-dataflow.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[LLM In The Actual World Dataflow]]></title><description><![CDATA[Problem Statement
Computers cannot understand natural language (the way people speak or write) or context (the situation or background that gives meaning to language) the way humans do. Generally speaking, computers require structured inputs (organiz...]]></description><link>https://llm-in-the-actual-world-dataflow.hashnode.dev/llm-in-the-actual-world-dataflow</link><guid isPermaLink="true">https://llm-in-the-actual-world-dataflow.hashnode.dev/llm-in-the-actual-world-dataflow</guid><category><![CDATA[data-engineering]]></category><category><![CDATA[Large Language Model]]></category><dc:creator><![CDATA[Jasmeet Singh Bhatia]]></dc:creator><pubDate>Sat, 29 Nov 2025 19:56:29 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-problem-statement"><strong>Problem Statement</strong></h2>
<p>Computers cannot understand natural language (the way people speak or write) or context (the situation or background that gives meaning to language) the way humans do. Generally speaking, computers require structured inputs (organized data in a set format), fixed rules, predefined patterns, and explicit instructions. LLMs (Large Language Models) exist because traditional software and rule-based systems fail when tasks involve unstructured language (free-form text), ambiguity (unclear meaning), and massive variation (many different ways of saying things).</p>
<p><img src="https://miro.medium.com/v2/resize:fit:700/0*GpAnFwA28jcBYikW.png" alt /></p>
<h2 id="heading-real-world-use-case-the-customer-support-email-that-breaks-traditional-software"><strong>Real-World Use Case: The Customer Support Email That Breaks Traditional Software</strong></h2>
<p>Imagine you run an online store. One morning, your customer-support system receives this email:</p>
<blockquote>
<p><em>“Hey, I ordered that blue wireless keyboard last week, and it still hasn’t shown up. I checked the tracking link, but it’s stuck on ‘processed.’ Can you see what’s going on? Also, if it’s going to take too long, I might just switch to the black one instead — whichever ships faster. Thanks!”</em></p>
</blockquote>
<p>To a human, this message is effortless to understand.<br />You instantly grasp:</p>
<ul>
<li><p>The customer is frustrated but polite.</p>
</li>
<li><p>They want to know <strong>why the order is delayed</strong>.</p>
</li>
<li><p>They bought the <strong>blue wireless keyboard</strong>.</p>
</li>
<li><p>They’re open to switching to the <strong>black</strong> model if it arrives sooner.</p>
</li>
<li><p>They don’t want a refund or cancellation — just the fastest path to getting a keyboard.</p>
</li>
</ul>
<p>But to a traditional computer system?<br />This message might as well be random noise.</p>
<p>Rule-based software chokes on everything that makes the email <em>human</em>:</p>
<ul>
<li><p>The language is unstructured — no fixed fields, no predictable sentence shape.</p>
</li>
<li><p>The intent is embedded in conversational phrasing (“can you see what’s going on?”).</p>
</li>
<li><p>The alternative product is mentioned indirectly (“switch to the black one”).</p>
</li>
<li><p>Key details are scattered across multiple sentences and pronouns (“that one”).</p>
</li>
<li><p>The emotional tone (mild frustration, patience) is invisible to rigid systems.</p>
</li>
</ul>
<p>To make a conventional program handle this email, you’d need to force users into rigid form fields or build an ever-expanding list of rules — rules that explode combinatorially as soon as real people write like real people.</p>
<p>This is exactly why LLMs exist.<br />They step into the gap created by unstructured language, ambiguity, implied meaning, and the infinite creativity of human expression. LLMs can interpret the intent, extract the key entities, recognize the conditional request (“if it takes too long, switch colors”), and even detect the customer’s tone — all without demanding that humans talk like structured databases.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:700/0*MEF22CX93G3t_sHk.png" alt /></p>
<h2 id="heading-what-are-large-language-models"><strong>What are Large Language Models?</strong></h2>
<p>LLMs, or Large Language Models, are deep learning models trained on vast datasets. They are based on the transformer neural network architecture, which is highly effective at understanding, generating, and modeling natural language and related content for a variety of tasks.</p>
<h2 id="heading-why-shift-to-transformers"><strong>Why shift to Transformers?</strong></h2>
<p>It is a type of neural network architecture that excels at processing sequential data. It is an evolution of the RNN (recurrent neural network) designed to cover the gap in long-range dependencies. RNNs process sequences step-by-step, which makes it difficult to capture relationships between words, leading to the vanishing gradient problem. It is a challenge in deep learning where the gradients, used to update a neural network’s weights, become extremely small as they are propagated backward through the layers. Transformers utilize a self-attention mechanism to simultaneously weigh the importance of all words in a sequence, thereby overcoming these limitations.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:612/0*BM0R6AMsqCDjuky6.jpeg" alt /></p>
<p>Transformer arch</p>
<h2 id="heading-pretraining-llms"><strong>Pretraining LLMs</strong></h2>
<p>Training starts with a massive amount of data- billions or trillions of words from various sources. It involves cleaning, pre-processing to remove errors, duplicates, and undesirable content.<br />The process of tokenization converts the text into smaller, machine-readable units called “tokens.” These tokens can be as short as individual characters or as long as entire words. Tokenization enables the model to process complex language by breaking it down into components that a machine can evaluate. Initially, training uses self-supervised learning (with unlabelled data) and supervised learning. The model passes tokens through a transformer network using a self-attention mechanism, which enables it to calculate relationships between tokens, even if they are far apart. This helps establish dependencies in language understanding.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:700/0*op7WY5AMY6jVE8gR.png" alt /></p>
<p>Tokenization &amp; meaning derivation</p>
<h2 id="heading-how-to-use-llms"><strong>How to use LLMs</strong></h2>
<p>Once trained, it works by responding to prompts by tokenizing the prompt, converting it into embeddings, and using its transformer to generate text one token at a time, calculating the probabilities for all potential next tokens, and outputting the next. The model does not know the final answer in advance; it uses the statistical relationship it learned in training to predict.</p>
<p><img src="https://miro.medium.com/v2/da:true/resize:fit:0/d9b6fa6dcadc4e1a618bc35ea90c34e7b0121f466e7640fec15bb132eba60048" alt="Become a member" /></p>
<p>The easiest and fastest way to get domain-specific knowledge from a general-purpose LLM is through prompt engineering, which does not require additional training. Users can modify prompts in all sorts of ways. LLMs have strategies to control their outputs, such as LLM temperature, which controls the randomness of text that is generated by LLMs during inference, or top-k/top-p sampling, which limits the set of tokens considered to the most likely ones, balancing creativity and coherence.</p>
<h2 id="heading-types-of-llm-parameters"><strong>Types of LLM Parameters</strong></h2>
<p><img src="https://miro.medium.com/v2/resize:fit:700/0*FlkIOfsWnTDDOTMG" alt /></p>
<p>Parameters</p>
<h2 id="heading-there-are-three-primary-categories-weights-biases-and-hyperparameters"><strong><em>There are three primary categories: Weights, Biases, and Hyperparameters.</em></strong></h2>
<ol>
<li><p>Weights: Numerical values that represent the importance that the LLM assigns to a specific input. The input weight is proportional to the relevance of the model’s output. Within neural networks, weights are multipliers that determine the signal strength from one neural network layer to the next. It affects how a network propagates data forward through its layers.</p>
</li>
<li><p>Biases: Constant values added to a signal’s value from the previous layers. The model uses biases to allow neurons to activate under conditions where the weight alone might not be sufficient to pass through the activation function. Like weights, biases are adjusted with backpropagation during training to optimize model performance and minimize errors.</p>
</li>
<li><p>Hyperparameters: External settings that determine a model’s behavior, shape, size, resource use, and other characteristics. It is a significant pillar of LLM customization that includes:</p>
</li>
</ol>
<ul>
<li><p><strong><em>Number of Layers:</em></strong> Neural networks are made of layers of neurons or nodes. The more layers between the initial input layer and the final output layer, the more complex the model. It also has its downsides; if the model has too many layers for a task that does not require it can lead to wasteful computational resources and overfitting.</p>
</li>
<li><p><strong><em>Context Window:</em></strong> The maximum number of tokens the model can field while maintaining coherence across the entire input sequence. It also determines the length of the conversation that a model can maintain without losing track of previous content. Larger context windows lead to greater accuracy, fewer hallucinations, and the ability to process larger documents or have longer conversations.</p>
</li>
<li><p><strong><em>Temperature:</em></strong> Randomness or creativity deal. Raising the temperature increases the probability distribution for the next words that appear in the model’s output during text generation, i.e., proportional to randomness. In the case of a chatbot, which needs to be creative, it needs a higher temperature to create human-like text. But for high regulatory fields such as law or finance, it must adhere to strict requirements.</p>
</li>
<li><p><strong><em>Top-p:</em></strong> Like temperature, top-p sampling also affects word diversity in generated text outputs. Top-p works by setting a probability threshold p for the next token in an output sequence. The model is allowed to generate responses by using tokens within the probability limit.</p>
</li>
<li><p><strong><em>Top-k:</em></strong> The <em>k</em> value sets the limit for the number of terms that can be considered as the next in the sequence. Terms are ordered based on probability, and the top <em>k</em> terms are chosen as candidates.</p>
</li>
<li><p><strong><em>Token number:</em></strong> The token number or max tokens hyperparameter sets an upper limit for output token length. Smaller token number values are ideal for quick tasks such as chatbot conversations and summarization — tasks that can be handled by small language models as well as LLMs.</p>
</li>
<li><p><strong><em>Learning Rate:</em></strong> Critical hyperparameter that affects the speed at which the model adjusts its weights and biases during training and fine-tuning. These processes often use a learning algorithm known as gradient descent.</p>
</li>
<li><p><strong><em>Frequency penalty:</em></strong> Helps prevent models from overusing terms within the same outputs. Once a term appears in the output, the frequency penalty dissuades the model from reusing it again later.</p>
</li>
<li><p><strong><em>Presence penalty:</em></strong> Related hyperparameter that works similarly to the frequency penalty, except it only applies once. The presence penalty lowers a term’s logit value by the same amount regardless of how often that term is present in the output, so long as it appears at least once.</p>
</li>
<li><p><strong><em>Stop Sequence:</em></strong> Preset string of tokens that, when it appears, causes the model to end the output sequence. For example, if a model is designed to output a single sentence at a time, the stop sequence might be a period.</p>
</li>
</ul>
<h2 id="heading-deterministic-llm-pipeline-temperature-0"><strong>Deterministic LLM Pipeline (Temperature = 0)</strong></h2>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> json
<span class="hljs-keyword">import</span> openai

<span class="hljs-comment"># --------------------------------------------------------------</span>
<span class="hljs-comment"># Model configuration</span>
<span class="hljs-comment"># --------------------------------------------------------------</span>
<span class="hljs-comment"># Using a deterministic LLM response for classification/extraction.</span>
<span class="hljs-comment"># temperature = 0 ensures:</span>
<span class="hljs-comment">#   - reproducibility</span>
<span class="hljs-comment">#   - no creativity/randomness</span>
<span class="hljs-comment">#   - consistent behavior for pipelines</span>
<span class="hljs-comment">#</span>
<span class="hljs-comment"># "gpt-4.1" is fast + capable enough for structured outputs.</span>
MODEL_NAME = <span class="hljs-string">"gpt-4.1"</span>
TEMPERATURE = <span class="hljs-number">0.0</span>

<span class="hljs-comment"># --------------------------------------------------------------</span>
<span class="hljs-comment"># Function: call_llm</span>
<span class="hljs-comment"># --------------------------------------------------------------</span>
<span class="hljs-comment"># This is the *core* wrapper that all downstream logic uses.</span>
<span class="hljs-comment"># It creates a single, standardized interface for:</span>
<span class="hljs-comment">#   - sending messages to the LLM</span>
<span class="hljs-comment">#   - controlling temperature, tokens, safety</span>
<span class="hljs-comment">#   - parsing JSON outputs</span>
<span class="hljs-comment">#   - error handling (minimal version for clarity)</span>
<span class="hljs-comment">#</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">call_llm</span>(<span class="hljs-params">prompt: str</span>) -&gt; dict:</span>
    <span class="hljs-string">"""
    Execute an LLM call and return a JSON-decoded response.
    ALL tasks (categorization/extraction/summarization/etc.) reuse this.
    """</span>

    response = openai.ChatCompletion.create(
        model=MODEL_NAME,

        <span class="hljs-comment"># messages is a LIST because you can include system / assistant / user roles.</span>
        <span class="hljs-comment"># Here we use only user content for simplicity.</span>
        messages=[
            {
                <span class="hljs-string">"role"</span>: <span class="hljs-string">"user"</span>,
                <span class="hljs-string">"content"</span>: prompt
            }
        ],

        <span class="hljs-comment"># temperature controls randomness (0 = deterministic)</span>
        temperature=TEMPERATURE,

        <span class="hljs-comment"># max_tokens controls how long the model can respond.</span>
        <span class="hljs-comment"># Keeping it high enough to ensure JSON fits.</span>
        max_tokens=<span class="hljs-number">500</span>,

        <span class="hljs-comment"># top_p is another randomness controller (we keep default 1)</span>
        <span class="hljs-comment"># top_p lower = more conservative sampling.</span>
        top_p=<span class="hljs-number">1.0</span>,

        <span class="hljs-comment"># frequency_penalty discourages repeated tokens (kept 0 here)</span>
        frequency_penalty=<span class="hljs-number">0.0</span>,

        <span class="hljs-comment"># presence_penalty encourages introducing new topics (kept 0)</span>
        presence_penalty=<span class="hljs-number">0.0</span>,
    )

    <span class="hljs-comment"># Extract the raw string JSON content</span>
    raw_output = response[<span class="hljs-string">"choices"</span>][<span class="hljs-number">0</span>][<span class="hljs-string">"message"</span>][<span class="hljs-string">"content"</span>]

    <span class="hljs-comment"># Convert JSON string → Python dict</span>
    <span class="hljs-keyword">return</span> json.loads(raw_output)

<span class="hljs-comment"># --------------------------------------------------------------</span>
<span class="hljs-comment"># Function: analyze_customer_email</span>
<span class="hljs-comment"># --------------------------------------------------------------</span>
<span class="hljs-comment"># This is our CASE-STUDY example:</span>
<span class="hljs-comment"># We take a customer support email and extract structured attributes.</span>
<span class="hljs-comment">#</span>
<span class="hljs-comment"># The LLM is instructed to behave as an "AI support triage system."</span>
<span class="hljs-comment"># All instructions are baked into one clear prompt.</span>
<span class="hljs-comment">#</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">analyze_customer_email</span>(<span class="hljs-params">email_text: str</span>) -&gt; dict:</span>
    <span class="hljs-string">"""
    Use LLM to analyze a customer’s email and extract:
        - issue_category
        - urgency_level
        - sentiment
        - summary
        - recommended_action

    Returns fully structured JSON.
    """</span>

    prompt = <span class="hljs-string">f"""
    You are an AI system that analyzes customer support emails and produces
    STRICTLY structured JSON. You MUST follow the output schema exactly.

    Extract and infer the following fields:
      - "issue_category": one of ["billing", "technical", "account", "refund", "other"]
      - "urgency_level": one of ["low", "medium", "high"]
      - "sentiment": one of ["positive", "neutral", "negative"]
      - "summary": short 1-2 line summary of the email
      - "recommended_action": action a support agent should take

    RULES:
      - Respond ONLY in JSON.
      - No explanation outside JSON.
      - Be deterministic and consistent.

    Email:
    \"\"\"
    <span class="hljs-subst">{email_text}</span>
    \"\"\"
    """</span>

    <span class="hljs-keyword">return</span> call_llm(prompt)

<span class="hljs-comment"># --------------------------------------------------------------</span>
<span class="hljs-comment"># Main Pipeline Entrypoint</span>
<span class="hljs-comment"># --------------------------------------------------------------</span>
<span class="hljs-comment"># This demonstrates the simplest real workflow:</span>
<span class="hljs-comment">#   Input → LLM → structured output → returned upstream</span>
<span class="hljs-comment">#</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">run_pipeline</span>(<span class="hljs-params">email_text: str</span>) -&gt; dict:</span>
    <span class="hljs-string">"""
    Complete pipeline for processing a single customer email.
    Easy to integrate in APIs, batch jobs, or downstream scoring.
    """</span>
    result = analyze_customer_email(email_text)
    <span class="hljs-keyword">return</span> result

<span class="hljs-comment"># --------------------------------------------------------------</span>
<span class="hljs-comment"># Example Usage (only runs if this file is executed manually)</span>
<span class="hljs-comment"># --------------------------------------------------------------</span>
<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">"__main__"</span>:
    sample_email = <span class="hljs-string">"""
    Hi, my account was suddenly locked today and I can’t access my
    subscription. I need this fixed ASAP because my work depends on it.
    """</span>

    print(<span class="hljs-string">"Input Email:\n"</span>, sample_email)
    print(<span class="hljs-string">"\nLLM Output:"</span>)
    print(run_pipeline(sample_email))
</code></pre>
<h2 id="heading-final-thoughts"><strong>Final Thoughts</strong></h2>
<p>Together, these parameters — weights, biases, and hyperparameters — define the behavior, capacity, and personality of an LLM. They control everything from how much context the model can remember to how creative its responses are, to how quickly it learns during training. Understanding these knobs is essential because they form the foundation of every customization technique we use today.</p>
<p>And this is where the bridge to the next stage begins.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:700/0*2KWzp0Xjt3jVgH6B.jpg" alt /></p>
<p>In real-world systems, we rarely retrain a model from scratch. Instead, we <em>use</em> these parameters — especially the inference-time hyperparameters — to shape the model’s behavior through <strong>prompt engineering</strong>, <strong>guided reasoning</strong>, <strong>structured outputs</strong>, and <strong>safety mechanisms</strong>.</p>
<p>This is the layer where organizations transform a general-purpose LLM into a domain-aligned, predictable, and governable system.</p>
<p>In the next post, we’ll explore how these concepts come together: how prompts are designed, refined, evaluated, governed, and deployed inside modern AI pipelines. This is where the model stops being just a mathematical object — and becomes a reliable component in a production workflow.</p>
<p><em>Stay tuned for more insights! 🚀</em></p>
]]></content:encoded></item></channel></rss>