<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Evan Shareef</title>
    <description>The latest articles on DEV Community by Evan Shareef (@evan_shareef).</description>
    <link>https://dev.to/evan_shareef</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2097853%2F0a45b34e-eecc-461f-97ad-ba764a2ef6f6.jpg</url>
      <title>DEV Community: Evan Shareef</title>
      <link>https://dev.to/evan_shareef</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/evan_shareef"/>
    <language>en</language>
    <item>
      <title>গ্রেডিয়েন্ট ডিসেন্ট কী এবং এটা কিভাবে কাজ করে? (understanding physical significance)</title>
      <dc:creator>Evan Shareef</dc:creator>
      <pubDate>Sat, 14 Jun 2025 13:52:49 +0000</pubDate>
      <link>https://dev.to/evan_shareef/greddiyentt-ddisentt-kii-ebn-ettaa-kibhaabe-kaaj-kre-understanding-physical-significance-4abd</link>
      <guid>https://dev.to/evan_shareef/greddiyentt-ddisentt-kii-ebn-ettaa-kibhaabe-kaaj-kre-understanding-physical-significance-4abd</guid>
      <description>&lt;p&gt;প্রথমত আমাদের জানতে হবে মেশিন লার্নিং মডেল বেইজ লেভেলে আসলে ট্রেনিং এর পর কী পায়? একটি মডেল আসলে ইকুয়েশন সল্ভ করা শিখে। বেসিক লেভেলে; ওকে কিছু ডেটা দেওয়া হয়। এই ডেটা গুলো থেকে ওর কাজ হয় একটা ইকুয়েশন বানানো। এমন একটা ইকুয়েশন বানানো যেখানে নতুন ডাটা দিলে ও সঠিক প্রেডিকশন দিতে পারে। &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;মডেল ট্রেনিং বলতে আসলে ওকে ইকুয়েশন, সেগুলোর weight বসাতে শেখানো হয়।&lt;/strong&gt; ট্রেনিং ডাটা থেকে ও আসলে বোঝার চেষ্টা করে যে স্পেসিফিক প্রব্লেম ডোমেইনের ডেটাগুলোকে কোন ইকুয়েশনে বসানো যায়।&lt;/p&gt;

&lt;p&gt;উদাহরনের খাতিরে ধরে নেই একটা মডেলকে এসির দাম প্রেডিক্ট করার জন্য ট্রেইন করা হচ্ছে। ওকে দেওয়া ডেটা দেখতে অনেকটা এরকমঃ&lt;/p&gt;

&lt;p&gt;===================&lt;/p&gt;

&lt;h1&gt;
  
  
  মাস, গড় তাপমাত্রা, এসির দাম 
&lt;/h1&gt;

&lt;p&gt;এখন এই ডেটা দিয়ে ট্রেইন করানো হলে হয়তোবা মডেলটা এমন একটা ইকুয়েশন বানাবেঃ &lt;/p&gt;

&lt;p&gt;=========================&lt;/p&gt;

&lt;h1&gt;
  
  
  এসির দাম = মাস * ০.৮ + তাপমাত্রা * ২০
&lt;/h1&gt;

&lt;p&gt;এখন এই প্রশ্ন হতে পারে, ০.৮ , ২০ এই ভ্যালু গুলো কী র‍্যান্ডম হবে? না! মূলত একটা মডেল এসব ভ্যালুকেই শিখে ফেলে। প্রতিটা ফিচারের জন্য কোন সংখ্যা গুণ করা যায় এই জিনিসটাই হচ্ছে একটা মডেলের লার্নিং। এখন থেকে এই মডেলকে নতুন কোনো ভ্যালু দিলে ও শুধু মাস ও তাপমাত্রাকে ইনপুট হিসেবে নিয়ে একটা weighted sum বের করবে। এটাই হবে এসির দাম।&lt;/p&gt;

&lt;p&gt;অর্থাৎ একটা মডেল তাহলে শুধু ওয়েট বের করা + ইকুয়েশন বের করা শেখে। এটাই ওর কাজ। এখন এই যে ও ওয়েট কত হবে এটা ক্যালকুলেট করা শেখে ; এই ভ্যালু ও কিভাবে বের করে? মূলত ট্রেনিং এর সময় ও এই ইকুয়েশনের ভ্যালু বের কর দেখে যে এরর রেট কত। ট্রেনিং এর সময় ওর কাছে তো একচুয়াল ভ্যালু আছেই। ও তখন ইকুয়েশনে বের করা ভ্যালুর সাথে একচুয়াল ভ্যালুর ডিফারেন্স বের করে দেখে। এখন আমরা চাই এই এরর ফাংশনের ভ্যালু কমাতে। যেই পয়েন্টে গিয়ে এই ভ্যালু সবচেয়ে মিনিমাম হবে ওইটাই আমাদের জন্য অপটিমাল পয়েন্ট। &lt;/p&gt;

