<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged cognitive-science</title>
<link>https://coderlegion.com/tag/cognitive-science</link>
<description>Powered by Question2Answer</description>
<item>
<title>I Wrapped an 8B Model in 40 Neuroscience Modules and It Started Outperforming GPT-4</title>
<link>https://coderlegion.com/18579/i-wrapped-an-8b-model-in-40-neuroscience-modules-and-it-started-outperforming-gpt-4</link>
<description>&lt;h2 id=&quot;i-wrapped-an-8b-model-in-40-neuroscience-modules-and-it-started-outperforming-gpt-4&quot;&gt;I Wrapped an 8B Model in 40 Neuroscience Modules and It Started Outperforming GPT-4&lt;/h2&gt;
&lt;p&gt;Okay, hear me out.&lt;/p&gt;
&lt;p&gt;I know that title sounds like clickbait. But I have benchmarks, code, and a story about hitting API rate limits at 3am.&lt;/p&gt;
&lt;p&gt;I'm 17. I built FRIDAY — a 95K-line cognitive AI pipeline in Python. It takes Llama-3.1-8B-Instruct (8 billion parameters, free-tier Groq inference) and wraps it in so much cognitive scaffolding that it scores 88% on ARC-Challenge. GPT-4 territory. On an 8B model. For free.&lt;/p&gt;
&lt;p&gt;This is the &quot;here's how the architecture actually works&quot; deep dive. Not the fluff piece — I already wrote &lt;a rel=&quot;nofollow&quot; href=&quot;https://dev.to/subhansh/how-i-built-a-95k-line-cognitive-ai-pipeline-that-takes-an-8b-model-to-gpt-4-territory-1k7c&quot;&gt;that one&lt;/a&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-problem-with-big-models&quot;&gt;The Problem With Big Models&lt;/h3&gt;
&lt;p&gt;The current playbook: make the model bigger. GPT-4, Claude, Gemini — more parameters = more intelligence. It works. But from an engineering perspective, &quot;throw 100x more compute at it&quot; feels like giving up.&lt;/p&gt;
&lt;p&gt;So I asked: what if the &lt;em&gt;architecture around the model&lt;/em&gt; is what matters?&lt;/p&gt;
&lt;p&gt;FRIDAY is my answer. A cognitive architecture — 40+ modules inspired by neuroscience and psychology — that forces a small model to think before it speaks. Not through prompts. Through computational structure.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-pipeline-8-stages-of-forced-reasoning&quot;&gt;The Pipeline: 8 Stages of Forced Reasoning&lt;/h3&gt;
&lt;p&gt;Every query follows this path:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;reason → perceive → plan → simulate → execute → debug → reflect → consolidate
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;the-routing-decision-fast-or-slow-&quot;&gt;The Routing Decision: Fast or Slow?&lt;/h4&gt;
&lt;p&gt;Inspired by Kahneman's dual-process theory (System 1 vs System 2), FRIDAY decides whether a query needs fast intuition or deep deliberation:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;FAST_PATH_CONFIDENCE = 0.75

