<?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: Guillermo Alcántara</title>
    <description>The latest articles on DEV Community by Guillermo Alcántara (@echo9k).</description>
    <link>https://dev.to/echo9k</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%2F1104592%2F688bc0ea-dc43-45a2-8f65-e7b639ad1994.jpeg</url>
      <title>DEV Community: Guillermo Alcántara</title>
      <link>https://dev.to/echo9k</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/echo9k"/>
    <language>en</language>
    <item>
      <title>Train the Harness First: Measuring, Delegating, and Consolidating Agent Self-Improvement</title>
      <dc:creator>Guillermo Alcántara</dc:creator>
      <pubDate>Mon, 02 Nov 2026 10:28:54 +0000</pubDate>
      <link>https://dev.to/echo9k/train-the-harness-first-measuring-delegating-and-consolidating-agent-self-improvement-4am9</link>
      <guid>https://dev.to/echo9k/train-the-harness-first-measuring-delegating-and-consolidating-agent-self-improvement-4am9</guid>
      <description>&lt;h2&gt;
  
  
  Two models, two rankings
&lt;/h2&gt;

&lt;p&gt;A frozen GPT-5.6 Sol and a frozen Claude Fable 5 each gain about 35 points of held-out score by rewriting their own tools and notes. Sol levels off after about $120 of learning cost; Fable after about $610. Sol gets the far better plasticity score, 298 points per $1,000 against 57, but Fable ends with the higher score.&lt;/p&gt;

&lt;p&gt;So which one should you deploy? The &lt;em&gt;Agent Plasticity&lt;/em&gt; paper is careful not to answer that, and its headline number can't. Its learning curves can, though, and three other recent papers turn them into a strategy: let a strong model improve its harness, use that harness to hand work down to cheaper models, and on open weights, consolidate what has stabilized into the weights.&lt;/p&gt;

&lt;p&gt;One detail from the paper's live games sets the stakes. At checkpoint 0, Fable reasoned through a chess game move by move with about 102,000 output tokens. At checkpoint 20, it loaded the engine it had written during training and used 2,000 to 7,000. The agent got better and cheaper to run at once, and the plasticity metric counts only the first.&lt;/p&gt;

&lt;h2&gt;
  
  
  What agent plasticity measures
&lt;/h2&gt;

&lt;p&gt;Agent plasticity is held-out gain per dollar of learning cost, with model weights frozen. All learning goes into a persistent inventory of Python tools, skills and notes that each fresh-context episode inherits. Held-out games never reach the reflection step, so gains there are evidence that the artifacts generalize.&lt;/p&gt;

&lt;p&gt;The headline number, P^sat, fits a saturating curve to held-out score against cumulative learning cost. It divides the fitted gain at saturation (the first checkpoint reaching 90% of the fitted rise) by the cost of getting there. Learning cost includes rejected edits; held-out evaluation and deployment costs are excluded.&lt;/p&gt;

&lt;p&gt;The authors scope the metric narrowly: plasticity "does not define self-improvement itself." It measures one property, how efficiently capability is acquired, and they note it depends on provider prices and on the saturation fit. Everything below builds on that scoping rather than arguing with it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The question plasticity doesn't answer
&lt;/h2&gt;

&lt;p&gt;A deployment has a quality bar τ, and a model whose ceiling sits below τ is useless however efficiently it learns. In Chess (Hard), Sol climbs from near 0% to 36.9% on held-out games. For a team that needs 70%, that curve is irrelevant.&lt;/p&gt;

&lt;p&gt;Score points are also not equally valuable across the range. Going from 70% to 85% halves the error rate; going from 0% to 15% barely dents it. Relative error reduction is a fairer measure of how much a model learned:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Chess (Hard), held-out ID&lt;/th&gt;
&lt;th&gt;Start&lt;/th&gt;
&lt;th&gt;Mean of ckpts 16–20&lt;/th&gt;
&lt;th&gt;Gain (points)&lt;/th&gt;
&lt;th&gt;Error removed&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Claude Fable 5&lt;/td&gt;
&lt;td&gt;37.5%&lt;/td&gt;
&lt;td&gt;73.3%&lt;/td&gt;
&lt;td&gt;35.8&lt;/td&gt;
&lt;td&gt;57%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GPT-5.6 Sol&lt;/td&gt;
&lt;td&gt;~0%&lt;/td&gt;
&lt;td&gt;36.9%&lt;/td&gt;
&lt;td&gt;~36.9&lt;/td&gt;
&lt;td&gt;37%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;On points the two gained about the same; on error removed, Fable learned more. Log-odds would be more principled but diverge at Sol's 0% start, which is the headroom problem in another form. These are Chess (Hard) numbers; the 298 vs 57 plasticity figures average chess, Go and Hex.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cost-to-threshold: a deployment metric from the same curves
&lt;/h2&gt;

