<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Luca Lullo</title>
    <description>The latest articles on DEV Community by Luca Lullo (@lucalullo).</description>
    <link>https://dev.to/lucalullo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4231126%2Fce1aae25-404f-480e-a817-ab2a39956818.png</url>
      <title>DEV Community: Luca Lullo</title>
      <link>https://dev.to/lucalullo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lucalullo"/>
    <language>en</language>
    <item>
      <title>Building CodAdapt: An Experimental Approach to Tabular Machine Learning</title>
      <dc:creator>Luca Lullo</dc:creator>
      <pubDate>Wed, 25 Nov 2026 12:40:45 +0000</pubDate>
      <link>https://dev.to/lucalullo/building-codadapt-an-experimental-approach-to-tabular-machine-learning-1dn0</link>
      <guid>https://dev.to/lucalullo/building-codadapt-an-experimental-approach-to-tabular-machine-learning-1dn0</guid>
      <description>&lt;h2&gt;
  
  
  Why I started CodAdapt
&lt;/h2&gt;

&lt;p&gt;I've been interested in experimenting with alternative approaches to machine learning, especially for tabular data.&lt;/p&gt;

&lt;p&gt;That's what led me to start CodAdapt, a personal research and experimentation project built around a different learning architecture.&lt;/p&gt;

&lt;p&gt;The goal wasn't to recreate XGBoost, Random Forest, or other established algorithms. I wanted to explore whether a model based on adaptive coded memory and shared multi-resolution encoding could offer an interesting balance between predictive quality, computational efficiency, memory usage, and ease of use.&lt;/p&gt;

&lt;p&gt;I also wanted the library to feel familiar to Python developers, with an API similar to scikit-learn.&lt;/p&gt;

&lt;h2&gt;
  
  
  The idea behind CodAdapt
&lt;/h2&gt;

&lt;p&gt;CodAdapt takes a different approach from traditional tree-based models and neural networks.&lt;/p&gt;

&lt;p&gt;Instead of learning a collection of decision trees or layers of neural network weights, it encodes numerical and categorical features and learns residual contributions through lookup memories.&lt;/p&gt;

&lt;p&gt;The architecture uses multiple encoding levels, allowing the model to work with different levels of detail while keeping the lookup budget bounded.&lt;/p&gt;

&lt;p&gt;The library supports binary and multiclass classification, single-target regression, numerical and categorical features, and missing values.&lt;/p&gt;

&lt;p&gt;One thing I wanted to preserve throughout development was a simple interface, regardless of the underlying algorithm.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using CodAdapt in Python
&lt;/h2&gt;

&lt;p&gt;CodAdapt is available on PyPI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip install codadapt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's a small classification example using scikit-learn's Breast Cancer dataset:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;datasets&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;load_breast_cancer&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;model_selection&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;train_test_split&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;codadapt&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;CodAdaptClassifier&lt;/span&gt;

&lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;load_breast_cancer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;return_X_y&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;as_frame&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nc"&gt;X_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;X_test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_test&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;train_test_split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;test_size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;random_state&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stratify&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;CodAdaptClassifier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;random_state&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;X_train&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_train&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Test accuracy:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;score&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;X_test&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y_test&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The idea is to keep the usual &lt;code&gt;fit&lt;/code&gt;, &lt;code&gt;predict&lt;/code&gt;, and &lt;code&gt;score&lt;/code&gt; workflow while experimenting with a different learning mechanism.&lt;/p&gt;

&lt;p&gt;This is a basic usage example, not a reproduction of the project's benchmark protocol.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the benchmarks showed
&lt;/h2&gt;

&lt;p&gt;One of the most interesting parts of developing CodAdapt has been evaluating its strengths and weaknesses against established models.&lt;/p&gt;

&lt;p&gt;The repository includes an exploratory benchmark panel covering 14 dataset origins, comparing CodAdapt 2.1.0 with fixed configurations of Logistic/Ridge, Random Forest, HistGradientBoosting, XGBoost, LightGBM, and CatBoost.&lt;/p&gt;

&lt;p&gt;The results are mixed.&lt;/p&gt;

&lt;p&gt;For example, on the Danish occupancy dataset, CodAdapt recorded:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ROC-AUC: 0.939468&lt;/li&gt;
&lt;li&gt;Fit and preparation time: 0.079 seconds&lt;/li&gt;
&lt;li&gt;Serialized model size: approximately 35.7 KiB&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The quality-selected CatBoost comparator recorded:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ROC-AUC: 0.951437&lt;/li&gt;
&lt;li&gt;Fit and preparation time: 0.5687 seconds&lt;/li&gt;
&lt;li&gt;Serialized model size: approximately 86.3 KiB&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Under this specific benchmark configuration, CodAdapt was faster to fit and produced a smaller serialized model, but CatBoost achieved better predictive quality.&lt;/p&gt;

