<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[toString(): AI Odyssey]]></title><description><![CDATA[AI Odyssey: Dive with me into AI as I learn and unravel its details. As a software architect, I'm exploring AI, LLMs, and Generative AI, writing down my discoveries on Substack to cement them in my brain and share on the blog. It's about breaking down complex AI nuggets into digestible insights while riding the wave of learning. Join the adventure, it's going to be a wild ride]]></description><link>https://www.tostring.ai/s/ai-odyssey</link><image><url>https://substackcdn.com/image/fetch/$s_!SYTr!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa656eca3-6631-468a-8633-07333c6fdfab_400x400.png</url><title>toString(): AI Odyssey</title><link>https://www.tostring.ai/s/ai-odyssey</link></image><generator>Substack</generator><lastBuildDate>Sun, 19 Apr 2026 06:19:05 GMT</lastBuildDate><atom:link href="https://www.tostring.ai/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Marco Altea]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[info@tostring.ai]]></webMaster><itunes:owner><itunes:email><![CDATA[info@tostring.ai]]></itunes:email><itunes:name><![CDATA[Marco Altea]]></itunes:name></itunes:owner><itunes:author><![CDATA[Marco Altea]]></itunes:author><googleplay:owner><![CDATA[info@tostring.ai]]></googleplay:owner><googleplay:email><![CDATA[info@tostring.ai]]></googleplay:email><googleplay:author><![CDATA[Marco Altea]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[E4: The Linguistics of Machines: LLM and NLP]]></title><description><![CDATA[Human and Machine Communication through Deep Learning Techniques]]></description><link>https://www.tostring.ai/p/e4-the-linguistics-of-machines-llm</link><guid isPermaLink="false">https://www.tostring.ai/p/e4-the-linguistics-of-machines-llm</guid><dc:creator><![CDATA[Marco Altea]]></dc:creator><pubDate>Fri, 03 Nov 2023 08:36:09 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63dfe2b8-b5d4-479b-b9f7-f5fe19656a7a_409x595.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>Introduction</h2><p>As the technology continually evolves, as you can probably have noticed </p><div class="pullquote"><p>WE CAN NOW TALK WITH MACHINE!!!! </p></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6wRp!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d96708c-6b50-4edc-b745-5e58b37c7c0f_1024x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6wRp!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d96708c-6b50-4edc-b745-5e58b37c7c0f_1024x1024.png 424w, https://substackcdn.com/image/fetch/$s_!6wRp!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d96708c-6b50-4edc-b745-5e58b37c7c0f_1024x1024.png 848w, https://substackcdn.com/image/fetch/$s_!6wRp!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d96708c-6b50-4edc-b745-5e58b37c7c0f_1024x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!6wRp!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d96708c-6b50-4edc-b745-5e58b37c7c0f_1024x1024.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6wRp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d96708c-6b50-4edc-b745-5e58b37c7c0f_1024x1024.png" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2d96708c-6b50-4edc-b745-5e58b37c7c0f_1024x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1712158,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!6wRp!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d96708c-6b50-4edc-b745-5e58b37c7c0f_1024x1024.png 424w, https://substackcdn.com/image/fetch/$s_!6wRp!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d96708c-6b50-4edc-b745-5e58b37c7c0f_1024x1024.png 848w, https://substackcdn.com/image/fetch/$s_!6wRp!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d96708c-6b50-4edc-b745-5e58b37c7c0f_1024x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!6wRp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d96708c-6b50-4edc-b745-5e58b37c7c0f_1024x1024.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.tostring.ai/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">toString() is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>The journey so far, through Machine Learning and Deep Learning, has set a good foundation into  how machines interpret and generate human language. In this episode, I will try to explain how Large Language Models (LLMs) and Natural Language Processing (NLP) works. This technique allows the fusion of linguistic and machine learning principles to foster a more nuanced interaction between humans and computers.</p><p>This new chapter of AI Odyssey  It's about to show how we can teach machines to understand and respond to textual data, mirroring human-like understanding to a significant extent. This exploration is all set to unveil the architectural designs and the underlying mechanisms that help machines process textual data effectively, thereby enhancing our digital solutions.</p><h2><strong>Large Language Models (LLMs)</strong></h2><p>LLMs as discussed in the first chapter </p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;2315765f-c58a-492a-a89e-55cc43cc3743&quot;,&quot;caption&quot;:&quot;1. Introduction In a world where the term \&quot;Artificial Intelligence\&quot; (AI) has become ubiquitous, it's crucial to ground my understanding in its foundational aspects. John McCarthy, a luminary in the domain from Stanford University, delved deep into the basic questions surrounding AI in his paper&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;lg&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;E1 - From Code to Cognition: My AI Exploration Begins&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:21150333,&quot;name&quot;:&quot;Marco Altea&quot;,&quot;bio&quot;:&quot;Londoner, IBM Technical Architect &amp; wine lover time traveller &quot;,&quot;photo_url&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/90a0c78f-fe64-4a86-8bf2-f89b09696a3e_3000x2002.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2023-10-13T08:40:55.155Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F751132e6-7ab7-4720-9984-a1a5787a7df3_1024x1024.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://tostring.substack.com/p/e1-from-code-to-cognition-my-ai-exploration&quot;,&quot;section_name&quot;:&quot;AI Odyssey&quot;,&quot;video_upload_id&quot;:null,&quot;id&quot;:137898406,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:4,&quot;comment_count&quot;:4,&quot;publication_id&quot;:null,&quot;publication_name&quot;:&quot;toString()&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9026593-bb1d-495c-8712-41f872e37c87_1080x1080.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><p></p><p>are a class of artificial intelligence models designed to understand and generate human language. They are trained on vast datasets comprising text from diverse sources, which provide them with a broad &#8220;understanding&#8221; of language, context, and even certain aspects of general knowledge.</p><p>One of the hallmarks of LLMs is the ability to handle and generate text in a way that resonates with human understanding. This allows machines to understand not just the words, but the sentiments, nuances, and contexts that come with human communication. LLMs like GPT-3, with its 175 billion parameters, represent the progress that have been made in this direction.</p><p>Now, let's get a bit technical. The underlying architecture that empowers these LLMs is the <a href="https://tostring.substack.com/i/137898406/llm-architecture-a-closer-look">Transformer Architecture</a>. <a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Vz6t!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63dfe2b8-b5d4-479b-b9f7-f5fe19656a7a_409x595.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Vz6t!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63dfe2b8-b5d4-479b-b9f7-f5fe19656a7a_409x595.webp 424w, https://substackcdn.com/image/fetch/$s_!Vz6t!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63dfe2b8-b5d4-479b-b9f7-f5fe19656a7a_409x595.webp 848w, https://substackcdn.com/image/fetch/$s_!Vz6t!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63dfe2b8-b5d4-479b-b9f7-f5fe19656a7a_409x595.webp 1272w, https://substackcdn.com/image/fetch/$s_!Vz6t!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63dfe2b8-b5d4-479b-b9f7-f5fe19656a7a_409x595.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Vz6t!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63dfe2b8-b5d4-479b-b9f7-f5fe19656a7a_409x595.webp" width="409" height="595" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/63dfe2b8-b5d4-479b-b9f7-f5fe19656a7a_409x595.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:595,&quot;width&quot;:409,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Vz6t!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63dfe2b8-b5d4-479b-b9f7-f5fe19656a7a_409x595.webp 424w, https://substackcdn.com/image/fetch/$s_!Vz6t!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63dfe2b8-b5d4-479b-b9f7-f5fe19656a7a_409x595.webp 848w, https://substackcdn.com/image/fetch/$s_!Vz6t!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63dfe2b8-b5d4-479b-b9f7-f5fe19656a7a_409x595.webp 1272w, https://substackcdn.com/image/fetch/$s_!Vz6t!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63dfe2b8-b5d4-479b-b9f7-f5fe19656a7a_409x595.webp 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>It's a model that utilizes layers of attention mechanisms to weigh the importance of different parts of the input text (if you want to dig deep on how it technically works you can find a detailed explaination <a href="https://tostring.substack.com/i/137898406/llm-architecture-a-closer-look">HERE</a>). This design enables the model to focus on different parts of the text, much like how we humans pay attention to different parts of a conversation. It's about distinguishing the critical from the trivial, the relevant from the irrelevant. </p><p>The impact of LLMs on the architectural designs is profound. They provide a way to incorporate a sophisticated understanding of language into our digital solutions, enabling a more intuitive interaction between users and systems. For instance, integrating an LLM like GPT-3 into a system can significantly enhance its ability to understand and respond to user queries in a more human-like manner.</p><p>But it's not all sunshine and rainbows. The computational resources required to train and run these behemoths are substantial. Also, the vast amount of data they require raises concerns regarding data privacy and bias. Yet, the potential they hold is immense and hard to overlook.</p><h2><strong>Natural Language Processing (NLP)</strong></h2><p>NLP enables machines to understand, process, and generate human language. It's not just about reading text or hearing speech; it's about deciphering the meanings, the context, and the intent behind the words.</p><p>Let's break it down. At its core, NLP include a variety of techniques and models working to convert our linguistic expressions into a format that machines can understand. </p><p>With the advent of transformative Language Models like <a href="https://cdn.openai.com/research-covers/language-unsupervised/language_understanding_paper.pdf">GPT (Generative Pre-trained Transformer)</a> and <a href="https://github.com/google-research/bert">BERT (Bidirectional Encoder Representations from Transformers)</a>. These models, with their ability to handle vast amounts of text and grasp contextual nuances, are pushing the boundaries of what's possible with NLP.</p><p>For instance, GPT-3, a model by OpenAI<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a>, can generate human-like text that's almost indistinguishable from something a person would write. It's fascinating and scary at the same time! BERT, from Google, shines in understanding the context of words in a sentence, which is instrumental in search queries and other language understanding tasks.</p><p>Using the below example ofe the <a href="https://openai.com/research/instruction-following">OpenAI Method</a>, we can extract the steps and how the information flow:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XMCF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcff6f28d-6d99-4212-9037-81edab06c7b8_1140x677.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XMCF!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcff6f28d-6d99-4212-9037-81edab06c7b8_1140x677.svg 424w, https://substackcdn.com/image/fetch/$s_!XMCF!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcff6f28d-6d99-4212-9037-81edab06c7b8_1140x677.svg 848w, https://substackcdn.com/image/fetch/$s_!XMCF!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcff6f28d-6d99-4212-9037-81edab06c7b8_1140x677.svg 1272w, https://substackcdn.com/image/fetch/$s_!XMCF!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcff6f28d-6d99-4212-9037-81edab06c7b8_1140x677.svg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XMCF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcff6f28d-6d99-4212-9037-81edab06c7b8_1140x677.svg" width="1456" height="865" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cff6f28d-6d99-4212-9037-81edab06c7b8_1140x677.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:865,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!XMCF!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcff6f28d-6d99-4212-9037-81edab06c7b8_1140x677.svg 424w, https://substackcdn.com/image/fetch/$s_!XMCF!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcff6f28d-6d99-4212-9037-81edab06c7b8_1140x677.svg 848w, https://substackcdn.com/image/fetch/$s_!XMCF!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcff6f28d-6d99-4212-9037-81edab06c7b8_1140x677.svg 1272w, https://substackcdn.com/image/fetch/$s_!XMCF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcff6f28d-6d99-4212-9037-81edab06c7b8_1140x677.svg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p><strong>Step 1: Collecting Demonstration Data</strong> - This is similar to requirement gathering in software design. We're identifying key use cases and setting the stage for how our system should behave. Like determining the core modules of a software system, this step helps us focus on primary functionalities.</p><p><strong>Step 2: Collecting Comparison Data</strong> - Here, it's about quality assurance and validation. Multiple model outputs are generated, much like how we'd have various modules or microservices in an architecture. They're then assessed for efficiency, coherence, and quality, similar to evaluating architectural components based on their performance metrics.</p><p><strong>Step 3: Policy Optimization using Reinforcement Learning</strong> - As you should know from the <a href="https://tostring.substack.com/i/138098744/reinforcement-learning">Episode 2</a> think of this as the iterative process of architectural refinement. Just as we would optimize server loads or streamline database queries in a system, this phase continually hones the NLP model based on feedback, ensuring that it meets the set criteria.</p><p>Now, let's take a moment to appreciate the architectural impact. Embedding NLP within our digital solutions opens doors to a plethora of possibilities. Imagine a system that can not only understand user queries but also sense the urgency or the emotion behind them. It's about creating interfaces that are not just smart, but empathetic.</p><p>Yet, we must tread cautiously. The models are as good as the data they are trained on. Biases in data can lead to biases in understanding and responses, which is a significant concern.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.tostring.ai/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">toString() is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2><strong>Generative AI</strong></h2><p>Generative Adversarial Networks, or GANs, are the linchpins of Generative AI. A GAN<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-3" href="#footnote-3" target="_self">3</a> comprises two neural networks &#8211; the Generator and the Discriminator &#8211; that are trained simultaneously through adversarial training. It's like a forger trying to create a masterpiece while an art detective tries to catch the forger. Over time, the forger gets so good that the detective can&#8217;t tell the real from the fake. The Generator creates new data instances, while the Discriminator evaluates them, and with each iteration, the Generator gets better at creating realistic data. This continuous feedback loop is the essence of GANs.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!l0cs!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81c65cef-1333-441c-a926-3f79662a6a46_577x254.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!l0cs!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81c65cef-1333-441c-a926-3f79662a6a46_577x254.svg 424w, https://substackcdn.com/image/fetch/$s_!l0cs!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81c65cef-1333-441c-a926-3f79662a6a46_577x254.svg 848w, https://substackcdn.com/image/fetch/$s_!l0cs!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81c65cef-1333-441c-a926-3f79662a6a46_577x254.svg 1272w, https://substackcdn.com/image/fetch/$s_!l0cs!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81c65cef-1333-441c-a926-3f79662a6a46_577x254.svg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!l0cs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81c65cef-1333-441c-a926-3f79662a6a46_577x254.svg" width="1456" height="641" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/81c65cef-1333-441c-a926-3f79662a6a46_577x254.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:641,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;A diagram of a generative adversarial network. At the center of the\n          diagram is a box labeled 'discriminator'. Two branches feed into this\n          box from the left.  The top branch starts at the upper left of the\n          diagram with a cylinder labeled 'real world images'. An arrow leads\n          from this cylinder to a box labeled 'Sample'. An arrow from the box\n          labeled 'Sample' feeds into the 'Discriminator' box. The bottom branch\n          feeds into the 'Discriminator' box starting with a box labeled 'Random\n          Input'. An arrow leads from the 'Random Input' box to a box labeled\n          'Generator'. An arrow leads from the 'Generator' box to a second\n          'Sample' box. An arrow leads from the 'Sample' box to the\n          'Discriminator box. On the right side of the Discriminator box, an\n          arrow leads to a box containing a green circle and a red circle. The\n          word 'Real' appears in green text above the box and the word 'False'\n          appears in red below the box. Two arrows lead from this box to two\n          boxes on the right side of the diagram. One arrow leads to a box\n          labeled 'Discriminator loss'. The other arrow leads to a box labeled\n          'Generator loss'.&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="A diagram of a generative adversarial network. At the center of the
          diagram is a box labeled 'discriminator'. Two branches feed into this
          box from the left.  The top branch starts at the upper left of the
          diagram with a cylinder labeled 'real world images'. An arrow leads
          from this cylinder to a box labeled 'Sample'. An arrow from the box
          labeled 'Sample' feeds into the 'Discriminator' box. The bottom branch
          feeds into the 'Discriminator' box starting with a box labeled 'Random
          Input'. An arrow leads from the 'Random Input' box to a box labeled
          'Generator'. An arrow leads from the 'Generator' box to a second
          'Sample' box. An arrow leads from the 'Sample' box to the
          'Discriminator box. On the right side of the Discriminator box, an
          arrow leads to a box containing a green circle and a red circle. The
          word 'Real' appears in green text above the box and the word 'False'
          appears in red below the box. Two arrows lead from this box to two
          boxes on the right side of the diagram. One arrow leads to a box
          labeled 'Discriminator loss'. The other arrow leads to a box labeled
          'Generator loss'." title="A diagram of a generative adversarial network. At the center of the
          diagram is a box labeled 'discriminator'. Two branches feed into this
          box from the left.  The top branch starts at the upper left of the
          diagram with a cylinder labeled 'real world images'. An arrow leads
          from this cylinder to a box labeled 'Sample'. An arrow from the box
          labeled 'Sample' feeds into the 'Discriminator' box. The bottom branch
          feeds into the 'Discriminator' box starting with a box labeled 'Random
          Input'. An arrow leads from the 'Random Input' box to a box labeled
          'Generator'. An arrow leads from the 'Generator' box to a second
          'Sample' box. An arrow leads from the 'Sample' box to the
          'Discriminator box. On the right side of the Discriminator box, an
          arrow leads to a box containing a green circle and a red circle. The
          word 'Real' appears in green text above the box and the word 'False'
          appears in red below the box. Two arrows lead from this box to two
          boxes on the right side of the diagram. One arrow leads to a box
          labeled 'Discriminator loss'. The other arrow leads to a box labeled
          'Generator loss'." srcset="https://substackcdn.com/image/fetch/$s_!l0cs!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81c65cef-1333-441c-a926-3f79662a6a46_577x254.svg 424w, https://substackcdn.com/image/fetch/$s_!l0cs!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81c65cef-1333-441c-a926-3f79662a6a46_577x254.svg 848w, https://substackcdn.com/image/fetch/$s_!l0cs!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81c65cef-1333-441c-a926-3f79662a6a46_577x254.svg 1272w, https://substackcdn.com/image/fetch/$s_!l0cs!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81c65cef-1333-441c-a926-3f79662a6a46_577x254.svg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Breaking down the architecture of a GAN using a practical use case the generation of realistic human to understand better how the information flow and change</p><p><strong>Random Input</strong>: Technically known as a latent space vector or noise, this randomly initialized set of data points provides the initial blueprint. For our face generation task, consider this as a basic, undetailed sketch of facial features.</p><p>This code defines a function to generate a random vector of a given size. This random vector will act as the initial seed for the GAN's generator.</p><pre><code><code>import numpy as np

def generate_random_input(dimensions):
    return np.random.randn(dimensions)

random_input = generate_random_input(100)</code></code></pre><ul><li><p>The <code>numpy</code> library is imported for numerical operations.</p></li><li><p><code>generate_random_input</code> function takes an integer argument <code>dimensions</code> which specifies the size of the random vector.</p></li><li><p>The <code>np.random.randn</code> function is used to generate a random array of shape <code>dimensions</code> with values sampled from a standard normal distribution.</p></li><li><p>An example random vector of size 100 is generated.</p></li></ul><h4><strong>Generator</strong></h4><p>A deep neural network that takes the random sketch and refines it. Imagine it as an artist who takes the basic sketch and starts adding details - eyes, nose, lips, skin texture, etc., based on its learning from real faces. The deeper the network, the more intricate the details, allowing it to capture subtle facial features and expressions.</p><p>This code defines the architecture of the generator model using the Keras API. The generator model is responsible for generating data (in this case, faces) from random inputs.</p><pre><code>from keras.models import Sequential
from keras.layers import Dense, Reshape, Conv2DTranspose

def build_generator():
    model = Sequential()
    model.add(Dense(128 * 7 * 7, activation="relu", input_dim=100))
    model.add(Reshape((7, 7, 128)))
    model.add(Conv2DTranspose(128, kernel_size=4, strides=2, padding="same", activation="relu"))
    model.add(Conv2DTranspose(1, kernel_size=4, strides=2, padding="same", activation="sigmoid"))
    return model

generator = build_generator()
generated_face = generator.predict(random_input)
</code></pre><ul><li><p>The necessary modules and layers are imported from Keras.</p></li><li><p>The <code>build_generator</code> function creates a sequential model for the generator.</p></li><li><p>The <code>Dense</code> layer acts as a fully connected layer, followed by a reshape layer to format the data into a 7x7 grid.</p></li><li><p><code>Conv2DTranspose</code> layers are used for up-sampling and creating the generated image.</p></li><li><p>The generated model expects a random vector of size 100 (hence <code>input_dim=100</code>).</p></li><li><p>The generator model is then built, and a sample face is generated using the previously defined random input.</p></li></ul><h4><strong>Real Images and Sampled Data</strong></h4><p>For our use case, these would be a collection of thousands of diverse human face photographs. This dataset provides authentic examples, teaching the 'artist' (generator) about various facial structures, skin tones, expressions, and more. It's akin to an artist studying different faces to improve his drawing skills.</p><p>This code defines a function to load real images from a given path into an array.</p><pre><code>import cv2

def load_real_images(path_to_dataset):
    images = []
    for image_path in path_to_dataset:
        image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
        images.append(image)
    return np.array(images)

real_images = load_real_images(['/path/to/image1.jpg', '/path/to/image2.jpg'])
</code></pre><ul><li><p>The <code>cv2</code> module from OpenCV is imported for image loading and processing.</p></li><li><p>The <code>load_real_images</code> function takes a list of image paths and loads each image in grayscale format.</p></li><li><p>These grayscale images are then appended to an <code>images</code> list.</p></li><li><p>The list is then converted to a numpy array and returned.</p><p></p></li></ul><h4><strong>Discriminator</strong></h4><p> Think of this as an art critic. After the artist (generator) produces a face, the critic (discriminator) judges it. It looks at the drawing and compares it to real human faces it has seen. If the drawing closely resembles a real face, the critic acknowledges it. If not, it points out the discrepancies. Over time, as the critic keeps giving feedback, the artist improves, producing even more realistic face drawings.</p><p>This code defines the architecture of the discriminator model. This model's role is to determine whether an input image is real or generated.</p><p>This code defines the architecture of the discriminator model. This model's role is to determine whether an input image is real or generated.</p><pre><code>from keras.layers import Conv2D, Flatten, Dense

def build_discriminator():
    model = Sequential()
    model.add(Conv2D(64, kernel_size=4, strides=2, padding="same", input_shape=(28, 28, 1)))
    model.add(Flatten())
    model.add(Dense(1, activation="sigmoid"))
    return model

discriminator = build_discriminator()
prediction = discriminator.predict(generated_face)
</code></pre><ul><li><p>Relevant layers are imported from Keras.</p></li><li><p>The <code>build_discriminator</code> function creates a sequential model for the discriminator.</p></li><li><p>The <code>Conv2D</code> layer processes the input image, followed by a <code>Flatten</code> layer to prepare the data for the final dense layer.</p></li><li><p>The final <code>Dense</code> layer has a sigmoid activation function, which outputs the probability of the input being a real image.</p></li><li><p>The discriminator model is then built and used to predict whether the previously generated face is real or fake.</p></li></ul><p>Let's consider an architectural use case here. Imagine a project where we need to generate realistic images for a virtual reality real estate platform. GANs can be used to create images of homes, landscapes, or interiors that are realistic and aesthetically appealing, enhancing the user experience of the platform. The generated images can be used to provide a virtual tour, allowing users to experience the property without being physically present. It's about building a bridge between the digital and physical worlds, enhancing the user experience manifold.</p><p>Lastly, let's touch upon <a href="https://www.tensorflow.org/tutorials/generative/style_transfer">Style Transfer</a>, where the style of one image is transferred to another. It&#8217;s like painting a photograph with the style of Van Gogh or Picasso. This technology has a myriad of applications, from art and design to real-time video modifications.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.tostring.ai/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">toString() is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2><strong>Conclusion</strong></h2><p>I went through the realms of Large Language Models (LLMs), explored the complexity of Natural Language Processing (NLP), and dig into the creativity unleashed by Generative AI. The concepts and technologies I&#8217;ve discussed in this episode shows to the rapid advancements in the field of AI. As architects, the understanding of these technologies empowers us to design intelligent systems that can interact, understand, and even generate human-like text or realistic images, adding a new dimension to user experiences.</p><p>Our exploration into the heart of machine and human language interaction has revealed a landscape rich with potential. The techniques and models discussed are not futuristic; they are here, and they are being integrated into the architectural designs, delivering solutions that are robust, intelligent, and intuitive.</p><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-1" href="#footnote-anchor-1" class="footnote-number" contenteditable="false" target="_self">1</a><div class="footnote-content"><p>Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., ... &amp; Polosukhin, I. (2017). Attention is all you need. In Advances in neural information processing systems (pp. 5998-6008).</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-2" href="#footnote-anchor-2" class="footnote-number" contenteditable="false" target="_self">2</a><div class="footnote-content"><p>Radford, A., Wu, J., Child, R., Luan, D., Amodei, D., &amp; Sutskever, I. (2019). Language models are unsupervised multitask learners. OpenAI Blog, 1(8), 9</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-3" href="#footnote-anchor-3" class="footnote-number" contenteditable="false" target="_self">3</a><div class="footnote-content"><p>Goodfellow, I., Pouget-Abadie, J., Mirza, M., Xu, B., Warde-Farley, D., Ozair, S., ... &amp; Bengio, Y. (2014). Generative adversarial nets. In Advances in neural information processing systems (pp. 2672-2680).</p></div></div>]]></content:encoded></item><item><title><![CDATA[E3: Architecting Intelligence - Deep Learning ]]></title><description><![CDATA[Architecture and Artificial Intelligence through Deep Learning]]></description><link>https://www.tostring.ai/p/e3-architecting-intelligence-deep</link><guid isPermaLink="false">https://www.tostring.ai/p/e3-architecting-intelligence-deep</guid><dc:creator><![CDATA[Marco Altea]]></dc:creator><pubDate>Fri, 27 Oct 2023 08:30:19 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ec2dd1c-633b-40a0-8c81-08ff49da6a71_3561x3141.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2><strong>Introduction</strong></h2><p><a href="https://tostring.substack.com/p/e2-journey-into-how-machines-learn">In the previous episode</a>, I explored the core principles of Machine Learning. Now, I transition to Deep Learning (DL), focusing on Neural Networks, the foundational aspect of DL. Neural Networks are inspired by the human brain's structure, aiding the creation of advanced intelligent systems. This shift to DL represents a deeper exploration into machine intelligence, allowing for more complex data interpretations. As I go into Neural Networks, and later, CNNs and RNNs, let me set the stage for a detailed exploration of DL from an architectural standpoint.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!r63h!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5e63dda-c075-4bc8-94f8-7e85218440e1_1024x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!r63h!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5e63dda-c075-4bc8-94f8-7e85218440e1_1024x1024.png 424w, https://substackcdn.com/image/fetch/$s_!r63h!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5e63dda-c075-4bc8-94f8-7e85218440e1_1024x1024.png 848w, https://substackcdn.com/image/fetch/$s_!r63h!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5e63dda-c075-4bc8-94f8-7e85218440e1_1024x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!r63h!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5e63dda-c075-4bc8-94f8-7e85218440e1_1024x1024.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!r63h!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5e63dda-c075-4bc8-94f8-7e85218440e1_1024x1024.png" width="566" height="566" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c5e63dda-c075-4bc8-94f8-7e85218440e1_1024x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:566,&quot;bytes&quot;:1602950,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!r63h!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5e63dda-c075-4bc8-94f8-7e85218440e1_1024x1024.png 424w, https://substackcdn.com/image/fetch/$s_!r63h!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5e63dda-c075-4bc8-94f8-7e85218440e1_1024x1024.png 848w, https://substackcdn.com/image/fetch/$s_!r63h!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5e63dda-c075-4bc8-94f8-7e85218440e1_1024x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!r63h!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5e63dda-c075-4bc8-94f8-7e85218440e1_1024x1024.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The history of Deep Learning (DL) reflects a gradual evolution of understanding and technological advancements. Here's a concise list of key milestones and notable figures in the field:</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.tostring.ai/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">toString() is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><ol><li><p><strong>Origins in Neural Networks</strong>: The concept of neural networks dates back to the 1940s. In 1943, <a href="https://en.wikipedia.org/wiki/Warren_Sturgis_McCulloch">Warren McCulloch</a> and <a href="https://en.wikipedia.org/wiki/Walter_Pitts">Walter Pitts</a> proposed a computational model of an artificial neuron, laying the groundwork for future developments in neural network theories&#8203;<a href="https://reason.town/deep-learning-milestones/#:~:text=Here%20are%20some%20notable%20milestones,which%20is%20still%20used%20today"><sup>1</sup></a>&#8203;.</p></li><li><p><strong>Perceptron Era</strong>: In 1958, <a href="https://en.wikipedia.org/wiki/Frank_Rosenblatt">Frank Rosenblatt</a> introduced the <a href="https://en.wikipedia.org/wiki/Perceptron">Perceptron</a>, a type of artificial neuron, which became a foundational element of neural network research.</p></li><li><p><strong>Backpropagation Algorithm</strong>: In the 1980s, the backpropagation algorithm was introduced, which is crucial for training multi-layer neural networks. This algorithm significantly contributed to the development and training of deep neural networks.</p></li><li><p><strong>Convolutional Neural Networks (CNNs)</strong>: In 1998, <a href="https://en.wikipedia.org/wiki/Yann_LeCun">Yann LeCun</a> introduced LeNet-5, a pioneering convolutional neural network that significantly influenced the development of CNNs.</p></li><li><p><strong>Deep Learning Renaissance</strong>: With the advent of big data and increased computational power, the early 2000s saw a resurgence in interest and advancements in deep learning. Pioneers like Geoffrey Hinton, Yann LeCun, and Yoshua Bengio played pivotal roles during this period.</p></li><li><p><strong>ImageNet Competition</strong>: The 2012 ImageNet competition marked a significant milestone with the introduction of AlexNet, a deep convolutional neural network that drastically reduced error rates in image recognition tasks, propelling DL to the forefront of AI research.</p></li><li><p><strong>Recent Advancements</strong>: Recent years have witnessed a rapid proliferation of deep learning applications across various domains, powered by advancements in neural network architectures, training algorithms, and the availability of vast amounts of data.</p></li></ol><p>Some of the main sources that I used to understand Deep Learning are</p><ol><li><p>"<a href="http://www.deeplearningbook.org/">Deep Learning</a>" by Ian Goodfellow, Yoshua Bengio, and Aaron Courville.</p></li><li><p><a href="https://www.nature.com/articles/nature14539">&#8220;Deep Learning&#8221;</a> by Yann LeCun, Yoshua Bengio &amp; Geoffrey Hinton&nbsp;</p></li><li><p>"<a href="http://neuralnetworksanddeeplearning.com/">Neural Networks and Deep Learning</a>" by Michael Nielsen.</p></li><li><p>"<a href="https://arxiv.org/abs/1801.00631">Deep Learning: A Critical Appraisal</a>" by Gary Marcus.</p></li></ol><p>And some amazing Substack that facilitate my understandment with two specific post are</p><div class="embedded-post-wrap" data-attrs="{&quot;id&quot;:105172284,&quot;url&quot;:&quot;https://artificialintelligencemadesimple.substack.com/p/how-to-build-large-ai-models-like&quot;,&quot;publication_id&quot;:1315074,&quot;publication_name&quot;:&quot;Artificial Intelligence Made Simple&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77504fa0-0f08-4a38-bbde-becb151d2db8_643x644.png&quot;,&quot;title&quot;:&quot;How to build Large AI Models like ChatGPT efficiently&quot;,&quot;truncated_body_text&quot;:&quot;Large Models have captured a lot of attention from people. By adding more parameters and data to the model, we can add more capabilities to a system. Additional parameters allow for more kinds of connections in your neurons, giving your neural networks both better performance on existing tasks and the ability to develop new kinds of skills, as this gif &#8230;&quot;,&quot;date&quot;:&quot;2023-02-26T14:17:19.627Z&quot;,&quot;like_count&quot;:7,&quot;comment_count&quot;:2,&quot;bylines&quot;:[{&quot;id&quot;:8101724,&quot;name&quot;:&quot;Devansh&quot;,&quot;handle&quot;:&quot;chocolatemilkcultleader&quot;,&quot;previous_name&quot;:null,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f49c53d6-8d45-4cba-a7f9-342282e6fd31_643x644.jpeg&quot;,&quot;bio&quot;:&quot;The best meme-maker in Tech.\nWriter on AI, Software, and the Tech Industry.\nCome say hi, I need more friends&quot;,&quot;profile_set_up_at&quot;:&quot;2021-08-21T20:28:53.612Z&quot;,&quot;publicationUsers&quot;:[{&quot;id&quot;:1274217,&quot;user_id&quot;:8101724,&quot;publication_id&quot;:1315074,&quot;role&quot;:&quot;admin&quot;,&quot;public&quot;:true,&quot;is_primary&quot;:true,&quot;publication&quot;:{&quot;id&quot;:1315074,&quot;name&quot;:&quot;Artificial Intelligence Made Simple&quot;,&quot;subdomain&quot;:&quot;artificialintelligencemadesimple&quot;,&quot;custom_domain&quot;:null,&quot;custom_domain_optional&quot;:false,&quot;hero_text&quot;:&quot;Turning complex ideas in AI Research, Machine Learning, Deep Learning, and Data Science into actionable insights. Read in over 160 countries. Sister Publication to Tech Made Simple&quot;,&quot;logo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/77504fa0-0f08-4a38-bbde-becb151d2db8_643x644.png&quot;,&quot;author_id&quot;:8101724,&quot;theme_var_background_pop&quot;:&quot;#009B50&quot;,&quot;created_at&quot;:&quot;2023-01-14T23:37:24.692Z&quot;,&quot;rss_website_url&quot;:null,&quot;email_from_name&quot;:null,&quot;copyright&quot;:&quot;Devansh&quot;,&quot;founding_plan_name&quot;:null,&quot;community_enabled&quot;:true,&quot;invite_only&quot;:false,&quot;payments_state&quot;:&quot;disabled&quot;,&quot;language&quot;:null,&quot;explicit&quot;:false}},{&quot;id&quot;:109622,&quot;user_id&quot;:8101724,&quot;publication_id&quot;:108704,&quot;role&quot;:&quot;admin&quot;,&quot;public&quot;:true,&quot;is_primary&quot;:false,&quot;publication&quot;:{&quot;id&quot;:108704,&quot;name&quot;:&quot;Technology Made Simple&quot;,&quot;subdomain&quot;:&quot;codinginterviewsmadesimple&quot;,&quot;custom_domain&quot;:null,&quot;custom_domain_optional&quot;:false,&quot;hero_text&quot;:&quot;Deep yet digestible insights about Computer Science, Programming Interviews, Software Engineering Careers, Machine Learning, and the Tech Industry for Tech Leaders. Amazing For Coders and Managers. Beneficial to anyone trying to make money in Tech. &quot;,&quot;logo_url&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/8546dc69-af46-4d5d-9a80-b66cb76c833b_644x644.png&quot;,&quot;author_id&quot;:8101724,&quot;theme_var_background_pop&quot;:&quot;#45D800&quot;,&quot;created_at&quot;:&quot;2020-10-07T10:47:41.199Z&quot;,&quot;rss_website_url&quot;:null,&quot;email_from_name&quot;:&quot;Devansh from Tech Made Simple&quot;,&quot;copyright&quot;:&quot;Devansh&quot;,&quot;founding_plan_name&quot;:&quot;Founding Member&quot;,&quot;community_enabled&quot;:true,&quot;invite_only&quot;:false,&quot;payments_state&quot;:&quot;enabled&quot;,&quot;language&quot;:null,&quot;explicit&quot;:false}}],&quot;twitter_screen_name&quot;:&quot;Machine01776819&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;utm_campaign&quot;:null,&quot;belowTheFold&quot;:true,&quot;type&quot;:&quot;newsletter&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="EmbeddedPostToDOM"><a class="embedded-post" native="true" href="https://artificialintelligencemadesimple.substack.com/p/how-to-build-large-ai-models-like?utm_source=substack&amp;utm_campaign=post_embed&amp;utm_medium=web"><div class="embedded-post-header"><img class="embedded-post-publication-logo" src="https://substackcdn.com/image/fetch/$s_!Pfon!,w_56,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77504fa0-0f08-4a38-bbde-becb151d2db8_643x644.png" loading="lazy"><span class="embedded-post-publication-name">Artificial Intelligence Made Simple</span></div><div class="embedded-post-title-wrapper"><div class="embedded-post-title">How to build Large AI Models like ChatGPT efficiently</div></div><div class="embedded-post-body">Large Models have captured a lot of attention from people. By adding more parameters and data to the model, we can add more capabilities to a system. Additional parameters allow for more kinds of connections in your neurons, giving your neural networks both better performance on existing tasks and the ability to develop new kinds of skills, as this gif &#8230;</div><div class="embedded-post-cta-wrapper"><span class="embedded-post-cta">Read more</span></div><div class="embedded-post-meta">3 years ago &#183; 7 likes &#183; 2 comments &#183; Devansh</div></a></div><div class="embedded-post-wrap" data-attrs="{&quot;id&quot;:83380695,&quot;url&quot;:&quot;https://www.deeplearningweekly.com/p/deep-learning-weekly-issue-275&quot;,&quot;publication_id&quot;:289327,&quot;publication_name&quot;:&quot;Deep Learning Weekly&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fc63609b6-c5bb-426a-a5c1-b6ce9d56b51e_468x468.png&quot;,&quot;title&quot;:&quot;Deep Learning Weekly: Issue #275&quot;,&quot;truncated_body_text&quot;:&quot;Hey Folks, This week in deep learning, we bring you Meta AI's neural theorem prover that has solved 10 IMO problems, partial blockout experiments at Booking.com, fine-tuning Whisper for Multilingual ASR with Hugging Face Transformers, and a paper on Efficient Spatially Sparse Inference for Conditional GANs and Diffusion Models&quot;,&quot;date&quot;:&quot;2022-11-09T15:49:25.555Z&quot;,&quot;like_count&quot;:9,&quot;comment_count&quot;:0,&quot;bylines&quot;:[{&quot;id&quot;:16414786,&quot;name&quot;:&quot;Miko Planas&quot;,&quot;handle&quot;:null,&quot;previous_name&quot;:null,&quot;photo_url&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/fbdc97c3-70aa-49d6-9215-13e13a5a33db_293x392.png&quot;,&quot;bio&quot;:&quot;Industrial Engineering - Deep Learning - Music Production - Rock Climbing&quot;,&quot;profile_set_up_at&quot;:&quot;2023-01-12T14:36:25.664Z&quot;,&quot;is_guest&quot;:true,&quot;bestseller_tier&quot;:null}],&quot;utm_campaign&quot;:null,&quot;belowTheFold&quot;:true,&quot;type&quot;:&quot;newsletter&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="EmbeddedPostToDOM"><a class="embedded-post" native="true" href="https://www.deeplearningweekly.com/p/deep-learning-weekly-issue-275?utm_source=substack&amp;utm_campaign=post_embed&amp;utm_medium=web"><div class="embedded-post-header"><img class="embedded-post-publication-logo" src="https://substackcdn.com/image/fetch/$s_!yiM2!,w_56,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fc63609b6-c5bb-426a-a5c1-b6ce9d56b51e_468x468.png" loading="lazy"><span class="embedded-post-publication-name">Deep Learning Weekly</span></div><div class="embedded-post-title-wrapper"><div class="embedded-post-title">Deep Learning Weekly: Issue #275</div></div><div class="embedded-post-body">Hey Folks, This week in deep learning, we bring you Meta AI's neural theorem prover that has solved 10 IMO problems, partial blockout experiments at Booking.com, fine-tuning Whisper for Multilingual ASR with Hugging Face Transformers, and a paper on Efficient Spatially Sparse Inference for Conditional GANs and Diffusion Models&#8230;</div><div class="embedded-post-cta-wrapper"><span class="embedded-post-cta">Read more</span></div><div class="embedded-post-meta">3 years ago &#183; 9 likes &#183; Miko Planas</div></a></div><h2><strong>Neural Networks</strong></h2><p>In my journey into Deep Learning, the first stop is Neural Networks (NNs). Being a cornerstone for many Deep Learning applications, understanding NNs is crucial for an architect to leverage AI in their solutions.</p><p>A Neural Network is a computational model inspired by the human brain's interconnected neuron structure. It's a framework for building and training models to understand and solve complex patterns, making them vital for various AI applications.</p><h3><strong>Components of NN</strong></h3><h4><strong>Input Layer</strong></h4><p>The initial layer where the model receives its data. Each neuron in this layer corresponds to one feature in the data set, acting as the entry point for data to flow into the network.</p><h4><strong>Hidden Layers</strong></h4><p>These are the layers between the input and output layers, where the &#8220;Magic&#8221; happens. Each neuron in a hidden layer receives inputs from all neurons in the previous layer, applies a transformation (typically non-linear), and passes its output to all neurons in the next layer. The presence of multiple hidden layers is what makes a Neural Network <strong>"deep"</strong> - leading to the term Deep Learning.</p><h4><strong>Output Layer</strong></h4><p>The final layer where the model makes its predictions. The number of neurons in this layer corresponds to the number of possible outputs.</p><p>The connections between neurons are represented by weights, which are adjusted during training to minimize the error between the model's predictions and the actual target values.</p><p>Check this diagram below that I have created to represent a NN</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!KpTI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17744ffb-79ea-434b-8e99-c87d8587be6d_1581x1631.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!KpTI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17744ffb-79ea-434b-8e99-c87d8587be6d_1581x1631.png 424w, https://substackcdn.com/image/fetch/$s_!KpTI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17744ffb-79ea-434b-8e99-c87d8587be6d_1581x1631.png 848w, https://substackcdn.com/image/fetch/$s_!KpTI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17744ffb-79ea-434b-8e99-c87d8587be6d_1581x1631.png 1272w, https://substackcdn.com/image/fetch/$s_!KpTI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17744ffb-79ea-434b-8e99-c87d8587be6d_1581x1631.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!KpTI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17744ffb-79ea-434b-8e99-c87d8587be6d_1581x1631.png" width="1456" height="1502" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/17744ffb-79ea-434b-8e99-c87d8587be6d_1581x1631.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1502,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:411265,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!KpTI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17744ffb-79ea-434b-8e99-c87d8587be6d_1581x1631.png 424w, https://substackcdn.com/image/fetch/$s_!KpTI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17744ffb-79ea-434b-8e99-c87d8587be6d_1581x1631.png 848w, https://substackcdn.com/image/fetch/$s_!KpTI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17744ffb-79ea-434b-8e99-c87d8587be6d_1581x1631.png 1272w, https://substackcdn.com/image/fetch/$s_!KpTI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17744ffb-79ea-434b-8e99-c87d8587be6d_1581x1631.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Here is a Python code example that translate the diagram above, using <a href="https://www.tensorflow.org/guide">TensorFlow</a></p><pre><code># neural_network.py

import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers

# Based on the diagram provided:
# - Input Layer: 4 neurons (Green Circles)
# - Hidden Layer 1: 6 neurons (First set of Orange Circles)
# - Hidden Layer 2: 3 neurons (Second set of Orange Circles)
# - Hidden Layer 3: 3 neurons (Grey Circles)
# - Output Layer: 1 neuron (Blue Circle)

# 1. Initializing the Sequential Model
model = keras.Sequential()

# 2. Adding the Input Layer
# Corresponding to the 4 Green Circles in the diagram.
# Each neuron corresponds to a distinct feature of the input

model.add(layers.Dense(units=4, activation='relu', input_dim=4, name="input_layer"))

# 3. Adding Hidden Layers

# First Hidden Layer - corresponds to the 6 Orange Circles in the diagram.
# Neurons in hidden layers process the incoming data from the previous layer and transform it using an activation function.

model.add(layers.Dense(units=6, activation='relu', name="hidden_layer_1"))

# Second Hidden Layer - corresponds to the 3 Orange Circles in the diagram.

model.add(layers.Dense(units=3, activation='relu', name="hidden_layer_2"))

# Third Hidden Layer - corresponds to the 3 Grey Circles in the diagram.

model.add(layers.Dense(units=3, activation='relu', name="hidden_layer_3"))

# 4. Adding the Output Layer
# Corresponding to the single Blue Circle in the diagram.
# The neuron in the output layer produces the final prediction of the model.

model.add(layers.Dense(units=1, name="output_layer"))

# 5. Compile the model
# 'mean_squared_error' is a common loss function for regression problems.
# The optimizer 'adam' is an algorithm that adjusts neuron weights to minimize the error during training.

model.compile(optimizer='adam', loss='mean_squared_error')

# NOTE on Nodes (Neurons):
# - Nodes in the input layer represent distinct features of the input data.
# - Nodes in hidden layers process the data, applying transformations using their weights and activation functions.
# - The node in the output layer provides the final prediction of the neural network.
# 
# NOTE on Weights:
# Every connection between the neurons in the diagram has a corresponding weight in the model.
# These weights determine how much influence one neuron has on the next neuron it's connected to.
# During training, the model adjusts these weights to better fit the training data and reduce prediction errors.
</code></pre><p>It&#8217;s important to understand that each node in the diagram computes a weighted sum of its inputs and then applies an activation function to this sum. To be specific the activation sum is mathematical function that determines the output of a neuron.</p><p>In the context of the code I provided, I&#8217;m using the activation functions that TensorFlow provides. Specifically, I&#8217;ve chosen the <code>relu</code><a href="https://www.tensorflow.org/api_docs/python/tf/keras/layers/ReLU"> (Rectified Linear Unit) </a>activation function for the input and hidden layers.</p><pre><code><code>model.add(layers.Dense(units=6, activation='relu', name="hidden_layer_1"))</code></code></pre><p><code>relu</code> Activation Function: <a href="https://www.tensorflow.org/api_docs/python/tf/keras/layers/ReLU">The Rectified Linear Unit (ReLU)</a> is one of the most widely used activation functions in deep neural networks, especially for feedforward and convolutional neural networks. Mathematically, it's defined as </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;f(x)=max(0,x)&quot;,&quot;id&quot;:&quot;GUAQHENNUE&quot;}" data-component-name="LatexBlockToDOM"></div><p>The function returns x if x is greater than or equal to 0, and returns 0 otherwise. The ReLU function is non-linear, which means it allows for complex mappings and is computationally efficient, making the network easier and faster to train.</p><p>The <code>activation='relu'</code> argument specifies that the <code>relu</code> activation function should be used for the neurons in that layer.</p><p>TensorFlow provides <a href="https://www.tensorflow.org/api_docs/python/tf/keras/activations">a variety of other activation functions</a> like <code>sigmoid</code>, <code>tanh</code>, <code>softmax</code>, and more. The choice of activation function depends on the specific task, the nature of the data, and the architecture of the neural network. In many cases, ReLU (or its variants like LeakyReLU or ParametricReLU) is a good default choice for hidden layers in feedforward neural networks. Potential If you have a specific reason or hypothesis, you can customize and create a neural network where each neuron or a group of neurons performs a different specific operation,</p><p>Deep Learning, via Neural Networks, has significantly expanded the capabilities of machine learning, addressing complex problems that were previously unsolvable with traditional machine learning models.</p><h3><strong>Neural Networks vs Classic Machine Learning:</strong></h3><p>Neural Networks, forming the core of Deep Learning, have a number of advantages over traditional machine learning methods:</p><ol><li><p><strong>Automatic Feature Extraction:</strong> Neural Networks have the capability to automatically discover and learn features from raw data. This is a significant advantage over traditional machine learning methods where feature engineering is manual, and domain expertise is required to design features.</p></li><li><p><strong>Complex Problem-Solving:</strong> They can model complex, non-linear relationships, which is crucial for solving complex problems that traditional machine learning models struggle with.</p></li><li><p><strong>Scalability:</strong> Neural Networks tend to perform better as the size of the data increases, making them highly scalable.</p></li><li><p><strong>Multi-dimensional and Sequential Data Handling:</strong> They are adept at handling multi-dimensional and sequential data, which is invaluable in fields like image and video recognition, and natural language processing.</p></li></ol><p>One of the part that fascinate me the most is the <em>Automatic Feature Engineering</em> </p><blockquote><p><em><strong>Feature engineering</strong> or <strong>feature extraction</strong> or <strong>feature discovery</strong> is the process of extracting features (characteristics, properties, attributes) from raw data.<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a></em></p></blockquote><p>For instance, in a dataset related real estate prices, features might include the size of the property, the number of rooms, the neighborhood's crime rate, proximity to schools, etc. In a text classification problem, features might include word counts, the frequency of certain words, the length of the text, etc.</p><p>In traditional ML, much of the feature engineering needs to be done manually which can be time-consuming and require domain expertise. On the other hand, deep learning models, especially neural networks, are capable of automatic feature extraction from raw data. This is one of the reasons why deep learning models have gained popularity for complex tasks such as image and text analysis where manual feature engineering would be incredibly challenging or impractical.</p><h2><strong>Convolutional Neural Networks (CNN)</strong></h2><p>Convolutional Neural Networks (CNN) are a class of deep learning models specially designed to process grid-like data, such as images. Unlike traditional Neural Networks, CNNs have a unique architecture well-suited to automatically and adaptively learn spatial hierarchies of features from input data.</p><h3><strong>Components of CNN</strong></h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!O4yQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ec2dd1c-633b-40a0-8c81-08ff49da6a71_3561x3141.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!O4yQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ec2dd1c-633b-40a0-8c81-08ff49da6a71_3561x3141.png 424w, https://substackcdn.com/image/fetch/$s_!O4yQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ec2dd1c-633b-40a0-8c81-08ff49da6a71_3561x3141.png 848w, https://substackcdn.com/image/fetch/$s_!O4yQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ec2dd1c-633b-40a0-8c81-08ff49da6a71_3561x3141.png 1272w, https://substackcdn.com/image/fetch/$s_!O4yQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ec2dd1c-633b-40a0-8c81-08ff49da6a71_3561x3141.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!O4yQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ec2dd1c-633b-40a0-8c81-08ff49da6a71_3561x3141.png" width="1456" height="1284" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6ec2dd1c-633b-40a0-8c81-08ff49da6a71_3561x3141.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1284,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1010443,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!O4yQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ec2dd1c-633b-40a0-8c81-08ff49da6a71_3561x3141.png 424w, https://substackcdn.com/image/fetch/$s_!O4yQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ec2dd1c-633b-40a0-8c81-08ff49da6a71_3561x3141.png 848w, https://substackcdn.com/image/fetch/$s_!O4yQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ec2dd1c-633b-40a0-8c81-08ff49da6a71_3561x3141.png 1272w, https://substackcdn.com/image/fetch/$s_!O4yQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6ec2dd1c-633b-40a0-8c81-08ff49da6a71_3561x3141.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h4><strong>Convolutional Layer</strong></h4><p>This is the core building block of a CNN. The layer's parameters consist of a set of learnable filters (or kernels), which have a small receptive field, but extend through the full depth of the input volume. During the forward pass, each filter is convolved across the width and height of the input volume, computing the dot product between the entries of the filter and the input, producing a 2-dimensional activation map.</p><h4><strong>Pooling Layer</strong></h4><p>Pooling (subsampling or down-sampling) reduces the dimensionality of each feature map and retains the most essential information. It could be done through various methods like max pooling, average pooling, etc.</p><h4><strong>Fully Connected Layer</strong></h4><p>Fully connected layers connect every neuron in one layer to every neuron in the next layer, which is the same as traditional neural networks as explained above.</p><h4><strong>Activation Functions</strong></h4><p>Activation functions like ReLU (Rectified Linear Unit) introduce non-linear properties to the system. Their main purpose is to convert a input signal of a node in a A-NN to an output signal. That output signal now is used as a input in the next layer in the stack.</p><h4><strong>Output Layer</strong></h4><p>The final layer which produces the output based on the learned features</p><p>Now I used TensorFlow's Keras API to create a Convolutional Neural Network (CNN) model that matches the diagram.</p><pre><code># CNN_Model.py

import tensorflow as tf
from tensorflow.keras import layers, models

# Initializing the CNN model
model = models.Sequential()

# Referencing the Image Icon in the provided diagram
# Assuming the input image has a shape of (64, 64, 3), which is a standard for RGB images.

# Convolution Block 1 (referenced as Blue in the diagram)
model.add(layers.Conv2D(32, (3,3), activation='relu', input_shape=(64, 64, 3)))
model.add(layers.MaxPooling2D((2, 2)))

# Convolution Block 2 (referenced as Green in the diagram)
model.add(layers.Conv2D(64, (3,3), activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))

# Convolution Block 3 (referenced as Orange in the diagram)
model.add(layers.Conv2D(128, (3,3), activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))

# Flatten Layer (referenced as Gray in the diagram)
model.add(layers.Flatten()) 

# Fully Connected Layer 1 (represented as circles in "Layer 1")
model.add(layers.Dense(128, activation='relu'))

# Fully Connected Layer 2 (represented as circles in "Layer 2")
model.add(layers.Dense(64, activation='relu'))

# Fully Connected Layer 3 (represented as circles in "Layer 3")
model.add(layers.Dense(32, activation='relu'))

# Output Layer (represented as the "Output" Yellow rectangle in the diagram)
# Assuming a binary classification task for simplicity

model.add(layers.Dense(1, activation='sigmoid')) # Use 'softmax' for multi-class problems.

model.compile(optimizer='adam',
              loss='binary_crossentropy', # Use 'categorical_crossentropy' for multi-class problems.
              metrics=['accuracy'])

# Printing the model summary for clarity
model.summary()
</code></pre><ol><li><p>I start by importing the necessary modules from TensorFlow's Keras API.</p></li><li><p>The <code>Sequential</code><a href="https://www.tensorflow.org/api_docs/python/tf/keras/Sequential"> model</a> is initialized, indicating that layers are added in sequence.</p></li><li><p>Following the structure of the provided image:</p><ul><li><p>We add three <code>Conv2D</code><a href="https://www.tensorflow.org/api_docs/python/tf/keras/layers/Conv2D"> layers</a> for convolution operations, where each layer attempts to identify patterns in the image. They are followed by <code>MaxPooling2D</code><a href="https://www.tensorflow.org/api_docs/python/tf/keras/layers/MaxPooling2D"> layers</a> which down-sample the spatial dimensions of the previous layer.</p></li><li><p>The <code>Flatten</code><a href="https://www.tensorflow.org/api_docs/python/tf/keras/layers/Flatten"> layer</a> converts the 2D matrices from previous layers into a 1D vector.</p></li><li><p>Three fully connected <code>Dense</code><a href="https://www.tensorflow.org/api_docs/python/tf/keras/layers/Dense"> layers</a> follow the flattening operation. They perform high-level reasoning based on the patterns identified in previous layers.</p></li><li><p>Finally, an output <code>Dense</code> layer is added. I assumed a binary classification task, but this can be modified based on the number of classes in the task.</p></li></ul></li><li><p>The <code>compile</code><a href="https://www.tensorflow.org/api_docs/python/tf/keras/Model#compile"> method</a> prepares the model for training, specifying the optimizer, loss function, and evaluation metric.</p></li><li><p><code>model.summary() </code><a href="https://www.tensorflow.org/api_docs/python/tf/keras/Model#summary">method</a> prints a summary of the model's architecture, so you can visually inspect the sequence of layers.</p></li></ol><p>As an architect, CNNs opens up a new spectrum of design solutions. With CNNs, applications like real-time image and video recognition, or even complex anomaly detection in multidimensional data become feasible. The<strong> automated feature extraction</strong> capability of CNNs can significantly reduce the time and effort required in the data preprocessing stage, allowing for quicker deployments and iterations. Understanding the architectural underpinnings and the potential of CNNs can lead to more informed decisions when designing systems revolving around image or video data processing.</p><h2><strong>Recurrent Neural Networks (RNN)</strong></h2><p>Recurrent Neural Networks (RNN)<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a> are a class of artificial neural networks where connections between nodes form a directed graph along a temporal sequence. Unlike traditional neural networks, RNNs have a "memory" that captures information about what has been calculated so far. This feature makes RNNs extremely useful for tasks involving sequential data like time series prediction, natural language processing, and speech recognition.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6K3V!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F198ad895-a6bd-47c0-bd5b-72f7347dd97a_1581x1881.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6K3V!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F198ad895-a6bd-47c0-bd5b-72f7347dd97a_1581x1881.png 424w, https://substackcdn.com/image/fetch/$s_!6K3V!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F198ad895-a6bd-47c0-bd5b-72f7347dd97a_1581x1881.png 848w, https://substackcdn.com/image/fetch/$s_!6K3V!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F198ad895-a6bd-47c0-bd5b-72f7347dd97a_1581x1881.png 1272w, https://substackcdn.com/image/fetch/$s_!6K3V!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F198ad895-a6bd-47c0-bd5b-72f7347dd97a_1581x1881.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6K3V!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F198ad895-a6bd-47c0-bd5b-72f7347dd97a_1581x1881.png" width="1456" height="1732" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/198ad895-a6bd-47c0-bd5b-72f7347dd97a_1581x1881.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1732,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:421459,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!6K3V!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F198ad895-a6bd-47c0-bd5b-72f7347dd97a_1581x1881.png 424w, https://substackcdn.com/image/fetch/$s_!6K3V!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F198ad895-a6bd-47c0-bd5b-72f7347dd97a_1581x1881.png 848w, https://substackcdn.com/image/fetch/$s_!6K3V!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F198ad895-a6bd-47c0-bd5b-72f7347dd97a_1581x1881.png 1272w, https://substackcdn.com/image/fetch/$s_!6K3V!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F198ad895-a6bd-47c0-bd5b-72f7347dd97a_1581x1881.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3><strong>Components of RNN</strong></h3><h4><strong>Recurrent Layer</strong></h4><p>The recurrent layer consists of a loop that connects the current time step to the previous time step, enabling the network to use information from the past in the current computation.</p><h4><strong>Hidden State</strong></h4><p>The hidden state captures information from previous time steps. It's like the memory of the network, retaining crucial insights from past data to help in current processing.</p><h4><strong>Output Layer</strong></h4><p>The output layer generates the final output for the current time step based on the current input and the hidden state.</p><h4><strong>Activation Functions</strong></h4><p>Similar to other neural networks, activation functions introduce non-linearity into the system, which enables the network to learn from the error, and make adjustments to the weights of the inputs.</p><h4>Loss Function</h4><p>The loss function (like Cross-Entropy or Mean Squared Error) measures the discrepancy between the predicted output and the true output, guiding the optimization of the network weights.</p><h3><strong>Recurrent Mechanism</strong></h3><h4><strong>Hidden State</strong></h4><p>The primary component responsible for memory in RNNs is the hidden state. The hidden state is a representation that captures information from past inputs and carries it forward to help process future inputs. At each time step, the hidden state is updated based on the current input and the previous hidden state. This way, it encapsulates information from all the previous steps up to the current step.</p><pre><code># Simplified RNN mechanism

hidden_state = initial_state

# This state will be updated over time
# Combine the input and the current state to generate the new state
# Now, hidden_state contains information from the past and the current input

for input in sequence: 
hidden_state = activation_function(W * input + U * hidden_state + b)  </code></pre><h4>
<strong>Recurrent Connections</strong></h4><p>The recurrent connections are what allow the network to maintain this memory. They create a looped pathway that feeds the hidden state from one step back into the network for the next step. This recurrent loop essentially creates a form of memory, where information from previous steps can continue to influence the processing of new steps.</p><h4><strong>Memory in Action</strong></h4><p>Consider a simple task of predicting the next word in a sentence. If the current word is "sky", and the previous words were "The", and "blue", an RNN could use its memory of these previous words to help predict that the next word might be "is". The memory in this case helps the RNN understand the context in which the current word appears.</p><h4><strong>Memory Duration</strong></h4><p>The ability of RNNs to maintain this memory over many steps is both its strength and its weakness. While it's useful for understanding context over sequences, the memory in basic RNNs tends to be quite short-term due to the vanishing gradient problem, which makes it hard for the network to learn from interactions occurring over longer sequences. Advanced variants of RNNs like Long Short-Term Memory (LSTM) networks and Gated Recurrent Units (GRUs) have been developed to address this, providing longer-term memory capabilities and making RNNs even more powerful for handling sequential data.</p><p>In summary, memory in RNNs facilitates the processing and understanding of sequential or temporal data by allowing the network to use information from past inputs while processing current inputs, which is crucial for tasks like language modeling, time series prediction, and many other applications where understanding context over time is essential.</p><p>I again used TensorFlow's Keras API to create a Recurrent Neural Network (RNN) model that matches the diagram. </p><pre><code># RNN_Model.py

import tensorflow as tf
from tensorflow.keras import layers, models

# Initializing the model

model = models.Sequential()

# Input Layer (represented as green circles in the diagram)
# Assuming input data is of shape (n, m) where n represents features and m represents samples.

model.add(layers.Input(shape=(None,)))

# Hidden Layer 1 (referenced as "Layer 1" in the diagram)
# Assuming 5 neurons based on the diagram

model.add(layers.Dense(5, activation='relu'))

# Recurrence within Hidden Layer (indicated by the dashed red line)
# A simple recurrence can be implemented using a SimpleRNN layer in Keras.
# Here, we're assuming recurrence in the second hidden layer.
# Assuming 5 neurons

model.add(layers.SimpleRNN(5, activation='relu', return_sequences=True)) 

# Hidden Layer 2 (referenced as "Layer 2" in the diagram)
# After the SimpleRNN layer, the data will be 3D (batch_size, timesteps, features).
# So, we need to flatten the data to feed into the Dense layer.

model.add(layers.Flatten())
model.add(layers.Dense(5, activation='relu')) # Assuming 5 neurons based on the diagram

# Output Layer (represented as the blue circle in the diagram)
# Assuming a single output for regression task.

model.add(layers.Dense(1))

# Compiling the model

model.compile(optimizer='adam', loss='mean_squared_error')

# Printing the model summary for clarity

model.summary()</code></pre><ol><li><p>The <code>Sequential</code> model is initialized.</p></li><li><p>The <code>Input</code> layer is added to define the input shape of the data. The actual shape would be dependent on the dataset.</p></li><li><p>The first hidden layer (<code>Layer 1</code> in the diagram) is added with 5 neurons, as visually indicated.</p></li><li><p>To capture the recurrence shown in the diagram, a <code>SimpleRNN</code><a href="https://www.tensorflow.org/api_docs/python/tf/keras/layers/SimpleRNN"> layer</a> is added. This layer can capture sequences in the data. The layer has 5 neurons, aligning with the number of circles in the diagram.</p></li><li><p>As the <code>SimpleRNN</code> produces 3D output data (batch_size, timesteps, features), we use the <code>Flatten</code> layer to reshape it for the next dense layer.</p></li><li><p>Another dense hidden layer (<code>Layer 2</code> in the diagram) with 5 neurons follows.</p></li><li><p>The final output layer is added. For simplicity, I assumed this is a regression task with a single output. If it's a classification task, you might want to use an activation like <code>sigmoid</code> or <code>softmax</code> and adjust the loss function accordingly during compilation.</p></li><li><p>The model is compiled using the Adam optimizer and a mean squared error loss, typically used for regression tasks.</p></li></ol><p>Understanding RNNs provides a way to design solutions around problems involving sequential data. The ability to handle temporal dynamics opens a new possibilities in application areas like real-time analytics, natural language processing, and many others. From an architectural standpoint, understanding the mechanisms of RNNs and their potential applications can be a cornerstone in building intelligent systems capable of interpreting and reacting to sequential or time-dependent data.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.tostring.ai/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">toString() is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h3><strong>Conclusion</strong></h3><p>Deep Learning is a paradigm where machines can learn from data at a depth which was previously unthought of. As a software architect, understanding and leveraging the intricacies of Neural Networks, CNNs, and RNNs opens up a frontier of possibilities in designing intelligent systems capable of self-learning, recognizing complex patterns, and making informed decisions over time.</p><p>As this episode comes to a close, the anticipation for the subsequent explorations into the heart of AI keeps the quest for knowledge aflame. The journey continues to be as exhilarating as it is enlightening, each step forward is a step into the future of software architecture, where machines not only compute but learn, adapt, and evolve.</p><p>As we close the chapter on Neural Networks, our next episode will delve into Large Language Models (LLMs) and the transformative world of Generative AI.</p><p><strong>Here's a brief on what to anticipate</strong>:</p><ol><li><p><strong>LLMs</strong>:</p><ul><li><p>Exploring Transformer Architecture and Attention Mechanisms.</p></li><li><p>Strategies of Pre-training and Fine-tuning.</p></li></ul></li><li><p><strong>Natural Language Processing</strong>:</p><ul><li><p>Insights into Text Mining and Sentiment Analysis.</p></li></ul></li><li><p><strong>Generative AI</strong>:</p><ul><li><p>Unveiling Generative Adversarial Networks (GANs) and Text Generation Techniques.</p></li></ul></li></ol><p>Stay tuned for the next episode in this AI Odyssey.</p><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-1" href="#footnote-anchor-1" class="footnote-number" contenteditable="false" target="_self">1</a><div class="footnote-content"><p>https://en.wikipedia.org/wiki/Feature_engineering</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-2" href="#footnote-anchor-2" class="footnote-number" contenteditable="false" target="_self">2</a><div class="footnote-content"><p>https://developer.ibm.com/articles/cc-cognitive-recurrent-neural-networks/</p><p></p></div></div>]]></content:encoded></item><item><title><![CDATA[E2: Journey into how Machines learn]]></title><description><![CDATA[Breaking Down ML]]></description><link>https://www.tostring.ai/p/e2-journey-into-how-machines-learn</link><guid isPermaLink="false">https://www.tostring.ai/p/e2-journey-into-how-machines-learn</guid><dc:creator><![CDATA[Marco Altea]]></dc:creator><pubDate>Fri, 20 Oct 2023 07:00:30 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!QZAh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F206d6575-bcc8-459d-a7b8-6b671f465932_1024x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3><strong>Introduction</strong></h3><p>As the digital landscape continuously change, introducing new paradigms, it&#8217;s a constant of a life for Software and Solution architect. The first chapter of my AI Odyssey went into Artificial Intelligence and Large Language Models, unravelling their foundational parts. My next stop is Machine Learning (ML). This realm is the fuel of the intelligence in AI.</p><p>Machine Learning, at its core, is about teaching machines to learn from data, to find patterns, and to make decisions (without awareness or consciousness). It's a foundational aspect in the broad field of AI, marking the initial steps towards equipping machines with a form of intelligence.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!QZAh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F206d6575-bcc8-459d-a7b8-6b671f465932_1024x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!QZAh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F206d6575-bcc8-459d-a7b8-6b671f465932_1024x1024.png 424w, https://substackcdn.com/image/fetch/$s_!QZAh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F206d6575-bcc8-459d-a7b8-6b671f465932_1024x1024.png 848w, https://substackcdn.com/image/fetch/$s_!QZAh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F206d6575-bcc8-459d-a7b8-6b671f465932_1024x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!QZAh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F206d6575-bcc8-459d-a7b8-6b671f465932_1024x1024.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!QZAh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F206d6575-bcc8-459d-a7b8-6b671f465932_1024x1024.png" width="572" height="572" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/206d6575-bcc8-459d-a7b8-6b671f465932_1024x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:572,&quot;bytes&quot;:2319644,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!QZAh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F206d6575-bcc8-459d-a7b8-6b671f465932_1024x1024.png 424w, https://substackcdn.com/image/fetch/$s_!QZAh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F206d6575-bcc8-459d-a7b8-6b671f465932_1024x1024.png 848w, https://substackcdn.com/image/fetch/$s_!QZAh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F206d6575-bcc8-459d-a7b8-6b671f465932_1024x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!QZAh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F206d6575-bcc8-459d-a7b8-6b671f465932_1024x1024.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>As an architect, exploring into ML means gaining a new perspective on the digital ecosystem. It's about understanding the mechanics that allow machines to exhibit human-like intelligence and using this knowledge to build strong, intelligent systems. Mastering ML  concepts goes beyond theory, it's a practical journey to improve my architectural skills, to create systems that are not only efficient but also have the ability to learn, evolve, and adapt to the constantly changing digital environment.</p><p>This journey into ML and DL extends beyond just algorithms and models. It's about how I, as architect, can utilize learning machines to drive innovation, solve real-world issues, and develop systems that adapt to the dynamic digital age. </p><h3><strong>Unveiling Machine Learning (ML)</strong></h3><p>Machine Learning (ML) sits at the heart of modern computational innovation. It's not about programming explicit instructions, but rather feeding a system a large amount of data and allowing it to learn the patterns<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a>. This premise is simple yet powerful. As an architect, I find it amazing how a machine can be trained to discern patterns and make predictions or decisions based on data. </p><p><em>This is the crux of ML and where our exploration begins.</em></p><p>The realm of ML is broad, encapsulating various learning paradigms. It's essential from my reading to grasp these to comprehend how machines learn and adapt. The primary paradigms are:</p><h4>Supervised Learning</h4><p>Supervised learning is a type of Machine Learning paradigm where the model is trained on labelled data. The data is provided with the answer key, and the algorithm iteratively makes predictions on the training data and is corrected by the teacher (In this context, the term "teacher" metaphorically refers to the provided labels or the ground truth in the dataset), allowing the model to learn over time.</p><h5>The Mathematics Behind it:</h5><p>In Supervised Learning, we typically have a dataset of input-output pairs, denoted as <br></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;(x \n1\n&#8203;\n ,y \n1\n&#8203;\n ),(x \n2\n&#8203;\n ,y \n2\n&#8203;\n ),...,(x \nn\n&#8203;\n ,y \nn\n&#8203;\n )&quot;,&quot;id&quot;:&quot;SYUADHRCNK&quot;}" data-component-name="LatexBlockToDOM"></div><p>where <em>x</em> represents the input data and <em>y</em> represents the labels.</p><p>One common algorithm used in Supervised Learning is Linear Regression. The goal is to find the parameters that minimize the difference between the predicted outputs and the true outputs. Mathematically, it&#8217;s defined as &#8220;loss function&#8221;, usually the Mean Squared Error (MSE) loss.</p><p>Linear Regression is like finding the straight line that best fits or represents the relationship between house size and price. The closer this line is to the actual prices, the better, a fantastic explanation of the Linear Regression you can find it here</p><div class="embedded-post-wrap" data-attrs="{&quot;id&quot;:54474544,&quot;url&quot;:&quot;https://bowtiedraptor.substack.com/p/understanding-linear-regression&quot;,&quot;publication_id&quot;:617941,&quot;publication_name&quot;:&quot;Data Science &amp; Machine Learning 101&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F5ef5c621-b4cc-4ad4-9f90-a15a8b49e008_657x657.png&quot;,&quot;title&quot;:&quot;Understanding Linear Regression&quot;,&quot;truncated_body_text&quot;:&quot;Required Readings Basic Data Wrangling Knowledge on Normal Distribution How to work with libraries Table of Contents: Where You Will Use this? What is Regression? What is Linear Regression (Multiple)? The Assumptions of Linear Regression Implementing Linear Regression&quot;,&quot;date&quot;:&quot;2022-05-18T13:18:46.509Z&quot;,&quot;like_count&quot;:4,&quot;comment_count&quot;:9,&quot;bylines&quot;:[{&quot;id&quot;:34373038,&quot;name&quot;:&quot;BowTied_Raptor&quot;,&quot;handle&quot;:&quot;bowtiedraptor&quot;,&quot;previous_name&quot;:null,&quot;photo_url&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/e856c8a7-1bde-42a0-87ac-de9a554f1b8d_400x400.jpeg&quot;,&quot;bio&quot;:&quot;Writes about Data Science/AI/ML&quot;,&quot;profile_set_up_at&quot;:&quot;2021-05-25T13:25:47.486Z&quot;,&quot;publicationUsers&quot;:[{&quot;id&quot;:550495,&quot;user_id&quot;:34373038,&quot;publication_id&quot;:617941,&quot;role&quot;:&quot;admin&quot;,&quot;public&quot;:true,&quot;is_primary&quot;:false,&quot;publication&quot;:{&quot;id&quot;:617941,&quot;name&quot;:&quot;Data Science &amp; Machine Learning 101&quot;,&quot;subdomain&quot;:&quot;bowtiedraptor&quot;,&quot;custom_domain&quot;:null,&quot;custom_domain_optional&quot;:false,&quot;hero_text&quot;:&quot;By Data Professionals, for Data Professionals.  \nThis is your centralized Website that has all of your data professional needs:\nWe cover:\n - Money Making Guides\n - Job Searching\n - Technical Skills (R, Python, SQL, MLOps, etc...)\n - Industry Knowledge&quot;,&quot;logo_url&quot;:&quot;https://bucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com/public/images/5ef5c621-b4cc-4ad4-9f90-a15a8b49e008_657x657.png&quot;,&quot;author_id&quot;:34373038,&quot;theme_var_background_pop&quot;:&quot;#FF0000&quot;,&quot;created_at&quot;:&quot;2021-12-17T05:13:30.963Z&quot;,&quot;rss_website_url&quot;:null,&quot;email_from_name&quot;:&quot;BT_Raptor - Data Science &amp; Machine Learning 101&quot;,&quot;copyright&quot;:&quot;BowTied_Raptor&quot;,&quot;founding_plan_name&quot;:null,&quot;community_enabled&quot;:true,&quot;invite_only&quot;:false,&quot;payments_state&quot;:&quot;enabled&quot;,&quot;language&quot;:null,&quot;explicit&quot;:false}}],&quot;twitter_screen_name&quot;:&quot;BowTied_Raptor&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:100}],&quot;utm_campaign&quot;:null,&quot;belowTheFold&quot;:true,&quot;type&quot;:&quot;newsletter&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="EmbeddedPostToDOM"><a class="embedded-post" native="true" href="https://bowtiedraptor.substack.com/p/understanding-linear-regression?utm_source=substack&amp;utm_campaign=post_embed&amp;utm_medium=web"><div class="embedded-post-header"><img class="embedded-post-publication-logo" src="https://substackcdn.com/image/fetch/$s_!PCBU!,w_56,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F5ef5c621-b4cc-4ad4-9f90-a15a8b49e008_657x657.png" loading="lazy"><span class="embedded-post-publication-name">Data Science &amp; Machine Learning 101</span></div><div class="embedded-post-title-wrapper"><div class="embedded-post-title">Understanding Linear Regression</div></div><div class="embedded-post-body">Required Readings Basic Data Wrangling Knowledge on Normal Distribution How to work with libraries Table of Contents: Where You Will Use this? What is Regression? What is Linear Regression (Multiple)? The Assumptions of Linear Regression Implementing Linear Regression&#8230;</div><div class="embedded-post-cta-wrapper"><span class="embedded-post-cta">Read more</span></div><div class="embedded-post-meta">4 years ago &#183; 4 likes &#183; 9 comments &#183; BowTied_Raptor</div></a></div><p>The Mean Squared Error (MSE) is a way to measure how well the line fits the data by averaging the squares of the differences (errors) between the predicted prices and the actual prices. Our goal is to adjust the line to minimize these errors, resulting in the best possible predictions.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.tostring.ai/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">toString() is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p><h5>Real-World Use Case: Predicting House Prices</h5><p>Let's consider a simplified scenario where I&#8217;m using a single feature (house size) to predict the house price. Our dataset consists of various house sizes and their corresponding price</p><p><strong>Collecting and Preparing Data</strong>:</p><ul><li><p>Gather a dataset of house sizes and their prices.</p></li><li><p>Split the data into a training set and a testing set.</p></li></ul><p><strong>Choosing a Model</strong>:</p><ul><li><p>Choose Linear Regression as our model since we're dealing with continuous data.</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!QWR7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b00ac9b-7e07-447e-af80-f072a93f582b_354x96.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!QWR7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b00ac9b-7e07-447e-af80-f072a93f582b_354x96.svg 424w, https://substackcdn.com/image/fetch/$s_!QWR7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b00ac9b-7e07-447e-af80-f072a93f582b_354x96.svg 848w, https://substackcdn.com/image/fetch/$s_!QWR7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b00ac9b-7e07-447e-af80-f072a93f582b_354x96.svg 1272w, https://substackcdn.com/image/fetch/$s_!QWR7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b00ac9b-7e07-447e-af80-f072a93f582b_354x96.svg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!QWR7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b00ac9b-7e07-447e-af80-f072a93f582b_354x96.svg" width="668" height="181.22252747252747" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4b00ac9b-7e07-447e-af80-f072a93f582b_354x96.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:395,&quot;width&quot;:1456,&quot;resizeWidth&quot;:668,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;\\mathrm{MSE} = \\frac{1}{n} \\sum_{i=1}^{n}(Y_{i}-\\hat{Y}_{i})^2&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="\mathrm{MSE} = \frac{1}{n} \sum_{i=1}^{n}(Y_{i}-\hat{Y}_{i})^2" title="\mathrm{MSE} = \frac{1}{n} \sum_{i=1}^{n}(Y_{i}-\hat{Y}_{i})^2" srcset="https://substackcdn.com/image/fetch/$s_!QWR7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b00ac9b-7e07-447e-af80-f072a93f582b_354x96.svg 424w, https://substackcdn.com/image/fetch/$s_!QWR7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b00ac9b-7e07-447e-af80-f072a93f582b_354x96.svg 848w, https://substackcdn.com/image/fetch/$s_!QWR7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b00ac9b-7e07-447e-af80-f072a93f582b_354x96.svg 1272w, https://substackcdn.com/image/fetch/$s_!QWR7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4b00ac9b-7e07-447e-af80-f072a93f582b_354x96.svg 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><ul><li><p><em>n</em>: The total number of data points (e.g., the number of houses you're considering).</p></li><li><p><em>yi</em>&#8203;: The actual value of the target variable for the <em>i</em>-th data point (e.g., the actual price of the <em>i</em>-th house).</p></li><li><p><em>y</em>^&#8203;<em>i</em>&#8203;: The predicted value of the target variable for the <em>i</em>-th data point (e.g., the price of the <em>i</em>-th house predicted by your model).</p></li><li><p>&#8721;: This symbol represents summation, meaning you'll add up the squared differences for all <em>n</em> data points.</p></li><li><p>(<em>yi</em>&#8203;&#8722;<em>y</em>^&#8203;<em>i</em>&#8203;)2: This part of the formula represents the squared difference between the actual value and the predicted value for each data point.</p></li></ul><p>In simpler terms, we are finding the average of the squared differences between the actual values and the predicted values, which gives you a measure of the accuracy of your model.</p><ol><li><p><strong>Training the Model</strong>:</p><ul><li><p>Use the training set to find the parameters that minimize the MSE loss.</p></li></ul></li><li><p><strong>Evaluating the Model</strong>:</p><ul><li><p>Use the testing set to evaluate the model's performance.</p></li><li><p>Measure the accuracy using metrics like R-squared or Root Mean Squared Error (RMSE).</p></li></ul></li><li><p><strong>Making Predictions</strong>:</p><ul><li><p>Now, given a new house size, use the learned parameters to predict its price.</p></li></ul></li><li><p><strong>Interpreting the Results</strong>:</p><ul><li><p>Analyze how well the model generalizes to new, unseen data.</p></li></ul></li></ol><p>This process shows how Supervised Learning algorithms like Linear Regression can be used to make predictions on continuous data, thus aiding in better decision-making and system design from an architectural standpoint.</p><h4>Unsupervised Learning</h4><p>Unsupervised Learning (UL) is another realm of Machine Learning, where the algorithms are left on their own to discover and present the interesting structures in the data. Unlike Supervised Learning, there are no labels here, no teacher to correct the model. The model learns through observation and finds structures in the data on its own.</p><p>One classic example of Unsupervised Learning is clustering.</p><p>Clustering<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a> is a technique used to group data points together based on certain similarities, without having prior knowledge of these groups. Imagine we have a dataset of different varieties of wines, each wine represents a data point with features like color, alcohol content, and sugar level. </p><pre><code>
data = {
    'Wine_Variety': ['Merlot', 'Chardonnay', 'Cabernet Sauvignon', 'Pinot Noir', 'Riesling', 'Sauvignon Blanc', 'Zinfandel'],
    'Color': ['Red', 'White', 'Red', 'Red', 'White', 'White', 'Red'],
    'Alcohol_Content': [13.5, 14.0, 13.8, 13.4, 11.5, 13.0, 14.5],  # in percentage
    'Sugar_Level': [1.5, 2.0, 1.2, 1.8, 2.5, 1.9, 2.2]  # scale from 1 to 3 (1-Dry, 2-Medium, 3-Sweet)
}</code></pre><p>The essence of clustering lies in finding inherent groupings within the data. The algorithm explores the structure of the data to identify clusters of wines that share similar characteristics, essentially uncovering hidden patterns. This way, even without pre-defined labels, the wines are categorized into different groups, making the data more understandable and ready for further analysis.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!P7Rr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F930481d5-4c58-4921-9679-a62f0ac37eb1_1024x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!P7Rr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F930481d5-4c58-4921-9679-a62f0ac37eb1_1024x1024.png 424w, https://substackcdn.com/image/fetch/$s_!P7Rr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F930481d5-4c58-4921-9679-a62f0ac37eb1_1024x1024.png 848w, https://substackcdn.com/image/fetch/$s_!P7Rr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F930481d5-4c58-4921-9679-a62f0ac37eb1_1024x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!P7Rr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F930481d5-4c58-4921-9679-a62f0ac37eb1_1024x1024.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!P7Rr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F930481d5-4c58-4921-9679-a62f0ac37eb1_1024x1024.png" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/930481d5-4c58-4921-9679-a62f0ac37eb1_1024x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1008314,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!P7Rr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F930481d5-4c58-4921-9679-a62f0ac37eb1_1024x1024.png 424w, https://substackcdn.com/image/fetch/$s_!P7Rr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F930481d5-4c58-4921-9679-a62f0ac37eb1_1024x1024.png 848w, https://substackcdn.com/image/fetch/$s_!P7Rr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F930481d5-4c58-4921-9679-a62f0ac37eb1_1024x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!P7Rr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F930481d5-4c58-4921-9679-a62f0ac37eb1_1024x1024.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Probably the most popular clustering algorithm used in unsupervised machine learning and data analysis is K-means. The algorithm categorizes the data into K number of clusters. It works iteratively to assign each data point to one of K groups based on the features that are provided</p><p><strong>Step 1:</strong> Initialization - Randomly initialize K centroids. </p><p><strong>Step 2:</strong> Assignment - Assign each data point to the nearest centroid, and it becomes a member of that cluster. </p><p><strong>Step 3:</strong> Update - Calculate the new centroid (mean) of each cluster. </p><p><strong>Step 4:</strong> Repeat Steps 2 and 3 until there are no changes in the assignments or a maximum number of iterations is reached.</p><pre><code># File path: /your_directory/wine_clustering.py

# Importing necessary libraries
from sklearn.cluster import KMeans
from sklearn.preprocessing import LabelEncoder
import pandas as pd

# Wine dataset
data = {
    'Wine_Variety': ['Merlot', 'Chardonnay', 'Cabernet Sauvignon', 'Pinot Noir', 'Riesling', 'Sauvignon Blanc', 'Zinfandel'],
    'Color': ['Red', 'White', 'Red', 'Red', 'White', 'White', 'Red'],
    'Alcohol_Content': [13.5, 14.0, 13.8, 13.4, 11.5, 13.0, 14.5],
    'Sugar_Level': [1.5, 2.0, 1.2, 1.8, 2.5, 1.9, 2.2]
}
df_wine = pd.DataFrame(data)

# Converting the 'Color' column to numerical values
le = LabelEncoder()
df_wine['Color'] = le.fit_transform(df_wine['Color'])  # Red:1, White:0

# Defining the number of clusters
num_clusters = 3

# Creating the KMeans object and fitting it to the wine data
kmeans = KMeans(n_clusters=num_clusters, random_state=0).fit(df_wine[['Color', 'Alcohol_Content', 'Sugar_Level']])

# The labels of the clusters
labels = kmeans.labels_

# The centroids of the clusters
centroids = kmeans.cluster_centers_

# Adding the cluster labels to the original DataFrame
df_wine['Cluster'] = labels

# Now df_wine has an additional column 'Cluster' indicating the cluster each wine
</code></pre><p>In this code</p><ol><li><p>The 'Color' column is converted to numerical values using the <code>LabelEncoder</code> from scikit-learn, where Red is encoded as 1 and White is encoded as 0.</p></li><li><p>The KMeans object is created and fitted to the wine data using the specified number of clusters (<code>num_clusters = 3</code>).</p></li><li><p>Cluster labels are generated and added to the original DataFrame in a new column called 'Cluster'.</p></li></ol><p>Output <a href="https://onecompiler.com/python/3zqxen5yy">Python One Compiler Code</a> :</p><pre><code>         Wine_Variety  Color  Alcohol_Content  Sugar_Level  Cluster
0              Merlot      0             13.5          1.5        1
1          Chardonnay      1             14.0          2.0        2
2  Cabernet Sauvignon      0             13.8          1.2        1
3          Pinot Noir      0             13.4          1.8        1
4            Riesling      1             11.5          2.5        0
5     Sauvignon Blanc      1             13.0          1.9        2
6           Zinfandel      0             14.5          2.2        1</code></pre><h5>The Mathematics Behind it:</h5><p>The objective of K-means is to minimize the variance within each cluster and maximize the variance between different clusters. Mathematically, it&#8217;s defined as an objective function J that we aim to minimize</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mH0u!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bbfa971-6177-4b84-ab97-72eec914539a_552x257.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mH0u!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bbfa971-6177-4b84-ab97-72eec914539a_552x257.png 424w, https://substackcdn.com/image/fetch/$s_!mH0u!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bbfa971-6177-4b84-ab97-72eec914539a_552x257.png 848w, https://substackcdn.com/image/fetch/$s_!mH0u!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bbfa971-6177-4b84-ab97-72eec914539a_552x257.png 1272w, https://substackcdn.com/image/fetch/$s_!mH0u!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bbfa971-6177-4b84-ab97-72eec914539a_552x257.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mH0u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bbfa971-6177-4b84-ab97-72eec914539a_552x257.png" width="552" height="257" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9bbfa971-6177-4b84-ab97-72eec914539a_552x257.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:257,&quot;width&quot;:552,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:16401,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!mH0u!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bbfa971-6177-4b84-ab97-72eec914539a_552x257.png 424w, https://substackcdn.com/image/fetch/$s_!mH0u!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bbfa971-6177-4b84-ab97-72eec914539a_552x257.png 848w, https://substackcdn.com/image/fetch/$s_!mH0u!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bbfa971-6177-4b84-ab97-72eec914539a_552x257.png 1272w, https://substackcdn.com/image/fetch/$s_!mH0u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bbfa971-6177-4b84-ab97-72eec914539a_552x257.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>Algorithm</strong></p><ol><li><p>Clusters the data into <em>k</em> groups where <em>k</em>&nbsp; is predefined.</p></li><li><p>Select <em>k</em> points at random as cluster centers.</p></li><li><p>Assign objects to their closest cluster center according to the <em>Euclidean distance</em> function.</p></li><li><p>Calculate the centroid or mean of all objects in each cluster.</p></li><li><p>Repeat steps 2, 3 and 4 until the same points are assigned to each cluster in consecutive rounds.</p></li></ol><p>As an architect, the potential of uncovering hidden structures in data, which could be pivotal in designing intelligent systems that can discover and adapt to the underlying patterns in the ever-evolving digital landscape.</p><h4>Reinforcement Learning</h4><p>Reinforcement Learning (RL) is a type of learning where an agent learns how to behave in an environment by performing certain actions and observing the rewards of those actions. It's much like learning by trial and error. In RL, the agent receives feedback in the form of rewards or penalties, which it uses to adjust its behavior to achieve the maximum cumulative reward</p><p>Imagine I&#8217;m developing a wine recommendation system (our agent) to suggest wines to customers based on their past preferences. Each successful recommendation, where a customer buys or positively rates a wine, rewards our system, while unsuccessful recommendations penalize it. Over time, our system learns to make better recommendations, maximizing customer satisfaction and, by extension, sales.</p><pre><code>import numpy as np

# Define the states, actions, rewards, and other parameters
states = [...]  # e.g., different customer profiles
actions = [...]  # e.g., different wine recommendations
rewards = np.zeros((len(states), len(actions)))  # initialize rewards matrix
q_values = np.zeros((len(states), len(actions)))  # initialize Q-values matrix
alpha = 0.1  # learning rate
gamma = 0.9  # discount factor

# Simulate the Q-learning process
for episode in range(1000):  # assume 1000 episodes
    state = np.random.choice(states)  # start with a random state
    while True:
        action = np.argmax(q_values[state, :] + np.random.randn(1, len(actions)) * (1./(episode+1)))  # choose an action
        reward = rewards[state, action]  # get the reward
        next_state = ...  # determine the next state
        # Update the Q-value
        q_values[state, action] = q_values[state, action] + alpha * (reward + gamma * np.max(q_values[next_state, :]) - q_values[state, action])
        state = next_state  # move to the next state
        if ...:  # check if the episode ends
            break
</code></pre><p>In this code snippet, I initialize our Q-values and simulate the Q-learning process over 1000 episodes to improve the wine recommendation system. With each episode, the Q-values are updated, and the recommendation policy improves, leading to better wine recommendations over time.</p><h5>The Mathematics Behind it:</h5><p>In RL, the agent uses a strategy known as a policy to decide its actions. One common approach is using a Q-Learning algorithm, which estimates the total expected rewards for each action in each state. The Q-value for a particular state-action pair is updated using the formula:<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-3" href="#footnote-3" target="_self">3</a></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!u5u7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bc7f167-576c-4eed-b968-1e05ba312aab_819x107.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!u5u7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bc7f167-576c-4eed-b968-1e05ba312aab_819x107.svg 424w, https://substackcdn.com/image/fetch/$s_!u5u7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bc7f167-576c-4eed-b968-1e05ba312aab_819x107.svg 848w, https://substackcdn.com/image/fetch/$s_!u5u7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bc7f167-576c-4eed-b968-1e05ba312aab_819x107.svg 1272w, https://substackcdn.com/image/fetch/$s_!u5u7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bc7f167-576c-4eed-b968-1e05ba312aab_819x107.svg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!u5u7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bc7f167-576c-4eed-b968-1e05ba312aab_819x107.svg" width="1456" height="190" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2bc7f167-576c-4eed-b968-1e05ba312aab_819x107.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:190,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;{\\displaystyle Q^{new}(s_{t},a_{t})\\leftarrow (1-\\underbrace {\\alpha } _{\\text{learning rate}})\\cdot \\underbrace {Q(s_{t},a_{t})} _{\\text{current value}}+\\underbrace {\\alpha } _{\\text{learning rate}}\\cdot {\\bigg (}\\underbrace {\\underbrace {r_{t}} _{\\text{reward}}+\\underbrace {\\gamma } _{\\text{discount factor}}\\cdot \\underbrace {\\max _{a}Q(s_{t+1},a)} _{\\text{estimate of optimal future value}}} _{\\text{new value (temporal difference target)}}{\\bigg )}}&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="{\displaystyle Q^{new}(s_{t},a_{t})\leftarrow (1-\underbrace {\alpha } _{\text{learning rate}})\cdot \underbrace {Q(s_{t},a_{t})} _{\text{current value}}+\underbrace {\alpha } _{\text{learning rate}}\cdot {\bigg (}\underbrace {\underbrace {r_{t}} _{\text{reward}}+\underbrace {\gamma } _{\text{discount factor}}\cdot \underbrace {\max _{a}Q(s_{t+1},a)} _{\text{estimate of optimal future value}}} _{\text{new value (temporal difference target)}}{\bigg )}}" title="{\displaystyle Q^{new}(s_{t},a_{t})\leftarrow (1-\underbrace {\alpha } _{\text{learning rate}})\cdot \underbrace {Q(s_{t},a_{t})} _{\text{current value}}+\underbrace {\alpha } _{\text{learning rate}}\cdot {\bigg (}\underbrace {\underbrace {r_{t}} _{\text{reward}}+\underbrace {\gamma } _{\text{discount factor}}\cdot \underbrace {\max _{a}Q(s_{t+1},a)} _{\text{estimate of optimal future value}}} _{\text{new value (temporal difference target)}}{\bigg )}}" srcset="https://substackcdn.com/image/fetch/$s_!u5u7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bc7f167-576c-4eed-b968-1e05ba312aab_819x107.svg 424w, https://substackcdn.com/image/fetch/$s_!u5u7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bc7f167-576c-4eed-b968-1e05ba312aab_819x107.svg 848w, https://substackcdn.com/image/fetch/$s_!u5u7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bc7f167-576c-4eed-b968-1e05ba312aab_819x107.svg 1272w, https://substackcdn.com/image/fetch/$s_!u5u7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2bc7f167-576c-4eed-b968-1e05ba312aab_819x107.svg 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><ul><li><p><em>s</em> and <em>s</em>&#8242; are the current and next states,</p></li><li><p><em>a</em> and <em>a</em>&#8242; are the current and potential future actions,</p></li><li><p><em>r</em> is the immediate reward,</p></li><li><p><em>&#945;</em> is the learning rate (how much we update our Q-value),</p></li><li><p><em>&#947;</em> is the discount factor (how much we value future rewards).</p></li></ul><p></p><h3><strong>Architectural Insights</strong></h3><p>In my journey, especially in commerce projects, platforms like Salesforce Commerce Cloud and SAP Commerce have been my playgrounds. These platforms leverage machine learning extensively to power their recommendation and promotion engines, providing a more tailored shopping experience. For instance, on Salesforce Commerce Cloud, the Einstein AI provides personalized recommendations by analyzing shopper data and behaviors using </p><ul><li><p><strong>Linear Regression</strong>: For predicting numerical values like sales forecasts.</p></li><li><p><strong>Classification Algorithms</strong>: For categorizing data into various classes. Algorithms like Random Forest, SVM, and Decision Trees might be employed.</p></li></ul><p>Designing systems around Machine Learning (ML) like this one calls for a understanding of scalability, efficiency, and deployment strategies.</p><p>Scalability isn&#8217;t just about handling increased load; it's about ensuring the ML models can be re-trained with larger datasets to improve accuracy over time. Efficiency touches on optimizing computational resources, minimizing latency, and ensuring the ML algorithms are fine-tuned for performance. Deployment strategies should be crafted to allow for smooth transitions, version control of models, and robust monitoring to catch anomalies early.</p><h4><strong>Training Scalability</strong></h4><p><strong>Distributed Training</strong><a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-4" href="#footnote-4" target="_self">4</a></p><p>This is a technique that partitions the data and model across multiple nodes to parallelize the computational workload. From an architectural standpoint, it leverages horizontal scaling, capitalizing on data parallelism and model parallelism techniques. By distributing the model's parameters and layers across various GPUs or even across multiple servers, we can achieve a significant reduction in training time. This enables organizations to expedite their time-to-market and handle large-scale, high-dimensional data efficiently. It's critical to integrate Distributed Training into the architecture from the get-go, ensuring seamless scalability while keeping an eye on network latency and data synchronization overhead.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nCfO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d19df82-f59a-4cda-9a40-cad8fb1ff0e0_1391x972.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nCfO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d19df82-f59a-4cda-9a40-cad8fb1ff0e0_1391x972.png 424w, https://substackcdn.com/image/fetch/$s_!nCfO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d19df82-f59a-4cda-9a40-cad8fb1ff0e0_1391x972.png 848w, https://substackcdn.com/image/fetch/$s_!nCfO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d19df82-f59a-4cda-9a40-cad8fb1ff0e0_1391x972.png 1272w, https://substackcdn.com/image/fetch/$s_!nCfO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d19df82-f59a-4cda-9a40-cad8fb1ff0e0_1391x972.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nCfO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d19df82-f59a-4cda-9a40-cad8fb1ff0e0_1391x972.png" width="1391" height="972" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2d19df82-f59a-4cda-9a40-cad8fb1ff0e0_1391x972.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:972,&quot;width&quot;:1391,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:109611,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!nCfO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d19df82-f59a-4cda-9a40-cad8fb1ff0e0_1391x972.png 424w, https://substackcdn.com/image/fetch/$s_!nCfO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d19df82-f59a-4cda-9a40-cad8fb1ff0e0_1391x972.png 848w, https://substackcdn.com/image/fetch/$s_!nCfO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d19df82-f59a-4cda-9a40-cad8fb1ff0e0_1391x972.png 1272w, https://substackcdn.com/image/fetch/$s_!nCfO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2d19df82-f59a-4cda-9a40-cad8fb1ff0e0_1391x972.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h4>Data Parallelism</h4><p>Data Parallelism involves distributing the dataset across multiple nodes (usually GPUs) and training a replica of the model on each node. Each node computes the gradients based on its subset of the data, which are then aggregated to update the model.</p><p><strong>How It Works</strong>:</p><ol><li><p>Partition the dataset into smaller batches.</p></li><li><p>Distribute the batches across multiple GPUs.</p></li><li><p>Each GPU computes the forward and backward pass using its subset of data.</p></li><li><p>Aggregate the gradients from all GPUs.</p></li><li><p>Update the model parameters.</p></li></ol><p><strong>Pros</strong>:</p><ul><li><p><strong>Simplicity</strong>: Easier to implement and manage.</p></li><li><p><strong>Batch Size</strong>: Allows for larger effective batch sizes, which can lead to a more stable and improved convergence.</p></li><li><p><strong>Scalability</strong>: Highly scalable as you can add more GPUs to handle larger datasets.</p></li></ul><p><strong>Cons</strong>:</p><ul><li><p><strong>Communication Overhead</strong>: Requires synchronization to aggregate gradients, which can be bandwidth-intensive.</p></li><li><p><strong>Limited by Dataset</strong>: If the dataset is too small, it may not benefit much from data parallelism.</p></li></ul><h4>Model Parallelism</h4><p><strong>Definition</strong>:<br>Model Parallelism involves splitting the model itself across multiple nodes. Each node is responsible for computing the forward and backward passes for its part of the model.</p><p><strong>How It Works</strong>:</p><ol><li><p>Divide the model layers or parameters across multiple GPUs.</p></li><li><p>Each GPU computes the forward and backward pass for its part of the model.</p></li><li><p>Communicate the intermediate outputs between GPUs as needed.</p></li></ol><p><strong>Pros</strong>:</p><ul><li><p><strong>Memory Efficiency</strong>: Allows for training of models that would not fit into the memory of a single GPU.</p></li><li><p><strong>Complex Models</strong>: Enables training of more complex models.</p></li></ul><p><strong>Cons</strong>:</p><ul><li><p><strong>Communication Overhead</strong>: Requires frequent communication between GPUs to share intermediate outputs.</p></li><li><p><strong>Implementation Complexity</strong>: More challenging to implement and manage compared to data parallelism.</p></li></ul><h4><strong>Data Parallelism vs Model Parallelism</strong></h4><ol><li><p><strong>Ease of Implementation</strong>:</p><ul><li><p><strong>Data Parallelism</strong>: Generally easier to implement.</p></li><li><p><strong>Model Parallelism</strong>: Requires more intricate handling of model layers and states.</p></li></ul></li><li><p><strong>Memory Utilization</strong>:</p><ul><li><p><strong>Data Parallelism</strong>: Can be limited by the memory of a single GPU for storing the model.</p></li><li><p><strong>Model Parallelism</strong>: More efficient in using memory for very large models.</p></li></ul></li><li><p><strong>Communication Overhead</strong>:</p><ul><li><p><strong>Data Parallelism</strong>: Involves less frequent but larger data transfers (aggregating gradients).</p></li><li><p><strong>Model Parallelism</strong>: Requires more frequent but smaller data transfers (intermediate layer outputs).</p></li></ul></li><li><p><strong>Scalability</strong>:</p><ul><li><p><strong>Data Parallelism</strong>: Scales well with larger datasets.</p></li><li><p><strong>Model Parallelism</strong>: Scales well with model complexity.</p></li></ul></li><li><p><strong>Use-Cases</strong>:</p><ul><li><p><strong>Data Parallelism</strong>: Effective for large-scale but simpler models.</p></li><li><p><strong>Model Parallelism</strong>: Necessary for complex models with many parameters that won't fit into a single GPU's memory.</p></li></ul></li></ol><ol><li><p><strong>Strategy: Data Sharding</strong></p><ul><li><p><em>Pros:</em> Efficient handling of large datasets, reduces memory load.</p></li><li><p><em>Cons:</em> Requires consistent data distribution, potential loss of inter-shard information.</p><p></p></li></ul></li></ol><h3><strong>Conclusion</strong></h3><p>In this episode, I've broken down the core concepts of Machine Learning, crucial for any architect aiming to leverage AI within system designs. The discussion around design considerations for ML systems, focusing on scalability, is fundamental for the architectural planning of robust, intelligent systems. The next episode will further this exploration into Deep Learning, extending our toolkit and understanding for designing AI-driven architectures.</p><p>Engage and  with this learning journey; share your insights or ask questions in the comments below. If you found value in this exploration, share it within your network. Stay tuned for the next episode where we'll delve deeper into Deep Learning, further broadening our architectural horizon in the AI realm. Subscribe now to stay updated!</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.tostring.ai/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">toString() is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-1" href="#footnote-anchor-1" class="footnote-number" contenteditable="false" target="_self">1</a><div class="footnote-content"><p>https://www.microsoft.com/en-us/research/uploads/prod/2006/01/Bishop-Pattern-Recognition-and-Machine-Learning-2006.pdf</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-2" href="#footnote-anchor-2" class="footnote-number" contenteditable="false" target="_self">2</a><div class="footnote-content"><p>https://developers.google.com/machine-learning/clustering/clustering-algorithms</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-3" href="#footnote-anchor-3" class="footnote-number" contenteditable="false" target="_self">3</a><div class="footnote-content"><p>https://static1.squarespace.com/static/5ff2adbe3fe4fe33db902812/t/6009dd9fa7bc363aa822d2c7/1611259312432/ISLR+Seventh+Printing.pdf</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-4" href="#footnote-anchor-4" class="footnote-number" contenteditable="false" target="_self">4</a><div class="footnote-content"><p>https://storage.googleapis.com/pub-tools-public-publication-data/pdf/40565.pdf</p><p></p></div></div>]]></content:encoded></item><item><title><![CDATA[E1 - From Code to Cognition: My AI Exploration Begins]]></title><description><![CDATA[Introduction to AI and LLM - history and basic concepts]]></description><link>https://www.tostring.ai/p/e1-from-code-to-cognition-my-ai-exploration</link><guid isPermaLink="false">https://www.tostring.ai/p/e1-from-code-to-cognition-my-ai-exploration</guid><dc:creator><![CDATA[Marco Altea]]></dc:creator><pubDate>Fri, 13 Oct 2023 08:40:55 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F751132e6-7ab7-4720-9984-a1a5787a7df3_1024x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3>1. Introduction</h3><p>In a world where the term "Artificial Intelligence" (AI) has become ubiquitous, it's crucial to ground my understanding in its foundational aspects. John McCarthy, a luminary in the domain from Stanford University, delved deep into the basic questions surrounding AI in his paper <a href="https://www-formal.stanford.edu/jmc/whatisai.pdf">"WHAT IS ARTIFICIAL INTELLIGENCE?"</a>. At its core, AI revolves around the science and engineering of creating intelligent machines, especially intelligent computer programs. Human intelligence, on the other hand, is often characterized by our ability to perceive, reason, learn from experience, and adapt to varying situations. People often think AI and human intelligence are the same thing. But even if AI might seem like it's thinking like us, it's actually pretty different in its own ways. That's an important thing to remember! </p><p>While AI may often engage in <strong>simulations of human intelligence</strong>, it's essential to understand that a simulation, by definition, can mimic or act like the real thing but is not the genuine article itself. Thus, AI's reflection of human-like intelligence is a crafted representation, not a genuine replication. Understanding intelligence itself is complex, described by McCarthy as the computational aspect of the ability to achieve goals. The realm of AI research is vast and multifaceted, navigating beyond mere simulations of human intelligence</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.tostring.ai/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">toString() is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h3>2. The Evolution of Artificial Intelligence</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!haIj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6360024-26aa-4e18-8219-09e7518e155e_1813x900.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!haIj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6360024-26aa-4e18-8219-09e7518e155e_1813x900.png 424w, https://substackcdn.com/image/fetch/$s_!haIj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6360024-26aa-4e18-8219-09e7518e155e_1813x900.png 848w, https://substackcdn.com/image/fetch/$s_!haIj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6360024-26aa-4e18-8219-09e7518e155e_1813x900.png 1272w, https://substackcdn.com/image/fetch/$s_!haIj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6360024-26aa-4e18-8219-09e7518e155e_1813x900.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!haIj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6360024-26aa-4e18-8219-09e7518e155e_1813x900.png" width="1456" height="723" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f6360024-26aa-4e18-8219-09e7518e155e_1813x900.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:723,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:478002,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!haIj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6360024-26aa-4e18-8219-09e7518e155e_1813x900.png 424w, https://substackcdn.com/image/fetch/$s_!haIj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6360024-26aa-4e18-8219-09e7518e155e_1813x900.png 848w, https://substackcdn.com/image/fetch/$s_!haIj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6360024-26aa-4e18-8219-09e7518e155e_1813x900.png 1272w, https://substackcdn.com/image/fetch/$s_!haIj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6360024-26aa-4e18-8219-09e7518e155e_1813x900.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>1950s</strong>: The initiation of AI was marked by Alan Turing's <strong>Turing Test</strong>, a theoretical benchmark for gauging machine intelligence. The core idea was simple: if a machine could converse indistinguishably from a human, it could be termed 'intelligent'. Concurrently, John McCarthy's <strong>Lisp</strong> emerged as a pioneering language for AI due to its symbolic processing capabilities, representing a shift from mere arithmetic computations to symbolic reasoning.</p><p><strong>1960s</strong>: The advent of <strong>rule-based systems</strong> became evident. Joseph Weizenbaum's ELIZA utilized <strong>pattern-matching algorithms</strong> to replicate human-like interactions, marking an early exploration into Natural Language Processing (NLP). Though rudimentary, it demonstrated that machines could, at a basic level, "understand" and generate human language.</p><p><strong>1970s</strong>: Expert systems, epitomized by <strong>MYCIN</strong>, brought forth a new paradigm. MYCIN, using a <strong>backward chaining algorithm</strong>, diagnosed bacterial infections. It marked an evolutionary step by employing rule-based logic on domain-specific knowledge, showcasing the potential of machines to emulate specialized human decision-making. Concurrently, the Stanford Cart, using basic <strong>computer vision algorithms</strong>, created the promise of autonomous movement.</p><p><strong>1980s</strong>: <strong>Expert systems</strong> further matured. They encapsulated human expertise using a combination of  <strong>knowledge bases and inference engines</strong>. Yet, their rigidity was evident; they were only as good as the rules fed into them. This decade also marked a resurgence of interest in <strong>neural networks</strong>, especially with the Backpropagation algorithm, which allowed the optimization of weights in multi-layered networks, paving the way for deep learning.</p><p><strong>1990s</strong>: <strong>IBM's Deep Blue</strong>, while a hardware marvel, utilized <strong>alpha-beta pruning</strong> and advanced <strong>evaluation heuristics</strong> to search through vast chess positions. This marked an evolutionary leap in combinatorial optimization. Simultaneously, Sony's <strong>AIBO</strong>, a blend of <strong> sensors and real-time processing</strong>, showcased AI's potential in robotics.</p><p><strong>2000s</strong>: The <strong>DARPA Grand Challenge</strong> was emblematic of advancements in sensor fusion and real-time decision-making. Machine learning began to shift from purely supervised paradigms to semi-supervised and unsupervised methods. Techniques like <strong>Random Forests, SVMs</strong>, and <strong>Boosting</strong> became predominant, laying the groundwork for more complex architectures.</p><p><strong>2010s</strong>: The term <strong>deep learning</strong> became synonymous with AI. DeepMind's AlphaGo combined <strong>deep convolutional networks</strong> with <strong>Monte Carlo Tree Search</strong>, marking a significant advancement in reinforcement learning. Architectures evolved from simple feed-forward networks to more complex structures like <strong>RNNs</strong>, <strong>LSTMs</strong>, and <strong>Transformers</strong>. OpenAI's GPT-2's transformer architecture showcased the potential of <strong>attention mechanisms</strong>, setting new benchmarks in NLP.</p><p><strong>2020s</strong>: OpenAI's <strong>GPT-3</strong> brought <strong>zero-shot and few-shot learning</strong> into the spotlight, emphasizing the capability of models to generalize from limited data. This evolution underscores a trend: from handcrafted rules to data-driven decision-making, from shallow models to deep, intricate architectures.</p><h3>3. Basic Terminology and Applications</h3><p><strong>Artificial Intelligence (AI):</strong> AI refers to the capability of a machine to <strong>mimic</strong> intelligent human behavior. It's a broad field that encompasses everything from robotic process automation to actual robotics.</p><p><strong>Machine Learning (ML):</strong>  ML allows computers to learn from data. Instead of being explicitly programmed to perform a task, the machine uses data and algorithms to learn how to perform the task by itself.</p><p><strong>Deep Learning (DL):</strong> Deep Learning is a subfield of ML. It's primarily concerned with algorithms inspired by the structure and function of the brain called artificial neural networks. These algorithms are known for processing vast amounts of data, including unstructured data like images and text.</p><p><strong>Large Language Models (LLM):</strong> LLMs, like GPT-4, are a type of Deep Learning model designed to understand and generate human-like text based on the patterns they've learned from massive datasets. They are particularly known for their ability to generate coherent and contextually relevant sentences over long passages.</p><h3><strong>Real-world applications: How AI touches our everyday lives:</strong></h3><ol><li><p><strong>Personal Assistants:</strong> Virtual personal assistants, like Siri, Alexa, and Google Assistant, use AI to interpret and respond to user prompts.</p></li><li><p><strong>Recommendation Systems:</strong> From Netflix movie suggestions to Amazon product recommendations, these systems use ML algorithms to tailor content to individual user preferences.</p></li><li><p><strong>Autonomous Vehicles:</strong> Cars like those from Tesla use a combination of sensors and AI algorithms to drive themselves.</p></li><li><p><strong>Medical Diagnosis:</strong> Advanced AI tools can help in diagnosing diseases and conditions from medical imagery with impressive accuracy.</p></li><li><p><strong>Language Translation:</strong> Platforms like Google Translate employ Deep Learning models to provide real-time translation across dozens of languages.</p></li><li><p><strong>Financial Trading:</strong> AI-powered systems analyze market conditions in real-time to make trading decisions at speeds far surpassing human capabilities.</p></li><li><p><strong>Chatbots and Customer Service:</strong> Many websites now have chatbot assistants that can answer user queries in real-time, improving user experience and efficiency.</p></li><li><p><strong>Smart Home Devices:</strong> Devices like Nest or Ring use AI to learn user behaviors and preferences, adjusting settings automatically for user convenience.</p></li></ol><p>These applications highlight the extensive reach of AI technologies in various industries and our daily lives.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!AEvw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F751132e6-7ab7-4720-9984-a1a5787a7df3_1024x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!AEvw!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F751132e6-7ab7-4720-9984-a1a5787a7df3_1024x1024.png 424w, https://substackcdn.com/image/fetch/$s_!AEvw!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F751132e6-7ab7-4720-9984-a1a5787a7df3_1024x1024.png 848w, https://substackcdn.com/image/fetch/$s_!AEvw!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F751132e6-7ab7-4720-9984-a1a5787a7df3_1024x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!AEvw!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F751132e6-7ab7-4720-9984-a1a5787a7df3_1024x1024.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!AEvw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F751132e6-7ab7-4720-9984-a1a5787a7df3_1024x1024.png" width="512" height="512" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/751132e6-7ab7-4720-9984-a1a5787a7df3_1024x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:512,&quot;bytes&quot;:1177179,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!AEvw!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F751132e6-7ab7-4720-9984-a1a5787a7df3_1024x1024.png 424w, https://substackcdn.com/image/fetch/$s_!AEvw!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F751132e6-7ab7-4720-9984-a1a5787a7df3_1024x1024.png 848w, https://substackcdn.com/image/fetch/$s_!AEvw!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F751132e6-7ab7-4720-9984-a1a5787a7df3_1024x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!AEvw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F751132e6-7ab7-4720-9984-a1a5787a7df3_1024x1024.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h3>4. The Backbone of AI: Mathematical Foundations</h3><p>At the foundation of Artificial Intelligence, there are mathematical principles. These pillars grant AI its strength and capabilities.</p><h4>4.1. Linear Algebra</h4><p><em><strong>Definition:</strong></em><br>Linear algebra is a branch of mathematics concerning linear equations, linear functions, and their representations in vector spaces and through matrices. Fundamentally, it deals with vectors, matrices, determinants, and systems of linear equations.</p><p><em><strong>Relevance to AI:</strong></em><br>In AI, and particularly in deep learning, linear algebra is crucial. Data, whether they are images, sound, or numerical values, are often represented as vectors or matrices. When processing this data, especially in neural networks, computations are performed using the principles of linear algebra. These computations include operations like matrix multiplication, finding eigenvectors/eigenvalues, and more. The efficiency and scalability of these operations are essential for training large neural networks on vast datasets.</p><p><em><strong>Use case example:</strong></em><br>Imagine training a neural network to recognize characters from popular culture. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ut4v!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdff733c6-f476-4bcd-87b4-1b6240231e62_1200x1191.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ut4v!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdff733c6-f476-4bcd-87b4-1b6240231e62_1200x1191.jpeg 424w, https://substackcdn.com/image/fetch/$s_!ut4v!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdff733c6-f476-4bcd-87b4-1b6240231e62_1200x1191.jpeg 848w, https://substackcdn.com/image/fetch/$s_!ut4v!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdff733c6-f476-4bcd-87b4-1b6240231e62_1200x1191.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!ut4v!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdff733c6-f476-4bcd-87b4-1b6240231e62_1200x1191.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ut4v!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdff733c6-f476-4bcd-87b4-1b6240231e62_1200x1191.jpeg" width="438" height="434.715" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dff733c6-f476-4bcd-87b4-1b6240231e62_1200x1191.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1191,&quot;width&quot;:1200,&quot;resizeWidth&quot;:438,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Obi-Wan show reveals return of Darth Vader in first-look photo&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Obi-Wan show reveals return of Darth Vader in first-look photo" title="Obi-Wan show reveals return of Darth Vader in first-look photo" srcset="https://substackcdn.com/image/fetch/$s_!ut4v!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdff733c6-f476-4bcd-87b4-1b6240231e62_1200x1191.jpeg 424w, https://substackcdn.com/image/fetch/$s_!ut4v!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdff733c6-f476-4bcd-87b4-1b6240231e62_1200x1191.jpeg 848w, https://substackcdn.com/image/fetch/$s_!ut4v!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdff733c6-f476-4bcd-87b4-1b6240231e62_1200x1191.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!ut4v!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdff733c6-f476-4bcd-87b4-1b6240231e62_1200x1191.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="captioned-button-wrap" data-attrs="{&quot;url&quot;:&quot;https://www.tostring.ai/p/e1-from-code-to-cognition-my-ai-exploration?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="CaptionedButtonToDOM"><div class="preamble"><p class="cta-caption">Thank you for reading toString(). This post is public so feel free to share it.</p></div><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.tostring.ai/p/e1-from-code-to-cognition-my-ai-exploration?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.tostring.ai/p/e1-from-code-to-cognition-my-ai-exploration?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p></div><p>The image provided, for instance, represents Darth Vader from the Star Wars series. An image can be thought of as a matrix where each entry in the matrix represents the pixel intensity (and possibly color channels). When this image is fed into a neural network, the matrix undergoes various linear algebraic operations, like matrix multiplications, to transform the raw pixel values into a form that the network can use to recognize and classify the character. Through multiple layers and operations, the network might learn to pick up on unique features such as the distinct helmet shape, the pattern of the grille on the mouthpiece, or the silhouette of the cape, which all signal that this could be an image of Darth Vader.</p><p>Imagine the image of Darth Vader being represented as a matrix. </p><pre><code># Example Python Code for Matrix-Vector Multiplication related to the Darth Vader image

# Let's assume a simplified 3x3 grayscale image of Darth Vader 
# (in reality, the image would have thousands or millions of pixels, 
# and possibly three channels for RGB)

# Simplified pixel matrix of the image (just an illustrative example)
darth_vader_image = [
    [230, 235, 232],   # top row of the image
    [50, 40, 48],     # middle row representing the darker mask region
    [220, 225, 222]   # bottom row of the image
]

# A sample weight matrix from the first layer of a neural network
weights = [
    [0.1, 0.2, 0.1],
    [0.2, 0.5, 0.2],
    [0.1, 0.2, 0.1]
]

# Multiplying the image matrix with the weight matrix to get the transformed matrix
transformed_matrix = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

for i in range(3):
    for j in range(3):
        transformed_matrix[i][j] = darth_vader_image[i][j] * weights[i][j]

print(transformed_matrix)
</code></pre><p>In the context of our Darth Vader image example:</p><ul><li><p>The <code>weights</code> matrix represents the first layer of a hypothetical neural network.</p></li><li><p>This matrix is used to transform the input image matrix (Darth Vader's image in this case) into another matrix that highlights or de-emphasizes certain features. This transformed matrix is then passed to subsequent layers of the network.</p></li></ul><p>In my illustrative example, I simply multiplied the image pixel values by these weights. In a real-world scenario, after this multiplication, a bias might be added, and then an activation function (like ReLU, sigmoid, etc.) would be applied to introduce non-linearity into the model.</p><p>Linear algebra, at its core, provides the mathematical foundation for representing and manipulating data in AI. In our example of identifying characters like Darth Vader, the image data is converted into matrices, and operations on these matrices, like matrix-vector multiplications, are performed. The weights, which are learned through training, determine the importance of specific features. By efficiently handling vast amounts of data and ensuring accurate computations using linear algebra principles, I can train models to recognize intricate patterns and make intelligent decisions. In the context of our character identification task, understanding linear algebra is paramount, ensuring that complex visual data can be distilled into meaningful insights, making it an indispensable tool in the realm of AI.</p><h4>4.2. Probability and Statistics</h4><p><em><strong>Definition</strong></em><strong>:</strong> Probability and Statistics are intertwined fields of mathematics. While probability provides a measure of the likelihood of a specific event occurring, statistics focuses on collecting, analyzing, interpreting, and presenting data in a meaningful manner.</p><p><em><strong>Relevance to AI:</strong></em> At its core, AI is essentially a statistical machine. Given vast amounts of data, AI models, especially those under machine learning, employ probability and statistics to recognize patterns, make predictions, and draw inferences. When an AI system provides a prediction, it often accompanies it with a confidence score, which is a direct application of probability. Furthermore, during the model training phase, statistical methods help determine the reliability and validity of the model's performance, ensuring that the model's decisions are not just mere coincidences but are statistically significant.</p><h4>4.3. Calculus</h4><p><em><strong>Definition:</strong></em> Calculus is a branch of mathematics that studies continuous change, primarily through derivatives and integrals. It's broken down into two main categories: Differential Calculus, which examines rates of change and the slopes of curves, and Integral Calculus, which looks at areas under curves.</p><p><em><strong>Relevance to AI:</strong></em> Calculus plays a foundational role in AI, especially in training algorithms like neural networks. For example, the backpropagation algorithm used in training neural networks involves calculating gradients (derivatives) of a loss function with respect to the model's parameters. These gradients guide how the parameters should be adjusted during the training process. The goal is to minimize the loss function, and this optimization is achieved using techniques from calculus.</p><p><em><strong>Use Case Example:</strong></em> Imagine training a simple neural network to recognize handwritten digits. During training, the network makes predictions, and the difference between its predictions and the actual labels is computed using a loss function. To minimize this loss, the network needs to adjust its weights and biases, which is done by understanding the gradient (or direction and magnitude of change) of the loss function with respect to these parameters.</p><pre><code>def compute_gradient(loss_function, weights):
    """
    Calculate the gradient of the loss function with respect to the network's weights.
    This is a simplified example; in practice, tools like TensorFlow or PyTorch handle these computations.
    """
    h = 1e-5  # a small value
    gradient = []
    
    for i, weight in enumerate(weights):
        weights[i] = weight + h
        loss1 = loss_function(weights)
        
        weights[i] = weight - h
        loss2 = loss_function(weights)
        
        gradient.append((loss1 - loss2) / (2 * h))
        weights[i] = weight  # reset the weight
        
    return gradient
</code></pre><h3>5. Introduction to <strong>Neural Network</strong></h3><p><strong>Neural Network </strong>- A neural network is a computational model inspired by the structure of biological neural systems. It comprises interconnected processing elements, called neurons, that process information using a connectionist approach to computation. The operations of a neural network are organized into layers. Each neuron in a layer receives input from the previous layer, processes it through a mathematical transformation involving weights, biases, and an activation function, and then sends the output to neurons in the next layer. Neural networks are trained using a set of input-output pairs, adjusting the weights via optimization techniques such as gradient descent to minimize the error between predicted and actual outputs.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ScT5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69d7eb1c-0ca2-49a0-8f4e-5a104b08dcb1_1120x631.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ScT5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69d7eb1c-0ca2-49a0-8f4e-5a104b08dcb1_1120x631.png 424w, https://substackcdn.com/image/fetch/$s_!ScT5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69d7eb1c-0ca2-49a0-8f4e-5a104b08dcb1_1120x631.png 848w, https://substackcdn.com/image/fetch/$s_!ScT5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69d7eb1c-0ca2-49a0-8f4e-5a104b08dcb1_1120x631.png 1272w, https://substackcdn.com/image/fetch/$s_!ScT5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69d7eb1c-0ca2-49a0-8f4e-5a104b08dcb1_1120x631.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ScT5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69d7eb1c-0ca2-49a0-8f4e-5a104b08dcb1_1120x631.png" width="1120" height="631" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/69d7eb1c-0ca2-49a0-8f4e-5a104b08dcb1_1120x631.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:631,&quot;width&quot;:1120,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Deep learning neural network&quot;,&quot;title&quot;:&quot;Deep learning neural network&quot;,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Deep learning neural network" title="Deep learning neural network" srcset="https://substackcdn.com/image/fetch/$s_!ScT5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69d7eb1c-0ca2-49a0-8f4e-5a104b08dcb1_1120x631.png 424w, https://substackcdn.com/image/fetch/$s_!ScT5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69d7eb1c-0ca2-49a0-8f4e-5a104b08dcb1_1120x631.png 848w, https://substackcdn.com/image/fetch/$s_!ScT5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69d7eb1c-0ca2-49a0-8f4e-5a104b08dcb1_1120x631.png 1272w, https://substackcdn.com/image/fetch/$s_!ScT5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69d7eb1c-0ca2-49a0-8f4e-5a104b08dcb1_1120x631.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"><a href="https://www.ibm.com/topics/neural-networks">Source</a></figcaption></figure></div><p><strong>Example: Handwritten Digit Classification</strong></p><p>Imagine I'm trying to build a system that recognizes handwritten digits from 0 to 9. For this, I'll use the <a href="https://www.tensorflow.org/datasets/catalog/mnist">MNIST</a> dataset, which contains grayscale images of handwritten digits.</p><p>Given the deep neural network visual:</p><ul><li><p>The <strong>Input layer</strong> will have as many neurons as there are pixels in each image. MNIST images are 28x28 pixels, so I&#8217;d have 784 input neurons.</p></li><li><p>The <strong>Multiple Hidden layers</strong> can vary, but for simplicity, let's assume I have two hidden layers with 128 neurons each.</p></li><li><p>The <strong>Output layer</strong> will have 10 neurons, each representing a digit from 0 to 9. The neuron with the highest activation predicts the digit.</p></li></ul><h4>Code Sample:</h4><p>Let's build a neural network model using TensorFlow/Keras:</p><pre><code><code>import tensorflow as tf

# Define the model
model = tf.keras.models.Sequential()

# Input Layer: Flatten the 28x28 images to a 784x1 vector
model.add(tf.keras.layers.Flatten(input_shape=(28, 28)))

# First Hidden Layer: 128 neurons with ReLU activation
model.add(tf.keras.layers.Dense(128, activation='relu'))

# Second Hidden Layer: 128 neurons with ReLU activation
model.add(tf.keras.layers.Dense(128, activation='relu'))

# Output Layer: 10 neurons (for digits 0-9) with softmax activation 
# to get probabilities for each class
model.add(tf.keras.layers.Dense(10, activation='softmax'))

# Compile the model
model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])</code></code></pre><h3><strong>How the Neural Network Works with this Code:</strong></h3><ol><li><p><strong>Input Layer</strong>: The <code>Flatten</code> layer takes in the 28x28 pixel images and transforms them into a single row of 784 pixels.</p></li><li><p><strong>Hidden Layers</strong>: The <code>Dense</code> layers with 128 neurons each, and <code>relu</code> activation function introduce non-linearity to the model. This allows the neural network to learn complex patterns.</p></li><li><p><strong>Output Layer</strong>: The final <code>Dense</code> layer has 10 neurons, one for each digit. I use the <code>softmax</code> activation because it turns logits (raw output scores) into probabilities for each class.</p></li></ol><p>When trained on the MNIST dataset, this neural network will learn to recognize patterns of handwritten digits. The weights between the neurons adjust during training to minimize the difference between the predicted and actual digits.</p><h3><strong>Visualization and Understanding:</strong></h3><p>Using the provided image:</p><ul><li><p><strong>Input Layer (Blue circles on the left)</strong>: Represents the pixels of an image.</p></li><li><p><strong>Hidden Layers (Green circles in the middle)</strong>: These are the layers where the magic happens. Here, our network learns patterns, features, and characteristics about the images.</p></li><li><p><strong>Output Layer (Blue circles on the right)</strong>: The final decisions are made here. The neuron with the highest value gives the predicted digit.</p></li></ul><p>Each arrow connecting the circles represents a weight. During training, the network adjusts these weights based on the error of its predictions.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.tostring.ai/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">toString() is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h3><strong>6. Introduction to Large Language Models (LLM): A Deep Dive for Architects</strong></h3><p>As we transition into an era where text-driven interfaces take precedence, Large Language Models (LLMs) have become instrumental in creating a more contextual and interactive user experience. For software architects, understanding the underlying design and structure of LLMs is paramount. Here, I delve into the intricate architecture of these models and discuss their applicability in real-world systems.</p><h3><strong>LLM Architecture: A Closer Look</strong></h3><p>The image offers a schematic representation of the transformer architecture, the foundational design behind modern Large Language Models (LLMs) such as GPT-3. This architecture was introduced in the landmark paper <a href="https://arxiv.org/pdf/1706.03762.pdf">"Attention Is All You Need"</a> by Ashish Vaswani and his team at Google</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Vz6t!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63dfe2b8-b5d4-479b-b9f7-f5fe19656a7a_409x595.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Vz6t!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63dfe2b8-b5d4-479b-b9f7-f5fe19656a7a_409x595.webp 424w, https://substackcdn.com/image/fetch/$s_!Vz6t!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63dfe2b8-b5d4-479b-b9f7-f5fe19656a7a_409x595.webp 848w, https://substackcdn.com/image/fetch/$s_!Vz6t!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63dfe2b8-b5d4-479b-b9f7-f5fe19656a7a_409x595.webp 1272w, https://substackcdn.com/image/fetch/$s_!Vz6t!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63dfe2b8-b5d4-479b-b9f7-f5fe19656a7a_409x595.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Vz6t!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63dfe2b8-b5d4-479b-b9f7-f5fe19656a7a_409x595.webp" width="409" height="595" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/63dfe2b8-b5d4-479b-b9f7-f5fe19656a7a_409x595.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:595,&quot;width&quot;:409,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Vz6t!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63dfe2b8-b5d4-479b-b9f7-f5fe19656a7a_409x595.webp 424w, https://substackcdn.com/image/fetch/$s_!Vz6t!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63dfe2b8-b5d4-479b-b9f7-f5fe19656a7a_409x595.webp 848w, https://substackcdn.com/image/fetch/$s_!Vz6t!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63dfe2b8-b5d4-479b-b9f7-f5fe19656a7a_409x595.webp 1272w, https://substackcdn.com/image/fetch/$s_!Vz6t!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63dfe2b8-b5d4-479b-b9f7-f5fe19656a7a_409x595.webp 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h4>1. <strong>Inputs and Embeddings:</strong></h4><p>The bottom-most section of the diagram showcases how raw inputs are processed:</p><ul><li><p><strong>Input Embedding</strong>: Textual data, in tokenized format, is transformed into dense vectors using embeddings. This acts as the initial representation of the data which the transformer will process.</p></li><li><p><strong>Positional Encoding</strong>: Since transformers don't inherently process data in sequence, positional encodings are added to ensure that the model retains information about the position of each token in a sequence.</p></li></ul><h4>2. <strong>Multi-Head Attention Mechanism:</strong></h4><p>A distinguishing feature of the transformer:</p><ul><li><p><strong>Multi-Head Attention</strong>: Allows the model to focus on different parts of the input data simultaneously. It computes attention weights for different "heads", enabling the model to capture various aspects of the data.</p></li><li><p><strong>Masked Multi-Head Attention</strong>: Used primarily in the decoder section (as seen in the right-hand portion of the diagram). This ensures that while predicting a particular token, the model doesn't have access to future tokens.</p></li></ul><h4>3. <strong>Feed Forward Neural Networks:</strong></h4><p>Contained within each block of the architecture:</p><ul><li><p>Every layer in the transformer contains a feed-forward neural network, which operates independently on each position.</p></li></ul><h4>4. <strong>Add &amp; Norm:</strong></h4><p>A crucial component for the model's stability and performance:</p><ul><li><p>After each main operation (attention or feed-forward), the output goes through an "Add &amp; Norm" step which includes residual connections and layer normalization. This aids in preventing the vanishing gradient problem and ensures smoother training.</p></li></ul><h4>5. <strong>Linear Layers and Softmax:</strong></h4><p>The final steps before producing an output:</p><ul><li><p><strong>Linear Layer</strong>: It transforms the output from the decoder's final layer.</p></li><li><p><strong>Softmax</strong>: Converts the raw output scores (logits) from the linear layer into probabilities. This is especially crucial when the model is used for tasks like classification.</p></li></ul><h4>6. <strong>Stacking:</strong></h4><p>As indicated by "N x" in the diagram, the transformer stacks these blocks multiple times, which allows it to learn more complex relationships and dependencies in the data.</p><h4>Use case example</h4><p>The Transformer architecture introduced in the paper revolutionized natural language processing tasks by utilizing self-attention mechanisms. The Language Model (LLM) based on this architecture can be thought of as a neural network model designed to understand and generate human language. It's particularly suited for tasks like machine translation, text summarization, and language generation.</p><p><em><strong>1. Tokenization and Input Embeddings:</strong></em></p><ul><li><p>The input sentence is first tokenized into subword or word-level tokens. Each token is represented as a vector using pre-trained embeddings (e.g., Word2Vec, GloVe).</p></li><li><p>These embeddings are then transformed into input embeddings for the model. In the original Transformer, these embeddings have a fixed dimension.</p></li></ul><p><em><strong>2. Positional Encoding:</strong></em></p><ul><li><p>Since the Transformer doesn't inherently understand the order of words in a sequence, positional encoding is added to the input embeddings.</p></li><li><p>Positional encoding vectors are calculated based on the position of each token in the input sequence and added element-wise to the embeddings.</p></li><li><p>This gives the model information about the relative positions of tokens in the sequence.</p></li></ul><p><em><strong>3. Encoder:</strong></em></p><p>a. <strong>Self-Attention Mechanism:</strong> - The input embeddings with positional encodings are passed through multiple self-attention layers in parallel. - In each self-attention layer, queries, keys, and values are computed from the input embeddings. - Attention scores are calculated by taking the dot product of queries and keys, followed by scaling and applying a softmax function. - These attention scores determine how much each token should attend to other tokens in the same input sequence. - The weighted sum of values based on attention scores produces the attended representation for each token. - This mechanism allows the model to capture dependencies and relationships between words, emphasizing important connections.</p><p>b. <strong>Multi-Head Attention:</strong> - Multiple self-attention heads operate in parallel in each layer. - Each head has its own set of learned parameters, allowing it to focus on different aspects of the input. - The outputs of all heads are concatenated and linearly transformed to create the final attention output for that layer.</p><p>c. <strong>Residual Connection and Layer Normalization:</strong> - After each self-attention sub-layer, there is a residual connection that bypasses the sub-layer and a layer normalization step. - This helps in preventing the vanishing gradient problem during training and ensures smooth information flow through the network.</p><p>d. <strong>Feed-Forward Neural Network (FFN):</strong> - After self-attention, the output is passed through a feed-forward neural network. - The FFN consists of two linear transformations followed by an activation function (commonly ReLU) and another linear transformation. - This network captures complex, non-linear relationships between tokens.</p><p>e. <strong>Residual Connection and Layer Normalization (Again):</strong> - Similar to self-attention sub-layers, after the FFN, there is another residual connection and layer normalization.</p><p><strong>4. Decoder:</strong></p><ul><li><p>The decoder architecture closely resembles the encoder but with some differences. It also includes the following components:</p></li></ul><p>a. <strong>Masked Self-Attention Mechanism:</strong> - In the decoder, self-attention is applied with a masking mechanism that prevents the model from attending to future positions in the output sequence.</p><p>b. <strong>Encoder-Decoder Attention:</strong> - In addition to the masked self-attention, the decoder also attends to the output of the encoder's final layer. - This allows the decoder to consider the entire input sequence while generating the output.</p><p>c. <strong>Residual Connections and Layer Normalization:</strong> - Similar to the encoder, residual connections and layer normalization are applied after each sub-layer in the decoder.</p><p><strong>5. Output Generation:</strong></p><ul><li><p>The final output from the decoder is passed through a linear layer followed by a softmax activation function.</p></li><li><p>This produces a probability distribution over the vocabulary for each position in the output sequence.</p></li><li><p>During training, the model is optimized to generate the correct target sequence by minimizing a suitable loss function like cross-entropy.</p></li></ul><p><strong>Information Flow:</strong></p><ul><li><p>Information flows through the Transformer architecture in a hierarchical manner, with each layer capturing different levels of abstraction and dependencies between tokens.</p></li><li><p>Self-attention mechanisms determine how much each token attends to other tokens in the input sequence, allowing the model to weigh their importance.</p></li><li><p>The residual connections and layer normalization ensure that information can flow smoothly through the network without vanishing gradients.</p></li><li><p>During decoding, the model attends to both the encoder's output and its own previously generated output to produce contextually relevant translations.</p><p></p></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.tostring.ai/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">toString() is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h3>6. Conclusion</h3><p>In the first post of "AI Odyssey" series, I went into the foundational aspects of Artificial Intelligence (AI) and Large Language Models (LLMs). I explored the basics of AI, the building blocks of neural networks, and took a look at the architecture that underpins modern LLMs, inspired by the groundbreaking paper "Attention Is All You Need."</p><p>As I go further into the world of AI, my next chapter will navigate the terrain of Deep Learning and Machine Learning Concepts. I&#8217;ll dissect various algorithms, dissect their strengths and weaknesses, and shed light on their practical applications.</p><p>It's important to note that this effort is a dynamic journey, fueled by my ongoing exploration and learning  of AI. The purpose of this blog post series is twofold: to solidify my understanding of these complex subjects and, just as importantly, to share this knowledge with you.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.tostring.ai/p/e1-from-code-to-cognition-my-ai-exploration/comments&quot;,&quot;text&quot;:&quot;Leave a comment&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.tostring.ai/p/e1-from-code-to-cognition-my-ai-exploration/comments"><span>Leave a comment</span></a></p>]]></content:encoded></item></channel></rss>