&lt;p&gt;এখন ট্রেনিং চলাকালীন কিভাবে বুঝবো যে আমি ঠিক পথে যাচ্ছি কিনা? এটা বোঝার জন্য আমরা ফাংশনের ডেরিভেটিভস ইউজ করি। ডেরিভেটিভস আমাদের কী দেয়? ডেরিভেটিভস আমাদের বলে যে আমাদের ইকুয়েশন ঠিক পথে আগাচ্ছে কিনা এবং কী পরিমাণে আগাচ্ছে। এই ডিরেকশন দেখে মডেল বুঝতে পারে যে ওয়েটের ভ্যালু কী পরিমাণ কমাতে বা বাড়াতে হবে। &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;তাহলে মডেল শেখে কী?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;কোন ফিচারের জন্য কী ওয়েট দিতে হবে — সেটাই শেখে ।&lt;/li&gt;
&lt;li&gt;শেখার সময় মডেল প্রতিবার একটা প্রেডিকশন করে, এবং দেখে সেটা আসল রেজাল্ট থেকে কতটা ভুল&lt;/li&gt;
&lt;li&gt;এই ভুলের পরিমাণকে বলে error বা loss&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;লক্ষ্য থাকে: এই error কে ধাপে ধাপে কমানো&lt;/p&gt;

&lt;p&gt;তখন আসে Gradient Descent ! প্রতিবার প্রেডিকশনের পর, মডেল error দেখে। এরপর derivative (gradient) ব্যবহার করে বুঝতে চায়: "আমি যে পথে weight বদলাচ্ছি, সেটা কি error কমাচ্ছে? নাকি বাড়াচ্ছে? কোন দিকে গেলে error কমবে?"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ডেরিভেটিভ কী দেয়?&lt;/strong&gt;&lt;br&gt;
Derivative বলে দেয়: বর্তমানে যে অবস্থানে আছি, ওখানে error কতটা পরিবর্তন হচ্ছে । এই পরিবর্তনের দিকটাই হচ্ছে gradient — যেটা মডেলকে বলে কোন দিকে গেলে error কমবে সেই দিকেই একটু একটু করে ওয়েট পরিবর্তন করা হয় — এই পুরো প্রক্রিয়াটার নামই Gradient Descent&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Gradient descent হলো এমন একটা অ্যালগরিদম যা derivative দেখে weight কীভাবে পরিবর্তন করলে cost function কমবে — সেটা নির্ধারণ করে।&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  MachineLearning #ML
&lt;/h1&gt;

</description>
      <category>machinelearning</category>
      <category>ai</category>
      <category>gradient</category>
      <category>datascience</category>
    </item>
    <item>
      <title>How I reduced code size by about 85%</title>
      <dc:creator>Evan Shareef</dc:creator>
      <pubDate>Thu, 19 Sep 2024 15:43:58 +0000</pubDate>
      <link>https://dev.to/evan_shareef/how-i-reduced-code-size-by-about-85-3aa4</link>
      <guid>https://dev.to/evan_shareef/how-i-reduced-code-size-by-about-85-3aa4</guid>
      <description>&lt;p&gt;&lt;strong&gt;Background Story&lt;/strong&gt;&lt;br&gt;
I worked on transforming a legacy desktop application into a system with centralized server-based data storage. This involved changing the existing measurement data storage system and implementing comprehensive safety and validation checks to enhance data integrity and security in the new environment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;&lt;br&gt;
There were many steps involved in each data synchronization process. It required some of the API calls, some verification steps, and so on. Here's the old code snippet:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd6q6j61hfjyeghcdwx7v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd6q6j61hfjyeghcdwx7v.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The code looks messy, Right? I had the same feeling when I saw my code. The repeated checks to see if the previous process succeeded made me realize something was wrong. I find myself doing the same thing repeatedly, and I know it will be repeated everywhere else. Is there a solution for this?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Approach to Solution&lt;/strong&gt;&lt;br&gt;
The first thing that needs improvement is the repetitive if/else ladder. Specifically, the additional error checking after each step makes the code larger and harder to follow. Anyone reading the whole method needs to understand what's going on, and those if/else conditions would distract them. It's also cumbersome for the coder (me) to repeatedly write out those checks.&lt;/p&gt;

&lt;p&gt;What if I could pass each step to a method that would check if the step is successful or not, and then decide whether to proceed to the next step? This means I need a mechanism that can receive each step and make a decision about whether to execute the next steps or not.&lt;/p&gt;

&lt;p&gt;I can create a method that receives the previous result and the next step. It can then decide, based on the previous result, whether the next step needs to be executed or not. If the previous result indicates failure, the method won't execute the received step; instead, it will return the error result. This way, the error message can propagate without executing any further steps. There are &lt;strong&gt;two paths for my code to take&lt;/strong&gt;: it can either go to the &lt;strong&gt;error line&lt;/strong&gt; or the &lt;strong&gt;success line&lt;/strong&gt;, but the code will be executed as expected. So for my convenience, I will refer to this method as "GatewayMethod" so that I can use the "GatewayMethod" keyword to clarify which thing played as this method in my codebase.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Updated Code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh3i05sno0zgi0x9wy9fd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh3i05sno0zgi0x9wy9fd.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;See the difference? I shared a simplified version of my task as a demo, but in reality, the actual codebase involves larger functions, which made it difficult for code reviewers to read. However, with this new approach, error handling has become more streamlined, and the code is easier to manage from a centralized location. In the future, if additional conditional checks need to be introduced, I can simply modify the BindAsync() method. The core method responsible for chaining all the necessary steps is BindAsync(). Below is the code snippet for BindAsync().&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Gateway Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcaqfeqialx5j8htkllwy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcaqfeqialx5j8htkllwy.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
This approach is called &lt;strong&gt;Railway Oriented Programming&lt;/strong&gt;. Your code will be executed based on the result, but it can take either of the railway lines.&lt;/p&gt;

</description>
      <category>monads</category>
      <category>cleancode</category>
      <category>designpatterns</category>
      <category>dotnet</category>
    </item>
  </channel>
</rss>