&lt;p&gt;For deployment, read each model's fitted curve at your own threshold τ, not at its own saturation point. Call the learning spend at which model m reliably reaches τ its cost-to-threshold, C_m(τ). Then pick the model with the lowest total cost over N deployed tasks, among models whose ceiling clears τ:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tex"&gt;&lt;code&gt;&lt;span class="k"&gt;\min&lt;/span&gt;&lt;span class="p"&gt;_&lt;/span&gt;m &lt;span class="k"&gt;\;&lt;/span&gt; C&lt;span class="p"&gt;_&lt;/span&gt;m(&lt;span class="k"&gt;\tau&lt;/span&gt;) + N&lt;span class="k"&gt;\left&lt;/span&gt;(c&lt;span class="p"&gt;^{&lt;/span&gt;&lt;span class="k"&gt;\text&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;act&lt;span class="p"&gt;}}_&lt;/span&gt;m + p&lt;span class="p"&gt;^{&lt;/span&gt;&lt;span class="k"&gt;\text&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;fail&lt;span class="p"&gt;}}_&lt;/span&gt;m &lt;span class="k"&gt;\,&lt;/span&gt; c&lt;span class="p"&gt;^{&lt;/span&gt;&lt;span class="k"&gt;\text&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;review&lt;span class="p"&gt;}}&lt;/span&gt;&lt;span class="k"&gt;\right&lt;/span&gt;) &lt;span class="k"&gt;\quad&lt;/span&gt; &lt;span class="k"&gt;\text&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;subject to&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;\quad&lt;/span&gt; S&lt;span class="p"&gt;_&lt;/span&gt;m&lt;span class="p"&gt;^{&lt;/span&gt;&lt;span class="k"&gt;\infty&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;\ge&lt;/span&gt; &lt;span class="k"&gt;\tau&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here c^act is the per-task acting cost after learning, p^fail the failure rate at τ, and c^review the cost of catching one failure. Three things change relative to P^sat:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Feasibility comes first.&lt;/strong&gt; A model that cannot reach τ is excluded, whatever its efficiency.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Operating cost is in the objective.&lt;/strong&gt; Artifacts can cut per-task cost, as Fable's engine did, or raise it when a bloated inventory is reread every episode.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Volume decides.&lt;/strong&gt; At small N, pick the best starting score per acting dollar. At large N, ceilings and learning slopes dominate.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;How long to keep learning is a marginal question, not an average one. Keep investing while N·v·S′(C) exceeds 1 + N·c′_act(C), where v is the value of one score point. P^sat is an average return, gain divided by cost.&lt;/p&gt;

&lt;p&gt;One definition needs care, because learning curves are not monotone. Claude Opus 5's Go score collapsed after a single bad tool edit at its final checkpoint. I define C_m(τ) as the cost after which the lower confidence bound of held-out score stays at or above τ for the rest of the run, and report "not reached" otherwise. Crossing τ once and falling back is not reaching it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Units: what dollars, GPU-hours, FLOPs and time each answer
&lt;/h2&gt;

&lt;p&gt;Dollars are the right unit for a deployment decision and the wrong one for a scientific claim. Prices move with vendor strategy, so an agent's plasticity changes when a price list does. Raw token counts are no fix: input, cached, output and reasoning tokens cost different amounts, and weighting them equally is just another price list.&lt;/p&gt;

&lt;p&gt;Tokens also aren't comparable across models. Tokenizers differ, and a token from a large dense model is far more compute than one from a small MoE.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Unit&lt;/th&gt;
&lt;th&gt;Answers&lt;/th&gt;
&lt;th&gt;Caveat&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Dollars at a dated market price&lt;/td&gt;
&lt;td&gt;Comparison with published results&lt;/td&gt;
&lt;td&gt;Price open-weight models at a hosted per-token rate to share the paper's unit&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GPU-hours × your rate at measured utilization&lt;/td&gt;
&lt;td&gt;What learning actually costs you&lt;/td&gt;
&lt;td&gt;Depends on batching, quantization and utilization&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;FLOPs (about 2·N_active per token, plus attention)&lt;/td&gt;
&lt;td&gt;Learning efficiency as a scientific claim&lt;/td&gt;
&lt;td&gt;Needs known parameter counts; undercounts bandwidth-bound decode&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Wall-clock time-to-threshold&lt;/td&gt;
&lt;td&gt;Whether learning finishes in time to matter&lt;/td&gt;
&lt;td&gt;Parallelism makes it a poor cost proxy; report it separately&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Open weights change more than the price. Marginal rollouts on owned hardware are cheap, which buys more lineages and larger validation sets, the two places where variance hurts these papers most. A harness injected as a fixed prompt prefix is nearly free to reread under prefix caching in vLLM or SGLang. And open weights allow a final step closed models can't take: moving stable harness knowledge into the weights.&lt;/p&gt;

&lt;h2&gt;
  
  
  Making harness learning compound
&lt;/h2&gt;

&lt;p&gt;WikiSkill adds a persistent knowledge layer between raw traces and executable skills. An inference agent runs tasks with the current skills, a wiki maintainer turns traces into pattern pages, a skill proposer edits one skill at a time, and a validation gate accepts or rolls back the edit. The wiki is never rolled back, so a rejected edit still leaves its lesson behind.&lt;/p&gt;

&lt;p&gt;Within the Qwen family, average gains over no skills grow with size: +12.3 points at 4B, +17.5 at 9B and +23.9 at 27B. Yet Qwen-3.5-9B with evolved skills (47.4%) beats Qwen-3.6-27B without them (39.4%). Removing the wiki from the skill proposer drops Gemini-3.5-Flash's average from 63.7% to 48.7%.&lt;/p&gt;

&lt;p&gt;Skills also transfer across models, sometimes better than self-evolved ones. On ALFWorld, Qwen-3.5-9B scores 63.4% with its own skill and 70.2% with one evolved by Qwen-3.6-27B. The authors read this as evidence that discovering skills and executing them are separate capabilities.&lt;/p&gt;