def _fast_path(self, request, context, response):
    domain = context.get(&quot;domain&quot;, &quot;general&quot;)
    success, result = self._call_module(&quot;intuition&quot;, &quot;recognize&quot;, request, domain)

    if success and result:
        action, confidence, match_info = result
        if action and confidence &amp;gt;= FAST_PATH_CONFIDENCE:
            emo_success, emo_result = self._call_module(&quot;emotional&quot;, &quot;affect_heuristic&quot;, action)
            if emo_success and emo_result:
                valence = emo_result.get(&quot;emotional_valence&quot;, 0.0)
                response.confidence = clamp(confidence + valence * 0.1)
            response.response = action
            response.path = &quot;fast&quot;
            return True
    return False
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The Intuition Engine checks if it's seen something like this before. If yes, and confident (&amp;gt;0.75), in under 100ms — fast path. No extra LLM calls. This is how FRIDAY handles &quot;what time is it&quot; without engaging 40 modules.&lt;/p&gt;
&lt;h4 id=&quot;the-deliberative-pipeline&quot;&gt;The Deliberative Pipeline&lt;/h4&gt;
&lt;p&gt;If fast path fails, we enter 8 cognitive stages:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Metacognitive Strategy → Emotional Priming → Module Competition →
Causal Reasoning → Analogical Reasoning → Creativity →
World Model Simulation → Neurosymbolic Verification
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Each module contributes weighted evidence. The key: &lt;strong&gt;graceful degradation&lt;/strong&gt;. If a module fails or times out (5s default), the pipeline keeps going. This is why FRIDAY had zero errors across 535 benchmark questions — not because nothing failed, but because the system never crashes when they do.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-modules-that-actually-matter&quot;&gt;The Modules That Actually Matter&lt;/h3&gt;
&lt;h4 id=&quot;intuition-engine-kahneman-meets-klein&quot;&gt;Intuition Engine: Kahneman Meets Klein&lt;/h4&gt;
&lt;p&gt;Implements two models simultaneously — Kahneman's System 1 (fast pattern recognition) and Gary Klein's Recognition-Primed Decision model (how experts decide under pressure).&lt;/p&gt;
&lt;p&gt;Each pattern is a 12-dimensional feature vector. Not embeddings. Hand-crafted features:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;def _extract_features(self, text):
    words = text.lower().split()
    n = len(words)
    f_len = min(1.0, n / 100.0)
    f_avg_wl = min(1.0, avg_wl / 15.0)
    f_uniq = len(set(words)) / max(n, 1)
    f_q = 1.0 if &quot;?&quot; in text else 0.0
    # ... 8 more features
    return [f_len, f_avg_wl, f_uniq, f_q, ...]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Pattern matching is cosine similarity. No LLM calls. Under 100ms.&lt;/p&gt;
&lt;p&gt;Patterns decay using Ebbinghaus' forgetting curve:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;DECAY_HALF_LIFE_DAYS = 60
decay_factor = 2 ** (-days_since_use / DECAY_HALF_LIFE_DAYS)
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;active-inference-friston-s-free-energy-principle&quot;&gt;Active Inference: Friston's Free Energy Principle&lt;/h4&gt;
&lt;p&gt;The core idea: organisms minimize surprise. Predict what happens, update when wrong.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;def compute_prediction_error(self, tool_name, prediction, actual_success, actual_duration_ms):
    success_error = abs(prediction[&quot;expected_success&quot;] - (1.0 if actual_success else 0.0))
    if actual_duration_ms &amp;gt; 0 and prediction[&quot;expected_duration_ms&quot;] &amp;gt; 0:
        ratio = actual_duration_ms / max(prediction[&quot;expected_duration_ms&quot;], 1)
        duration_error = math.log2(ratio) * 0.3 if ratio &amp;gt; 1 else abs(1 - ratio) * 0.3
    return min(success_error + duration_error, 2.0)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;High prediction errors trigger &lt;strong&gt;epistemic foraging&lt;/strong&gt; — &quot;I don't understand this well enough, explore more.&quot;&lt;/p&gt;