&lt;p&gt;Other datasets showed less favorable results for CodAdapt, particularly in some multiclass classification and regression tasks.&lt;/p&gt;

&lt;p&gt;These results don't establish that CodAdapt is generally better than existing algorithms.&lt;/p&gt;

&lt;p&gt;They show that different learning architectures can have different trade-offs, and that computational efficiency alone doesn't tell the whole story.&lt;/p&gt;

&lt;p&gt;The benchmark panel is exploratory, not an independent certification of predictive superiority.&lt;/p&gt;

&lt;h2&gt;
  
  
  What changed in version 2.2.0?
&lt;/h2&gt;

&lt;p&gt;CodAdapt has evolved through multiple releases.&lt;/p&gt;

&lt;p&gt;Version 2.2.0 focuses on technical improvements rather than changing the underlying predictive algorithm.&lt;/p&gt;

&lt;p&gt;It introduces combined classifier outputs, prepared inputs for repeated inference requests, and optional compressed model snapshots.&lt;/p&gt;

&lt;p&gt;The goal is to improve particular inference and storage workflows without making unsupported claims about predictive accuracy.&lt;/p&gt;

&lt;p&gt;The current release is pure Python and requires Python 3.12 or later.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I learned
&lt;/h2&gt;

&lt;p&gt;Building CodAdapt has been an opportunity to explore much more than a different algorithm.&lt;/p&gt;

&lt;p&gt;I've worked on model architecture, numerical and categorical preprocessing, API design, performance measurement, serialization, testing, and compatibility.&lt;/p&gt;

&lt;p&gt;One important lesson is that developing an algorithm and demonstrating that it performs competitively are two different challenges.&lt;/p&gt;

&lt;p&gt;A model can perform well in certain situations and poorly in others. Understanding those differences is more useful than looking for a single benchmark where it wins.&lt;/p&gt;

&lt;p&gt;There is still plenty of room for experimentation and independent evaluation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sharing the project
&lt;/h2&gt;

&lt;p&gt;CodAdapt is open source and available on GitHub and PyPI.&lt;/p&gt;

&lt;p&gt;The repository includes source code, documentation, examples, benchmark data, methodology, and known limitations.&lt;/p&gt;

&lt;p&gt;I originally started this as a personal research project, but decided to share it so others can explore the approach, test it, or provide technical feedback.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/lucalullo/codadapt" rel="noopener noreferrer"&gt;https://github.com/lucalullo/codadapt&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PyPI:&lt;/strong&gt; &lt;a href="https://pypi.org/project/codadapt/" rel="noopener noreferrer"&gt;https://pypi.org/project/codadapt/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Benchmarks:&lt;/strong&gt; &lt;a href="https://github.com/lucalullo/codadapt/tree/main/benchmarks" rel="noopener noreferrer"&gt;https://github.com/lucalullo/codadapt/tree/main/benchmarks&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I'm especially interested in feedback on the learning architecture and how to evaluate its predictive-quality and resource trade-offs more rigorously.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AI disclosure:&lt;/strong&gt; I use AI coding assistants, including Codex, to support development, testing, and code review. I also used AI assistance to translate, organize, and polish this article in English. CodAdapt is my personal research and experimentation project, and the technical choices, results, and limitations presented here are based on the project's implementation and documentation.&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>python</category>
      <category>opensource</category>
      <category>datascience</category>
    </item>
    <item>
      <title>Understanding Causal Masking in LLMs with Pure Python</title>
      <dc:creator>Luca Lullo</dc:creator>
      <pubDate>Sun, 15 Nov 2026 20:40:10 +0000</pubDate>
      <link>https://dev.to/lucalullo/understanding-causal-masking-in-llms-with-pure-python-4o5m</link>
      <guid>https://dev.to/lucalullo/understanding-causal-masking-in-llms-with-pure-python-4o5m</guid>
      <description>&lt;h2&gt;
  
  
  Why I started looking into causal masking
&lt;/h2&gt;

&lt;p&gt;I've been working on a personal learning project called &lt;em&gt;Building LLM Technologies&lt;/em&gt;, where I explore individual components of language models using small Python notebooks.&lt;/p&gt;

&lt;p&gt;The idea is to understand one mechanism at a time, without having to build or train an entire language model.&lt;/p&gt;

&lt;p&gt;One of the first things I looked at was causal masking.&lt;/p&gt;

&lt;p&gt;It's a relatively simple concept, but an important one for understanding how autoregressive language models work.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's a causal mask?
&lt;/h2&gt;