&lt;p&gt;Transfer cuts both ways, and the failures are the useful part:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Weak author, strong user.&lt;/strong&gt; Qwen-3.5-4B's SpreadSheet skills drop Gemini-3.5-Flash from 50.5% to 18.1%. They encode low-level workarounds that stop the stronger model from writing end-to-end scripts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Strong procedure, weak executor.&lt;/strong&gt; On OfficeQA, Qwen-3.5-4B fails to follow multi-step long-context search procedures and falls back to its default reading behavior.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The working rule: a skill fits the capabilities of the model whose failures it was built from. That rule drives the delegation strategy below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Progressive delegation: start strong, hand work down
&lt;/h2&gt;

&lt;p&gt;Start each task on the strongest model you can afford, and let the harness it builds carry the work down to cheaper models, one tested promotion at a time. A ladder might run Claude Fable → Opus → Sonnet → Haiku → an open-weight model on your own GPUs. That ladder is my extrapolation: the transfer evidence above comes from Qwen, Gemma and Gemini, not Claude tiers.&lt;/p&gt;

&lt;p&gt;[embed: node/9eb4f389-c807]&lt;/p&gt;

&lt;p&gt;Each task moves down only after its re-fitted harness passes every regression suite, and climbs back when its failure rate rises.&lt;/p&gt;

&lt;p&gt;Four rules make the ladder work.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Promote per task type, not per model.&lt;/strong&gt; Extraction and routing may reach the bottom rung; long-context synthesis may never leave the top. Where each task stalls is itself the measurement.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Promotion means re-fitting the harness.&lt;/strong&gt; Run the cheaper model on the task, collect its failures, and let the strong model rewrite the harness from them. The student generates the traces and the teacher does the diagnosis, so skills fit the model that will run them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gate on regression, with enough data.&lt;/strong&gt; A promoted tier must pass every earlier test suite, not only the current one. Validation sets must be big enough to gate: Gemini-3.5-Flash scored 100% on WikiSkill's ALFWorld validation split and 85.9% on test.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep a way back up.&lt;/strong&gt; Vendors update models and task distributions drift. Escalate a task back up the ladder when its failure rate crosses the gate.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Moving a task from tier k to the cheaper tier k+1 pays when the per-task savings over the deployment volume exceed the costs it adds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tex"&gt;&lt;code&gt;N&lt;span class="k"&gt;\left&lt;/span&gt;(c&lt;span class="p"&gt;_&lt;/span&gt;k - c&lt;span class="p"&gt;_{&lt;/span&gt;k+1&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="k"&gt;\right&lt;/span&gt;) &lt;span class="k"&gt;\;&lt;/span&gt;&amp;gt;&lt;span class="k"&gt;\;&lt;/span&gt; C&lt;span class="p"&gt;^{&lt;/span&gt;&lt;span class="k"&gt;\text&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;refit&lt;span class="p"&gt;}}&lt;/span&gt; + C&lt;span class="p"&gt;^{&lt;/span&gt;&lt;span class="k"&gt;\text&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;test&lt;span class="p"&gt;}}&lt;/span&gt; + N&lt;span class="k"&gt;\left&lt;/span&gt;(p&lt;span class="p"&gt;^{&lt;/span&gt;&lt;span class="k"&gt;\text&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;fail&lt;span class="p"&gt;}}_{&lt;/span&gt;k+1&lt;span class="p"&gt;}&lt;/span&gt; - p&lt;span class="p"&gt;^{&lt;/span&gt;&lt;span class="k"&gt;\text&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;fail&lt;span class="p"&gt;}}_{&lt;/span&gt;k&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="k"&gt;\right&lt;/span&gt;) c&lt;span class="p"&gt;^{&lt;/span&gt;&lt;span class="k"&gt;\text&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;review&lt;span class="p"&gt;}}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;High-volume tasks pay back quickly; rare ones stay on the strong model.&lt;/p&gt;

&lt;p&gt;This resembles model cascades and routers such as FrugalGPT and RouteLLM, which send each query to the cheapest model likely to succeed. The difference is time. Here the routing thresholds move because the harness improves, so a model's place on the ladder is not a fixed property of the model.&lt;/p&gt;

&lt;h2&gt;
  
  
  Consolidation: from harness to weights
&lt;/h2&gt;

&lt;p&gt;On open weights, the harness can be a staging area for weight updates. Learn in files, where edits are fast, auditable and reversible; once a skill has stayed stable across promotions, distill it into the model. This is the wake–sleep pattern of &lt;em&gt;Language Models Need Sleep&lt;/em&gt;, with the fast memory moved out of the architecture and into the harness.&lt;/p&gt;

&lt;p&gt;That paper moves knowledge from fast, temporary components into a new low-rank expert in a slower block. The new expert is trained to imitate a teacher holding old and new knowledge together, so old behavior is the target rather than collateral damage. Its Dreaming stage builds on SEAL, and the method is built on the authors' own architecture and training loop rather than an off-the-shelf model.&lt;/p&gt;

&lt;p&gt;The harness version is context distillation. The teacher is the small model with the harness in its prompt; the student is the same model without it, plus a new LoRA trained to match the teacher's outputs. The LoRA becomes a cache of the wiki, and you can test whether the cache still agrees with its source.&lt;/p&gt;