&lt;h4 id=&quot;hierarchical-active-inference-3-levels-of-belief&quot;&gt;Hierarchical Active Inference: 3 Levels of Belief&lt;/h4&gt;
&lt;p&gt;Three levels — Meta (strategic), Subgoal (tactical), Action (execution). Each maintains a belief state with Bayesian updates:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;def update(self, observation, learning_rate=0.1):
    effective_lr = learning_rate * self.precision
    for hyp, likelihood in observation.items():
        if hyp in self.hypotheses:
            prior = self.hypotheses[hyp]
            self.hypotheses[hyp] = prior + effective_lr * (likelihood - prior)
    for hyp in list(self.hypotheses.keys()):
        if hyp not in observation:
            self.hypotheses[hyp] *= 0.95
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Bidirectional: top-down constraints propagate down, execution errors propagate up. Mirrors prefrontal-motor cortex interaction.&lt;/p&gt;
&lt;h4 id=&quot;cognitive-appraisal-how-emotions-get-generated&quot;&gt;Cognitive Appraisal: How Emotions Get Generated&lt;/h4&gt;
&lt;p&gt;Using Lazarus' theory — two evaluation levels:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Primary&lt;/strong&gt;: Is this relevant? Good or bad?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Secondary&lt;/strong&gt;: What can I do about it?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Maps to coping strategies (problem-focused, reappraisal, avoidance, etc.) that affect downstream reasoning — confidence, risk tolerance, exploration vs exploitation.&lt;/p&gt;
&lt;h4 id=&quot;metacognitive-monitor-thinking-about-thinking&quot;&gt;Metacognitive Monitor: Thinking About Thinking&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Confidence calibration&lt;/strong&gt;: tracks whether confidence matches reality (overconfidence threshold: 0.15)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Error pattern detection&lt;/strong&gt;: scans last 200 errors, flags recurring patterns&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Fatigue detection&lt;/strong&gt;: notices &amp;gt;20% accuracy drop over 30 interactions&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;cognitive-load-miller-s-7-2&quot;&gt;Cognitive Load: Miller's 7±2&lt;/h4&gt;
&lt;p&gt;Implements Sweller's Cognitive Load Theory:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;WORKING_MEMORY_SLOTS = 7
MODULE_COSTS = {
    &quot;active_inference&quot;: 0.10, &quot;dreaming&quot;: 0.15,
    &quot;causal_reasoner&quot;: 0.15, &quot;intuition_engine&quot;: 0.05,
    # ... 30+ modules
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When load exceeds capacity, sheds lower-priority modules. Better slightly less thorough than crashing.&lt;/p&gt;
&lt;h4 id=&quot;memory-systems&quot;&gt;Memory Systems&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;Episodic&lt;/strong&gt;: timestamped event log. &lt;strong&gt;Associative&lt;/strong&gt;: spreading activation network (Collins &amp;amp; Loftus, 1975) — recall one memory, connected ones activate. &lt;strong&gt;Predictive&lt;/strong&gt;: anticipates what you'll need. &lt;strong&gt;Consolidation&lt;/strong&gt;: sleep-like processing (McClelland et al., 1995) — compresses episodic into semantic knowledge every 6 hours.&lt;/p&gt;
&lt;h4 id=&quot;the-dreaming-system&quot;&gt;The Dreaming System&lt;/h4&gt;
&lt;p&gt;When idle for 2 minutes, FRIDAY dreams. Replays memories, extracts patterns, validates against reality. Inspired by hippocampal replay during sleep.&lt;/p&gt;
&lt;h4 id=&quot;self-awareness-module&quot;&gt;Self-Awareness Module&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Introspection Engine: examines own reasoning&lt;/li&gt;
&lt;li&gt;Self-Narrative: continuous identity across sessions&lt;/li&gt;
&lt;li&gt;Theory of Mind: models user's mental state&lt;/li&gt;
&lt;li&gt;Bias Detection: monitors for 12 cognitive biases (confirmation, anchoring, Dunning-Kruger, etc.)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Is it &quot;real&quot; self-awareness? It's functional self-monitoring that improves output quality. Whether that counts as consciousness is above my pay grade.&lt;/p&gt;
&lt;h4 id=&quot;causal-reasoner-pearl-s-three-levels&quot;&gt;Causal Reasoner: Pearl's Three Levels&lt;/h4&gt;
&lt;p&gt;Full causal hierarchy — Association (P(Y|X)), Intervention (P(Y|do(X=x))), Counterfactual. Causal edges have strength, mechanism, confidence — and decay if not reinforced.&lt;/p&gt;
&lt;h4 id=&quot;neurosymbolic-reasoner&quot;&gt;Neurosymbolic Reasoner&lt;/h4&gt;
&lt;p&gt;Combines neural (LLM) and symbolic (formal logic) reasoning. Propositional logic engine built from scratch — no SymPy, no Z3. Can verify code invariants and do formal verification.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-benchmarks&quot;&gt;The Benchmarks&lt;/h3&gt;
&lt;p&gt;All on Groq's Llama-3.1-8B-Instruct. Single-shot pass@1. No tricks.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Benchmark &lt;/th&gt;&lt;th&gt;Accuracy &lt;/th&gt;&lt;th&gt;Questions &lt;/th&gt;&lt;th&gt;Avg Time&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;ARC-Challenge &lt;/td&gt;&lt;td&gt;&lt;strong&gt;88.0%&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;50 &lt;/td&gt;&lt;td&gt;46.2s&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;GSM8K &lt;/td&gt;&lt;td&gt;&lt;strong&gt;85.0%&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;100 &lt;/td&gt;&lt;td&gt;26.5s&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;TruthfulQA &lt;/td&gt;&lt;td&gt;&lt;strong&gt;71.0%&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;100 &lt;/td&gt;&lt;td&gt;37.2s&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;ARC-Easy &lt;/td&gt;&lt;td&gt;68.0% &lt;/td&gt;&lt;td&gt;50 &lt;/td&gt;&lt;td&gt;30.6s&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;MMLU &lt;/td&gt;&lt;td&gt;61.0% &lt;/td&gt;&lt;td&gt;100 &lt;/td&gt;&lt;td&gt;21.0s&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;GPQA &lt;/td&gt;&lt;td&gt;42.0% &lt;/td&gt;&lt;td&gt;50 &lt;/td&gt;&lt;td&gt;60.0s&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;535 questions. Zero errors.&lt;/p&gt;
&lt;p&gt;ARC-Challenge at 88% is the standout — genuine multi-step reasoning. TruthfulQA at 71% is interesting — the pipeline helps resist confident wrong answers. MMLU at 61% is nuanced: 100% on heavy conceptual subjects, below baseline on trivia (the over-thinking penalty).&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;key-design-decisions&quot;&gt;Key Design Decisions&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Graceful degradation everywhere&lt;/strong&gt; — every import is try/except'd&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Thread-safe JSON persistence&lt;/strong&gt; — state survives crashes&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;No heavy dependencies&lt;/strong&gt; — logic engine from scratch, features hand-crafted&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Prediction-error learning&lt;/strong&gt; — self-improving feedback loop&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Module competition&lt;/strong&gt; — multiple proposals, best wins&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;h3 id=&quot;what-s-next&quot;&gt;What's Next&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Routing layer to avoid the MMLU over-thinking penalty&lt;/li&gt;
&lt;li&gt;Scaling to Llama-3.1-70B&lt;/li&gt;
&lt;li&gt;More benchmarks: HellaSwag, WinoGrande, HumanEval&lt;/li&gt;
&lt;li&gt;200+ samples per benchmark&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;p&gt;I'm 17 and building cognitive AI systems. If you're interested in the architecture, benchmarks, or just want to argue about whether any of this constitutes &quot;real&quot; reasoning — I'm at &lt;em&gt;Emails are not allowed&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Source: &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/subhansh-dev/Friday-Autonomous-Cognitive-AI-Operating-System&quot;&gt;github.com/subhansh-dev/Friday-Autonomous-Cognitive-AI-Operating-System&lt;/a&gt;&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/18579/i-wrapped-an-8b-model-in-40-neuroscience-modules-and-it-started-outperforming-gpt-4</guid>
<pubDate>Thu, 21 May 2026 16:41:56 +0000</pubDate>
</item>
</channel>
</rss>