&lt;p&gt;When a model processes a sequence of tokens, attention allows each position to use information from other positions.&lt;/p&gt;

&lt;p&gt;But in a causal language model, a position shouldn't be able to look at future tokens when predicting what comes next.&lt;/p&gt;

&lt;p&gt;For example, consider:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;["I", "love", "Python"]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The first token can only attend to itself. The second can attend to the first two tokens. The third can attend to all three.&lt;/p&gt;

&lt;p&gt;We can represent this with a simple matrix.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;tokens&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"I"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"love"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Python"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;mask&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;mask&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[1, 0, 0]
[1, 1, 0]
[1, 1, 1]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;1&lt;/code&gt; means attention is allowed, while &lt;code&gt;0&lt;/code&gt; means that position is blocked.&lt;/p&gt;

&lt;p&gt;The triangular structure ensures that each position can only access itself and earlier positions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Applying the mask to attention scores
&lt;/h2&gt;

&lt;p&gt;A Transformer normally calculates attention scores from Query and Key vectors.&lt;/p&gt;

&lt;p&gt;To keep this example simple, I used predefined scores:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;masked_scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;new_row&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;mask&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;new_row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;score&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;new_row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;999&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;masked_scores&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;new_row&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;masked_scores&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[2, -999, -999]
[2, 4, -999]
[0, 2, 2]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The scores for future positions have been replaced with a very large negative value.&lt;/p&gt;

&lt;p&gt;I used &lt;code&gt;-999&lt;/code&gt; to keep the example straightforward. Real implementations generally use negative infinity or an appropriate masking value.&lt;/p&gt;

&lt;h2&gt;
  
  
  What happens after softmax?
&lt;/h2&gt;

&lt;p&gt;Attention scores are converted into probabilities using softmax.&lt;/p&gt;

&lt;p&gt;Here's the minimal implementation from my notebook:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;softmax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;exps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;exps&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;exps&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;masked_scores&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;softmax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[1.0, 0.0, 0.0]
[0.11920292202211756, 0.8807970779778824, 0.0]
[0.06337893833303762, 0.4683105308334812, 0.4683105308334812]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's the interesting part.&lt;/p&gt;

&lt;p&gt;The first position assigns all its attention to itself. The second distributes attention across the first two positions. The third can attend to all three.&lt;/p&gt;

&lt;p&gt;With the large negative masking value used here, future positions receive attention weights that are effectively zero after softmax.&lt;/p&gt;

&lt;p&gt;This is how masking prevents information from later positions from influencing earlier ones.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this example doesn't cover
&lt;/h2&gt;

&lt;p&gt;This is intentionally a small educational example.&lt;/p&gt;

&lt;p&gt;The attention scores are predefined rather than calculated from learned Query and Key projections. There's no training process or complete Transformer implementation.&lt;/p&gt;

&lt;p&gt;The softmax function is also simplified and isn't intended as a numerically stable production implementation.&lt;/p&gt;

&lt;p&gt;I wanted to isolate the masking mechanism and make its effect visible through a few small matrices.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I found this useful
&lt;/h2&gt;

&lt;p&gt;What I like about studying LLM components this way is being able to inspect every intermediate result.&lt;/p&gt;

&lt;p&gt;Instead of starting with a complete Transformer and trying to understand everything at once, I can focus on one mechanism, see what changes, and then move on to the next.&lt;/p&gt;

&lt;p&gt;Causal masking was the first of ten small notebooks I created following this approach.&lt;/p&gt;

&lt;p&gt;I've made the project available on GitHub and Kaggle in case anyone else finds it useful for learning.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/lucalullo/building-llm-technologies" rel="noopener noreferrer"&gt;https://github.com/lucalullo/building-llm-technologies&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Kaggle:&lt;/strong&gt; &lt;a href="https://www.kaggle.com/code/lucalullo/building-llm-technologies" rel="noopener noreferrer"&gt;https://www.kaggle.com/code/lucalullo/building-llm-technologies&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Have you tried learning Transformer internals by implementing individual components from scratch?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Writing note:&lt;/strong&gt; I used AI assistance to translate, organize, and polish this article in English. The project, code examples, and technical content are my own.&lt;/p&gt;

</description>
      <category>llm</category>
      <category>machinelearning</category>
      <category>python</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Building an AI Agent from Scratch in Python: What I Learned</title>
      <dc:creator>Luca Lullo</dc:creator>
      <pubDate>Mon, 09 Nov 2026 12:45:22 +0000</pubDate>
      <link>https://dev.to/lucalullo/building-an-ai-agent-from-scratch-in-python-what-i-learned-1hbe</link>
      <guid>https://dev.to/lucalullo/building-an-ai-agent-from-scratch-in-python-what-i-learned-1hbe</guid>
      <description>&lt;h2&gt;
  
  
  Why I started this project