&lt;p&gt;SEAL generates the training data for that step, and two of its properties fit this design:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;It needs a downstream evaluation for every context.&lt;/strong&gt; Its authors name this as what keeps it from scaling to unlabeled data. A harness loop always has one: the validation gate or the held-out tasks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Its authors already describe a teacher–student variant.&lt;/strong&gt; A separate teacher is trained by RL to write edits that maximize the student's improvement. That is the delegation ladder applied to weights.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Two problems remain open. SEAL reports that knowledge from earlier edits gradually degrades as sequential self-edits accumulate. And each SEAL reward requires fine-tuning and evaluating a model, about 30–45 seconds per candidate edit.&lt;/p&gt;

&lt;p&gt;Consolidating &lt;em&gt;from&lt;/em&gt; a harness rather than replacing it gives a rollback: if a LoRA degrades anything, drop it and the harness still works. Consolidation then becomes one more promotion. "Model plus LoRA plus a thinner harness" must beat "model plus full harness" on the same regression suite, at lower cost per task.&lt;/p&gt;

&lt;h2&gt;
  
  
  Professional work: where verification costs the most
&lt;/h2&gt;

&lt;p&gt;In professional work, verification cost favors the stronger model. Chess has a cheap, strong verifier in an engine. In legal or medical work the verifier is an expert's time, so review cost scales with the failure rate, and a better model at a higher token price can be cheaper in total.&lt;/p&gt;

&lt;p&gt;Verification cost also limits plasticity itself, because feedback is what the harness learns from. The plasticity paper's environments form a gradient: chess gives a per-move engine verdict, Go and Hex get lighter diagnostics, and NetHack has no per-action oracle. In NetHack only one of six lineages improved reliably, and Sol, the most plastic model on board games, fell from a mean score of about 570 to 420.&lt;/p&gt;

&lt;p&gt;That suggests a feedback ladder for any domain:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Rung&lt;/th&gt;
&lt;th&gt;Reflection sees&lt;/th&gt;
&lt;th&gt;Tests&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;Nothing beyond validator checks that tools run&lt;/td&gt;
&lt;td&gt;Priors plus a compute budget&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Trajectories with outcomes stripped&lt;/td&gt;
&lt;td&gt;Learning from process alone&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Trajectories plus the final outcome&lt;/td&gt;
&lt;td&gt;Learning from sparse results&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Plus per-step expert annotations&lt;/td&gt;
&lt;td&gt;The plasticity paper's chess setup&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Most professional work sits at rung 2: you learn whether the brief won, rarely which paragraph lost it. The gap between rungs 2 and 3 estimates how much measured plasticity survives outside games. Until someone measures it, read game-based plasticity as an upper bound for professional domains.&lt;/p&gt;

&lt;p&gt;This is also why I'd call these loops autonomous between gates, not autonomous overall. Every gate here is a validation set with ground truth that a person built.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two experiments worth running
&lt;/h2&gt;

&lt;p&gt;Both experiments fit on open weights and a modest GPU budget.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. The feedback ladder.&lt;/strong&gt; Run the plasticity protocol at rungs 0 to 3 with budget-matched reflection. Rung 0 is the control the plasticity authors name as missing: it separates learning from feedback from simply thinking harder with more compute. A related counterfactual design, which reruns from a branch point with the agent's experience erased, appears in recent work on long-horizon R&amp;amp;D agents.&lt;/p&gt;

&lt;p&gt;Rung 1 is hard to build in chess, since a checkmate is visible in the final position. Truncating games works but changes what reflection sees, so report it as a limit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Harness-to-LoRA consolidation.&lt;/strong&gt; Take a WikiSkill-style evolved skill for a small Qwen model and context-distill it into a LoRA. Measure three things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Task score with the skill removed from the prompt, against the skill-in-prompt baseline.&lt;/li&gt;
&lt;li&gt;Score on an unrelated benchmark before and after, as a forgetting check.&lt;/li&gt;
&lt;li&gt;Prompt tokens saved per call, and the volume N at which distillation pays for itself.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A third arm would test the student-plays, teacher-diagnoses design: a small model generates the traces while a larger model maintains the wiki and proposes skills. As far as I can tell from WikiSkill's main text, its roles are never split that way.&lt;/p&gt;

&lt;h2&gt;
  
  
  Caveats
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The plasticity results come from games with automatic scoring and small evaluation sets. Claude Fable 5, the highest-scoring model, has one run in Chess (Hard); most others have three.&lt;/li&gt;
&lt;li&gt;P^sat and every dollar figure here depend on provider prices at the time of the study.&lt;/li&gt;
&lt;li&gt;WikiSkill's validation sets are small enough that a perfect validation score coexisted with 85.9% on test.&lt;/li&gt;
&lt;li&gt;The Claude-tier delegation ladder is an extrapolation; the transfer evidence comes from Qwen, Gemma and Gemini.&lt;/li&gt;
&lt;li&gt;Consolidation from a harness is a proposal. SEAL shows forgetting under sequential edits, and retention across many consolidation cycles at production scale is unshown.&lt;/li&gt;
&lt;li&gt;The cost formulas are decision aids. Their inputs, especially review cost and failure rate at τ, must be measured per deployment.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Singh et al. (2026). &lt;a href="https://arxiv.org/abs/2610.08902" rel="noopener noreferrer"&gt;Agent Plasticity: Measuring Self-Improvement Through Experience&lt;/a&gt;. arXiv:2610.08902. &lt;a href="https://harmandotpy.github.io/agent-plasticity/" rel="noopener noreferrer"&gt;Project page and game replays&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Tang et al. (2026). &lt;a href="https://arxiv.org/abs/2608.27454v1" rel="noopener noreferrer"&gt;WikiSkill: Compiling Agent Experience into Persistent Knowledge for Skill Evolution&lt;/a&gt;. arXiv:2608.27454.&lt;/li&gt;
&lt;li&gt;Zweiger, Pari et al. (2025). &lt;a href="https://arxiv.org/abs/2506.10943v2" rel="noopener noreferrer"&gt;Self-Adapting Language Models&lt;/a&gt; (SEAL). arXiv:2506.10943.&lt;/li&gt;
&lt;li&gt;Behrouz, Hashemi, Javanmard and Mirrokni (2026). &lt;a href="https://arxiv.org/abs/2606.03979" rel="noopener noreferrer"&gt;Language Models Need Sleep: Learning to Self-Modify and Consolidate Memories&lt;/a&gt;. arXiv:2606.03979.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://arxiv.org/pdf/2608.13417" rel="noopener noreferrer"&gt;Beyond Final Scores: A Systematic Evaluation of Agents for Long-Horizon AI Research and Development&lt;/a&gt;. arXiv:2608.13417.&lt;/li&gt;
&lt;li&gt;Chen, Zaharia and Zou (2023). &lt;a href="https://arxiv.org/abs/2305.05176" rel="noopener noreferrer"&gt;FrugalGPT: How to Use Large Language Models While Reducing Cost and Improving Performance&lt;/a&gt;. arXiv:2305.05176.&lt;/li&gt;
&lt;li&gt;Ong et al. (2024). &lt;a href="https://arxiv.org/abs/2406.18665v4" rel="noopener noreferrer"&gt;RouteLLM: Learning to Route LLMs with Preference Data&lt;/a&gt;. arXiv:2406.18665.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Mastering Prompting for AI Agents: Insights and Best Practices</title>
      <dc:creator>Guillermo Alcántara</dc:creator>
      <pubDate>Sat, 09 Aug 2025 19:21:06 +0000</pubDate>
      <link>https://dev.to/echo9k/mastering-prompting-for-ai-agents-insights-and-best-practices-3iod</link>
      <guid>https://dev.to/echo9k/mastering-prompting-for-ai-agents-insights-and-best-practices-3iod</guid>
      <description>&lt;p&gt;In the rapidly evolving landscape of artificial intelligence, particularly in the development of intelligent agents, &lt;strong&gt;prompt engineering&lt;/strong&gt; has emerged as a crucial skill. In a recent presentation, AI experts Hannah and Jeremy from Anthropic delved into the nuances of crafting effective prompts for AI agents. This blog post distills their insights, providing clear guidelines and examples to help you leverage AI agents effectively.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding AI Agents
&lt;/h2&gt;

&lt;p&gt;At the core of this discussion is the concept of &lt;strong&gt;AI agents&lt;/strong&gt;—systems that use tools to execute tasks continuously and autonomously. Unlike basic prompt interactions, AI agents integrate feedback from their environment, making decisions based on the information they gather. Here’s a simplified breakdown of what an agent encompasses:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Tasks with Autonomy&lt;/strong&gt;: Agents receive a task and, using various tools, work independently to complete it—much like a human solving a multifaceted problem.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Environment &amp;amp; Tools&lt;/strong&gt;: An agent operates within a defined environment equipped with the tools necessary for task completion. The message you convey through prompts essentially acts as the guiding instruction, determining what the agent should accomplish.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  When to Use AI Agents
&lt;/h2&gt;

&lt;p&gt;Not all tasks require the sophistication of agents. Here’s a quick checklist to determine if an agent is suitable for your scenario:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Task Complexity&lt;/strong&gt;: Is the task intricate enough that a step-by-step human approach isn't clear? If the process is straightforward, it might be better to stick with simpler workflows.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Valuable Outcomes&lt;/strong&gt;: Is the task poised to provide significant value—like revenue generation or improving user experience? High-leverage tasks are candidates for agents.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Feasibility&lt;/strong&gt;: Can you define and provide the necessary tools or information for the agent to execute the task? Without clarity in tool access, it may be better to limit the task scope.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error Impact&lt;/strong&gt;: What are the repercussions of errors? If a mistake is costly or hard to correct, it may be prudent to keep a human in the loop.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Examples of Effective Use Cases
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Coding Projects&lt;/strong&gt;: When turning a design document into a pull request (PR), agents can navigate the complexity of coding tasks autonomously, resulting in significant time savings for highly-skilled engineers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Search Processes&lt;/strong&gt;: In scenarios where searches can be rectified through citations or double-checking results, deploying an agent could streamline the task. For instance, when searching for information about various startups, an agent can autonomously adjust its searches based on gathered data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Analysis&lt;/strong&gt;: When delineating insights from varied data sets with unpredictable formats, agents can navigate the complexities without needing a perfectly defined pathway.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Best Practices for Prompting Agents
&lt;/h2&gt;