&lt;/h2&gt;

&lt;p&gt;I wanted to understand how AI agents actually work, beyond just using a framework.&lt;/p&gt;

&lt;p&gt;So I decided to build a small one from scratch in Python.&lt;/p&gt;

&lt;p&gt;It started as a personal learning exercise. I wasn't trying to build something production-ready or create another agent framework. I just wanted to understand the different components, how they interact, and what happens when you add more capabilities.&lt;/p&gt;

&lt;p&gt;I eventually ended up with nine versions of the same project, each introducing one new architectural concept.&lt;/p&gt;

&lt;p&gt;After finishing it, I thought it might be useful to share the process with anyone interested in learning how agents work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Starting with simple rules
&lt;/h2&gt;

&lt;p&gt;The first version was intentionally basic.&lt;/p&gt;

&lt;p&gt;It could receive a request, choose a tool using predefined rules, extract arguments, execute the tool, and store the result.&lt;/p&gt;

&lt;p&gt;Nothing fancy. No LLM, no external API, no framework.&lt;/p&gt;

&lt;p&gt;But that simplicity made it easier to see what each component was actually doing.&lt;/p&gt;

&lt;p&gt;From there, I started separating responsibilities. First the Executor, then a more generic Parser, followed by planning, memory management, and a Tool Registry.&lt;/p&gt;

&lt;p&gt;My approach was simple: one version, one concept, one architectural improvement.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding an LLM
&lt;/h2&gt;

&lt;p&gt;Only after building those components did I introduce a language model.&lt;/p&gt;

&lt;p&gt;I used Qwen2.5-0.5B-Instruct, running locally, first for choosing tools and later for extracting arguments from natural language.&lt;/p&gt;

&lt;p&gt;What I found useful was that I could replace the rule-based components without having to redesign the entire system.&lt;/p&gt;

&lt;p&gt;The rest of the architecture stayed mostly the same.&lt;/p&gt;

&lt;p&gt;It helped me understand that the LLM is just one part of the agent. The surrounding code still handles tool execution, validation, planning, and state.&lt;/p&gt;

&lt;h2&gt;
  
  
  From one step to multiple steps
&lt;/h2&gt;

&lt;p&gt;The final version introduced basic multi-step execution.&lt;/p&gt;

&lt;p&gt;For example, given this request:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Add 2 and 3, then multiply the result by 4.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The agent creates two steps, executes the addition, and passes the result to the multiplication step.&lt;/p&gt;

&lt;p&gt;The final answer is 20.&lt;/p&gt;

&lt;p&gt;It's a small example, but it brings together the components developed throughout the project.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I learned
&lt;/h2&gt;

&lt;p&gt;The biggest takeaway for me was that building an agent became much less confusing once I stopped treating it as one big system.&lt;/p&gt;

&lt;p&gt;Separating routing, parsing, execution, planning, and memory made it easier to understand what each part was responsible for.&lt;/p&gt;

&lt;p&gt;It also made frameworks like LangChain or CrewAI easier to approach, because I now had a clearer idea of the problems those frameworks are trying to solve.&lt;/p&gt;

&lt;p&gt;There are still plenty of limitations. The planner uses simple rules, memory is stored in a Python list, and the local LLM can make mistakes when choosing tools or extracting arguments.&lt;/p&gt;

&lt;p&gt;But that's fine for what I wanted to learn.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sharing the project
&lt;/h2&gt;

&lt;p&gt;I've made the whole project available on GitHub, with all nine versions, Jupyter notebooks, architecture diagrams, and documentation in English and Italian.&lt;/p&gt;

&lt;p&gt;There's also an executable notebook on Kaggle.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/lucalullo/building-ai-agent" rel="noopener noreferrer"&gt;https://github.com/lucalullo/building-ai-agent&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Kaggle:&lt;/strong&gt; &lt;a href="https://www.kaggle.com/code/lucalullo/building-ai-agent" rel="noopener noreferrer"&gt;https://www.kaggle.com/code/lucalullo/building-ai-agent&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I originally built this for myself, but I hope the step-by-step approach might help someone else understand agent architecture a little better.&lt;/p&gt;

&lt;p&gt;If you've tried building an agent without a framework, I'd be interested to hear how you approached it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Writing note:&lt;/strong&gt; I used AI assistance to translate, organize, and polish this article in English. The project, its implementation, and the technical content are my own.&lt;/p&gt;

</description>
      <category>python</category>
      <category>ai</category>
      <category>opensource</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