&lt;p&gt;Jeremy offered several guidelines on how to &lt;strong&gt;construct effective prompts&lt;/strong&gt; for agents, emphasizing a cognitive approach to tool selection:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Think Like Your Agent&lt;/strong&gt;: Develop a mental model of the agent’s environment and tasks. Understand from an agent’s perspective what tools and responses are necessary for successful execution.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Define Reasonable Heuristics&lt;/strong&gt;: Guiding agents with clear, practical heuristics helps shape their decision-making processes. This could pertain to resource allocation, such as setting tool call limits based on query complexity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Tool Selection Is Vital&lt;/strong&gt;: Specify which tools the agent should leverage for different tasks. For instance, if a company heavily relies on Slack for communication, the agent should prioritize this tool for relevant tasks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Plan and Reflect&lt;/strong&gt;: Encourage agents to plan their actions prior to execution. Notably, using interleaved thinking, agents can reflect on their search results before proceeding, allowing for smarter decision-making.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Beware of Unintended Side Effects&lt;/strong&gt;: As agents function autonomously, changes in prompts may lead to unpredictable results. If an agent is directed to "keep searching," ensure to include contingencies for scenarios where desired outputs don’t exist.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Manage Context Windows&lt;/strong&gt;: With models that handle extensive context windows, strategies like &lt;strong&gt;compaction&lt;/strong&gt;—summarizing excessive context to maintain focus—can be beneficial.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Evaluating Agent Performance
&lt;/h2&gt;

&lt;p&gt;Performance evaluation is crucial for understanding effectiveness:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Use Realistic Tasks&lt;/strong&gt;: Ensure evaluation tasks reflect real-world scenarios relevant to the agent's functions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Leverage LLMs for Judging&lt;/strong&gt;: Using language models as judges can help in assessing outputs against established rubrics, allowing for a more nuanced evaluation of agent performance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check Final States&lt;/strong&gt;: Confirm that your agent completes tasks correctly by checking if it reaches the desired end state, such as updating a database correctly.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Building effective prompts for AI agents is an iterative process that demands clarity, strategy, and thoughtful evaluation. By understanding when to deploy agents and refining your prompting techniques, you can unlock the full potential of AI-driven solutions. Whether in coding, data analysis, or information retrieval, these best practices will help you streamline workflows and achieve more valuable outcomes. &lt;/p&gt;

&lt;p&gt;Feel free to explore these concepts further and adapt the insights shared here to meet your specific AI use cases and contexts.&lt;/p&gt;

&lt;p&gt;Summary from Prompting for Agents - Anthropic&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=XSZP9GhhuAc" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=XSZP9GhhuAc&lt;/a&gt;&lt;/p&gt;

</description>
      <category>agents</category>
      <category>bestpractices</category>
      <category>promptengineering</category>
      <category>ai</category>
    </item>
    <item>
      <title>Feature Engineering: A Practical Guide to Doing It Right</title>
      <dc:creator>Guillermo Alcántara</dc:creator>
      <pubDate>Wed, 16 Apr 2025 03:06:04 +0000</pubDate>
      <link>https://dev.to/echo9k/feature-engineering-a-practical-guide-to-doing-it-right-1f1j</link>
      <guid>https://dev.to/echo9k/feature-engineering-a-practical-guide-to-doing-it-right-1f1j</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;You’ve probably heard it a hundred times: &lt;em&gt;feature engineering is the key to unlocking better model performance&lt;/em&gt;. But what does that actually mean? And more importantly—where do you start?&lt;/p&gt;

&lt;p&gt;If you’re staring at a dataset and feeling unsure what to do with it, you’re not alone. Maybe it’s a mix of numbers, categories, and even some free-form text. Maybe you’ve already thrown it into a model and gotten “meh” results. And now you’re wondering: &lt;em&gt;am I missing something obvious?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Here’s the thing—most people jump straight into feature engineering without really understanding their data. That’s like trying to decorate a house before it’s even built. To do this well, you need a framework. One that helps you identify the type of data you’re working with, choose the right techniques, and measure whether what you’re doing is actually making a difference.&lt;/p&gt;

&lt;p&gt;This article breaks it all down for you. You’ll learn the core principles behind feature engineering, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The difference between structured and unstructured data—and why it matters
&lt;/li&gt;
&lt;li&gt;How to classify features into four key levels (and what you can actually &lt;em&gt;do&lt;/em&gt; with them)
&lt;/li&gt;
&lt;li&gt;A clear breakdown of the five main types of feature engineering
&lt;/li&gt;
&lt;li&gt;How to evaluate your work beyond just model accuracy
&lt;/li&gt;
&lt;li&gt;And finally, a repeatable, step-by-step process to do it all with confidence
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you're ready to stop guessing and start engineering your features with purpose—this is your blueprint.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;1. Structured vs. Unstructured Data&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Before you apply any feature engineering techniques, you need to understand what kind of data you're working with.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Structured data&lt;/strong&gt; lives in spreadsheets and databases—think rows and columns, like customer age, income, or product ratings. It's neat, easy to query, and easy for machine learning models to parse.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unstructured data&lt;/strong&gt; includes things like text, images, audio, or video. There’s no predefined format. It makes up roughly 80% of enterprise data, but it’s harder to work with.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Most machine learning models need structured input. So, if you’ve got unstructured data, your first task is to transform it—usually through &lt;strong&gt;feature extraction&lt;/strong&gt; or &lt;strong&gt;feature learning&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Sometimes, datasets are a mix of both. For example, a customer service dataset might include structured fields like time of call, and unstructured fields like call transcripts. The goal is always the same: get it into a structured format your model can understand.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;2. The Four Levels of Data&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Understanding the &lt;em&gt;type&lt;/em&gt; of each feature in your dataset is critical because it determines what you can (and can’t) do with it. Here are the four levels:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Nominal (Qualitative, No Order)&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Examples: blood type, product category&lt;/li&gt;
&lt;li&gt;Only meaningful operations: mode, counts&lt;/li&gt;
&lt;li&gt;Common technique: convert to binary/dummy variables&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Ordinal (Qualitative, Ordered)&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Examples: satisfaction rating, education level&lt;/li&gt;
&lt;li&gt;Has order, but gaps between values aren’t consistent&lt;/li&gt;
&lt;li&gt;Strategy: assign integers (e.g. 1–5), but avoid maths on them unless it makes sense&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Interval (Quantitative, No True Zero)&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Examples: temperature in Celsius, dates&lt;/li&gt;
&lt;li&gt;Differences are meaningful, ratios aren’t&lt;/li&gt;
&lt;li&gt;OK to calculate: mean, standard deviation&lt;/li&gt;
&lt;li&gt;Avoid: saying “twice as much” (e.g. 100°C ≠ 2× 50°C)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Ratio (Quantitative, True Zero)&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Examples: age, income, weight&lt;/li&gt;
&lt;li&gt;All arithmetic operations are valid, including ratios&lt;/li&gt;
&lt;li&gt;You can use arithmetic, geometric, or harmonic means&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Quick Tip:&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Misclassifying interval vs. ratio isn’t the end of the world. But mixing up qualitative and quantitative types can break your model logic.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;3. The Five Types of Feature Engineering&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Once you understand your data and its levels, you can start applying the right techniques. Here’s a breakdown of the five main types of feature engineering:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1. Feature Improvement&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Goal: clean and refine existing features
&lt;/li&gt;
&lt;li&gt;Techniques: fill missing values, scale numbers, normalise distributions
&lt;/li&gt;
&lt;li&gt;When to use: features are noisy, incomplete, or skewed&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;2. Feature Construction&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Goal: create new features from existing ones
&lt;/li&gt;
&lt;li&gt;Example: combine "day" and "hour" into "daypart", or map text categories to sentiment scores
&lt;/li&gt;
&lt;li&gt;Requires: domain knowledge and logic
&lt;/li&gt;
&lt;li&gt;When to use: original features lack signal or need transformation&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;3. Feature Selection&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Goal: keep only the most relevant features
&lt;/li&gt;
&lt;li&gt;Benefits: reduces overfitting, speeds up models, improves interpretability
&lt;/li&gt;
&lt;li&gt;Techniques: correlation filtering, mutual information, model-based selection
&lt;/li&gt;
&lt;li&gt;When to use: high dimensionality, multicollinearity, or slow training times&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;4. Feature Extraction&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Goal: reduce dimensionality or summarise unstructured data
&lt;/li&gt;
&lt;li&gt;Techniques: PCA, SVD, Bag-of-Words for text
&lt;/li&gt;
&lt;li&gt;When to use: assumptions about structure are valid, or when simplifying data&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;5. Feature Learning&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Goal: let deep models create features from raw data
&lt;/li&gt;
&lt;li&gt;Techniques: autoencoders, CNNs, GANs
&lt;/li&gt;
&lt;li&gt;Powerful, but: needs lots of data, features may be hard to interpret
&lt;/li&gt;
&lt;li&gt;Best for: images, audio, text—when manual engineering isn’t feasible&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;4. How to Evaluate Feature Engineering&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Creating new features is one thing—knowing if they actually &lt;em&gt;help&lt;/em&gt; is another. Here’s how to assess their impact:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Machine Learning Metrics&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Compare model performance (accuracy, precision, recall) &lt;em&gt;before&lt;/em&gt; and &lt;em&gt;after&lt;/em&gt; applying techniques&lt;/li&gt;
&lt;li&gt;Look for real gains, not just tiny improvements&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Interpretability&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Can you explain what a feature does?&lt;/li&gt;
&lt;li&gt;Human-friendly features help with debugging, stakeholder trust, and regulatory compliance&lt;/li&gt;
&lt;li&gt;Simpler models often win here (e.g. using decision trees instead of deep nets)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Fairness and Bias&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Watch for features that encode bias (e.g. postcode might correlate with race or income)&lt;/li&gt;
&lt;li&gt;Good feature engineering can help reveal and reduce these risks&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Speed and Complexity&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Fewer, more informative features usually train faster&lt;/li&gt;
&lt;li&gt;High-dimensional data can slow things down and increase storage/memory needs&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;5. The Feature Engineering Process&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Here’s a repeatable, 5-step process to follow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Structure Your Data&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Convert unstructured data to structured using extraction or learning&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Classify Feature Types&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Assign each feature a level: nominal, ordinal, interval, or ratio&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Apply Engineering Techniques&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Choose from the five categories: improve, construct, select, extract, or learn—based on your feature types&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Evaluate Impact&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use model performance, interpretability, fairness, and speed as your criteria&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Iterate&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Based on results, repeat or adjust your techniques&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Final Thoughts&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Feature engineering isn’t about using every technique under the sun—it’s about using the right ones, for the right data, at the right time. Start by understanding your data. Know its structure. Know its level. And use that knowledge to apply logical, targeted transformations.&lt;/p&gt;

&lt;p&gt;When you follow this framework, you stop guessing and start building features that &lt;em&gt;actually move the needle&lt;/em&gt;. That’s how you make your models smarter—not just bigger.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Implementing similarity search algotithms</title>
      <dc:creator>Guillermo Alcántara</dc:creator>
      <pubDate>Wed, 16 Oct 2024 18:51:25 +0000</pubDate>
      <link>https://dev.to/echo9k/implementing-similarity-search-algotithms-4hh9</link>
      <guid>https://dev.to/echo9k/implementing-similarity-search-algotithms-4hh9</guid>
      <description>&lt;h1&gt;
  
  
  Get the data
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pandas&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;


&lt;span class="n"&gt;descripciones&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;All users must reset passwords every 90 days.&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Passwords need to be reset by all users every 90 days.&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Admin access should be restricted.&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Passwords must change for users every 90 days.&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Passwords must change for users every 80 days.&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;# Cargar el dataset
&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DataFrame&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Rule_ID&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;range&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="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;descripciones&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="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Description&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;descripciones&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Lexical similarity
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.feature_extraction.text&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;TfidfVectorizer&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sklearn.metrics.pairwise&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;cosine_similarity&lt;/span&gt;

&lt;span class="err"&gt;!&lt;/span&gt;
&lt;span class="c1"&gt;# Vectorización de las descripciones con TF-IDF
&lt;/span&gt;&lt;span class="n"&gt;vectorizer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;TfidfVectorizer&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;fit_transform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Description&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="c1"&gt;# Calcular la matriz de similitud de coseno
&lt;/span&gt;&lt;span class="n"&gt;cosine_sim_matrix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;cosine_similarity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vectorizer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Crear un diccionario para almacenar las relaciones sin duplicados
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;find_related_rules&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;matrix&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rule_ids&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;threshold&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;related_rules&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
    &lt;span class="n"&gt;seen_pairs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;  &lt;span class="c1"&gt;# Para evitar duplicados de la forma (A, B) = (B, A)
&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;matrix&lt;/span&gt;&lt;span class="p"&gt;)):&lt;/span&gt;
        &lt;span class="n"&gt;related&lt;/span&gt; &lt;span class="o"&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="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&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="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;matrix&lt;/span&gt;&lt;span class="p"&gt;)):&lt;/span&gt;  &lt;span class="c1"&gt;# j comienza en i + 1 para evitar duplicados
&lt;/span&gt;            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;matrix&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="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;threshold&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;pair&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rule_ids&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="n"&gt;rule_ids&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="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;pair&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;seen_pairs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                    &lt;span class="n"&gt;seen_pairs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pair&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="n"&gt;related&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;rule_ids&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="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;matrix&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="n"&gt;j&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="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;related&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;related_rules&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;rule_ids&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="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;related&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;related_rules&lt;/span&gt;

&lt;span class="c1"&gt;# Aplicar la función para encontrar reglas relacionadas
&lt;/span&gt;&lt;span class="n"&gt;related_rules&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;find_related_rules&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cosine_sim_matrix&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Rule_ID&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;tolist&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;threshold&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Mostrar las reglas relacionadas
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Reglas relacionadas por similitud:&lt;/span&gt;&lt;span class="sh"&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;rule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;relations&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;related_rules&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Rule &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;rule&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; es similar a:&lt;/span&gt;&lt;span class="sh"&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;related_rule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;relations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;  - Rule &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;related_rule&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; con similitud de &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;score&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Semantical similarity
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="err"&gt;!&lt;/span&gt;&lt;span class="n"&gt;pip&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="n"&gt;sentence&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;transformers&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;sentence_transformers&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;SentenceTransformer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;util&lt;/span&gt;


&lt;span class="c1"&gt;# Load the pre-trained model for generating embeddings
&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;SentenceTransformer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;all-MiniLM-L6-v2&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Generate sentence embeddings for each rule description
&lt;/span&gt;&lt;span class="n"&gt;embeddings&lt;/span&gt; &lt;span class="o"&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;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Description&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;convert_to_tensor&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Compute the semantic similarity matrix
&lt;/span&gt;&lt;span class="n"&gt;cosine_sim_matrix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;util&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cos_sim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;embeddings&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;embeddings&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;cpu&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;numpy&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;# Function to find related rules based on semantic similarity
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;find_related_rules&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;matrix&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rule_ids&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;threshold&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;related_rules&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
    &lt;span class="n"&gt;seen_pairs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;  &lt;span class="c1"&gt;# To avoid duplicates of the form (A, B) = (B, A)
&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;matrix&lt;/span&gt;&lt;span class="p"&gt;)):&lt;/span&gt;
        &lt;span class="n"&gt;related&lt;/span&gt; &lt;span class="o"&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="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&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="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;matrix&lt;/span&gt;&lt;span class="p"&gt;)):&lt;/span&gt;  &lt;span class="c1"&gt;# Only consider upper triangular matrix
&lt;/span&gt;            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;matrix&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="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;threshold&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;pair&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rule_ids&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="n"&gt;rule_ids&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="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;pair&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;seen_pairs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                    &lt;span class="n"&gt;seen_pairs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pair&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="n"&gt;related&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;rule_ids&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="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;matrix&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="n"&gt;j&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="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;related&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;related_rules&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;rule_ids&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="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;related&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;related_rules&lt;/span&gt;

&lt;span class="c1"&gt;# Apply the function to find related rules
&lt;/span&gt;&lt;span class="n"&gt;related_rules&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;find_related_rules&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cosine_sim_matrix&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Rule_ID&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;tolist&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;threshold&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Display the related rules
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Reglas relacionadas por similitud semántica:&lt;/span&gt;&lt;span class="sh"&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;rule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;relations&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;related_rules&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Rule &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;rule&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; es similar a:&lt;/span&gt;&lt;span class="sh"&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;related_rule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;relations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;  - Rule &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;related_rule&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; con similitud de &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;score&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>similarity</category>
      <category>nlp</category>
      <category>tutorial</category>
      <category>python</category>
    </item>
  </channel>
</rss>
