<?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:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Salih Talha Akgün on Medium]]></title>
        <description><![CDATA[Stories by Salih Talha Akgün on Medium]]></description>
        <link>https://medium.com/@akgunsalihtalha?source=rss-d425f5d2c34d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4hgbq16nzoaiOlQyNrPUYg.jpeg</url>
            <title>Stories by Salih Talha Akgün on Medium</title>
            <link>https://medium.com/@akgunsalihtalha?source=rss-d425f5d2c34d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 02:55:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@akgunsalihtalha/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[First Impressions of Codex: Automated Bug Fixing and Feature Creation on GitHub with ChatGPT]]></title>
            <link>https://akgunsalihtalha.medium.com/first-impressions-of-codex-automated-bug-fixing-and-feature-creation-on-github-with-chatgpt-e128ab5c5c92?source=rss-d425f5d2c34d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e128ab5c5c92</guid>
            <category><![CDATA[codice]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[chatgpt]]></category>
            <dc:creator><![CDATA[Salih Talha Akgün]]></dc:creator>
            <pubDate>Tue, 17 Jun 2025 07:49:14 GMT</pubDate>
            <atom:updated>2025-06-17T07:49:14.201Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post, I will examine a new ChatGPT-based technology called <strong>Codex</strong>, which allows you to connect your repositories and interact with it through prompts. Codex has its own runtime environment and can suggest code, run tests, generate pull requests, and respond intelligently to your queries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*m1ed-LMhIOjHw45c" /></figure><p>Our examination will cover several aspects. I’ll walk through a set of tasks and explain how well Codex performs in meeting specific objectives. For testing, I’ll use a repository that doesn’t have many open pull requests but contains a large issue archive — nearly two thousand entries — some of which are linked to the commits that resolved them.</p><p>I will use short, one- or two-sentence prompts without providing detailed explanations or step-by-step instructions.Explaining the Codebase</p><p>It definitely responds slowly, often taking around 3–4 minutes. However, when it comes to explaining the codebase, it starts off well by covering the main concepts. That said, it tends to miss some important components and lacks depth, making the explanations less comprehensive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4ClwxseKA3tFQq2u" /></figure><h4><strong>Requesting a Solution in the Codebase</strong></h4><p>We have a Kafka service and a corresponding Kafka consumer service in our codebase. I asked Codex for a solution to the issue of leftover Kafka log files after a re-run — an issue that prevents Kafka from starting properly. However, Codex simply suggested deleting the old logs, which I had already mentioned in the prompt. I was expecting a more robust or automated solution.</p><p>After a follow-up prompt requesting an automatic solution, the only suggestion it gave was to create a .sh file—which I still had to run manually. This response took a minute and a half.</p><h4><strong>Explaining How to Send a Request to an Endpoint</strong></h4><p>Codex correctly identified that a particular endpoint was running behind an Nginx proxy and advised sending requests to the appropriate Nginx location. That part was handled well.<br>However, when I asked how to send a request to a set-session endpoint—where a prerequisite step involves adding user IDs to a list of expected login attempts—Codex failed to mention that required step. After a follow-up question, it did identify the prerequisite, but it took about a minute and a half to respond.</p><h4><strong>Code Cleaning</strong></h4><p>I requested some general code cleanup. Codex provided useful suggestions, including improvements I hadn’t noticed myself. I initially doubted it would fully understand the logic, but it handled it surprisingly well.</p><h4><strong>Adding or Expanding a Service</strong></h4><p>I asked Codex to expand an existing service, which required adding related code to other services as well. While it did a solid job on the primary service, it ignored the parts of the system that also needed updating.<br>Later, I requested a new full-fledged service to be added to the application. Codex heavily borrowed from existing services, which was helpful to a point — but it copied too much. I expected it to at least adapt or improve on parts like internal prompt texts, rather than reusing them word by word.</p><h3>Summary</h3><p>Based on my research and experiments, I observed that Codex does not provide sufficiently comprehensive answers when given just one or two sentences. Considering the 3–4 minute response time, I can’t say it’s very efficient. It also doesn’t go out of its way to suggest new ideas for your codebase. If it did, I’m sure it could offer many valuable insights.</p><p>To test whether it had a holistic understanding of the codebase, I asked for general suggestions. Unfortunately, the response was quite superficial — definitely not at the level I would expect from a senior developer. It recommended cleaning up TODOs and expanding the documentation. I was hoping for more deep suggestions, like introducing a new tool or technology that could benefit the entire project.</p><h4><strong>Pros:</strong></h4><p>I believe Codex can get the job done — sometimes even suggesting things you hadn’t noticed before, which sets it apart from other AI systems that don’t have full access to your repository. However, you need to be very specific in your prompts — and patient with the response times.</p><h4><strong>Cons:</strong></h4><p>The downside is that it doesn’t always align with what you have in mind, and it rarely goes beyond the most obvious or easiest solution. At least, that was my experience.</p><p>I hope this post helps you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e128ab5c5c92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Protein Language Models (PLMs): Tasks and Architectural Differences [2/3]]]></title>
            <link>https://akgunsalihtalha.medium.com/protein-language-models-plms-tasks-and-architectural-differences-2-3-083099ceb42f?source=rss-d425f5d2c34d------2</link>
            <guid isPermaLink="false">https://medium.com/p/083099ceb42f</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[protein]]></category>
            <category><![CDATA[language-model]]></category>
            <category><![CDATA[bert]]></category>
            <dc:creator><![CDATA[Salih Talha Akgün]]></dc:creator>
            <pubDate>Sat, 18 May 2024 15:53:22 GMT</pubDate>
            <atom:updated>2024-05-18T16:05:24.897Z</atom:updated>
            <content:encoded><![CDATA[<p>Today, I will introduce some of the protein language models and compare them to the large language models used in natural language processing (NLP). But first, let’s start with some well-known tasks in the field of protein research.</p><h3>Well Known Tasks in the Protein Research</h3><h4>3D Folding</h4><p>This fascinating field of AI first captured my attention with the AlphaFold model by Google’s DeepMind [1], which aims to solve the protein-folding problem. Proteins are formed from sequences of amino acids, but it is essential to remember that they exist in a three-dimensional world. After their initial formation, these amino acid sequences undergo a complex folding process. For example, proper folding enables proteins to form tissues and perform their biological functions effectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/0*MGM6l4eN8O4-U6wz.png" /><figcaption><a href="https://en.wikipedia.org/wiki/Protein_folding">https://en.wikipedia.org/wiki/Protein_folding</a></figcaption></figure><p>The sequence of amino acids in a protein ultimately dictates how it will fold, and the resulting structure determines the protein’s function. However, the exact nature of this resulting structure remains a mystery that we are actively working to unravel. AlphaFold represents a significant milestone in our efforts to predict the structure of proteins accurately.</p><h4>Token Prediction, Text Classification, Text Generation</h4><p>Another task involves predicting segments of the protein sequence. This task falls under the umbrella of Protein Language Model tasks. Through this type of training, we can expect our model to develop a reasonable “understanding” of proteins, enabling us to tackle more specific downstream tasks, such as text classification, where we classify proteins into their respective families.</p><p>Protein families are groups of proteins sharing similar evolutionary backgrounds or functionalities.</p><p>Additionally, we can focus on generating entire protein sequences. I believe this area holds the most intrigue. However, given the infinite number of possible proteins, identifying functional ones and understanding their roles proves challenging.</p><p>It’s akin to encountering a hypothetical alien language. We might discern individual “words” or vocalisations, but without grasping their grammar and meanings, constructing coherent “sentences” remains elusive.</p><h4>Evolution</h4><p>What I find truly fascinating is that using Protein Language Models (PLMs), we can identify the evolutionary trajectory within a conceptual protein landscape. Life on our planet shares certain proteins, yet even proteins with identical functions may exhibit slight variations across different species. These variations can lead to enhanced efficiency for one species over another. Such advantageous changes are likely to persist and proliferate in future generations. PLMs enable us to identify the directionality of these evolutionary changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/0*4VplNJ80oGZDYg3i.PNG" /><figcaption><a href="https://evolocity.readthedocs.io/en/latest/index.html">https://evolocity.readthedocs.io/en/latest/index.html</a></figcaption></figure><blockquote><a href="https://evolocity.readthedocs.io/en/latest/index.html">Evolocity</a> implements evolutionary velocity (evo-velocity), which models a protein sequence landscape as an evolutionary “vector field” by using the local evolutionary predictions enabled by language models to enable global evolutionary insight.</blockquote><h4>Multiple Sequence Alignment</h4><p>Some early studies on protein sequence data include Multiple Sequence Alignments (MSA). MSA is highly effective in detecting mutations and continues to be used as a scientific metric to determine protein families or superfamilies. I find it analogous to studies conducted with Regex or TF-IDF in the natural language processing realm. Although based on alignment or statistics, their purpose is to capture features of the given data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*JQ-dqzLi9ufw2xMP.png" /><figcaption><a href="https://blog.bionl.ai/multiple-sequence-alignment-introduction/">https://blog.bionl.ai/multiple-sequence-alignment-introduction/</a></figcaption></figure><h3>BERTology Meets Biology</h3><p>BERTology met Biology<strong>[2]</strong> and transformer based models are trained with protein data for Masked Language Modelling. Notably, training was conducted solely on sequence data, yet the resulting models exhibited a remarkable ability to discern crucial features such as binding sites. This revelation underscores the potential of leveraging language models in deciphering complex biological phenomena.</p><p>Below are some details and comparisons.</p><h4>1. Training Data:</h4><p>While Natural Language Models Trained on large corpora of text data from diverse sources (e.g., books, articles, web pages) on the other hand, Protein Language Models are trained on large databases of protein sequences such as UniProt or Pfam. These databases include sequences derived from various organisms and can include evolutionary information (e.g., multiple sequence alignments).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*R7bsibab7n1NyXqc" /><figcaption>Comparison of Number of Datapoints for Natural Language and Protein Datasets</figcaption></figure><p>But in comparison, protein datasets are much more smaller than natural language datasets. Assuming each protein sequence is a sentence, and each 30 words is sentence, when compared, largest protein sequence dataset available is 40 times smaller than natural language dataset used for ChatGPT training.</p><p>Also there are some other information to feed into the model such as structural information or how the genes function. For example, there is a Gene Ontology database<strong>[3]</strong>.</p><h4>2. Input Representation:</h4><p>Natural Language Models typically use word embeddings or token embeddings where each word or sub-word token is represented by a vector but in PLMs we use amino acid embeddings where each amino acid (or sometimes a group of amino acids) is represented by a vector. These embeddings capture the biochemical properties and evolutionary information of amino acids.</p><h4>3. Model Architecture:</h4><p>NLP models commonly use architectures like Transformer (e.g., BERT, GPT), which rely on self-attention mechanisms to capture dependencies across tokens.</p><p>Protein Language Models adopt Transformer architectures with modifications to handle the specific properties of protein sequences. For example:</p><ul><li><strong>Evoformer (AlphaFold)[1]</strong>: Combines attention mechanisms with additional blocks tailored to capture spatial and evolutionary information. For example, it will make use of a protein database to create a MSA representation and pairwise feature matrix.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6YkTeek_gkWfmjm0pTk7hg.png" /><figcaption><a href="https://deepmind.google/discover/blog/alphafold-a-solution-to-a-50-year-old-grand-challenge-in-biology/">https://deepmind.google/discover/blog/alphafold-a-solution-to-a-50-year-old-grand-challenge-in-biology/</a></figcaption></figure><ul><li><strong>Rostlab’s ProtBERT:</strong> Uses BERT-like architecture but is trained on protein sequences. An important difference is that ProtBERT won’t use Next Sentence Prediction and treats each sequence as a document.</li></ul><p>There is much more to explore and discuss regarding Protein Language Models, but for now, let’s conclude here. I will continue writing about this topic in the future.</p><p>I hope you’ve enjoyed this blog. If you’re interested in delving deeper into this topic, I encourage you to check out the referenced papers for more detailed information.</p><p>Feel free to share your thoughts and ideas with me — I’d love to continue the conversation.</p><p>Thank you for reading!</p><h3>References:</h3><p>[1] Highly accurate protein structure prediction with AlphaFold: <a href="https://www.nature.com/articles/s41586-021-03819-2">https://www.nature.com/articles/s41586-021-03819-2</a></p><p>[2] Bertology meets Biology: Interpreting Attention in Protein Language Models: <a href="https://arxiv.org/abs/2006.15222">https://arxiv.org/abs/2006.15222</a></p><p>[3] Gene Ontology Database: <a href="https://geneontology.org/">https://geneontology.org/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=083099ceb42f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Protein Language Models (PLMs): Modelling Natural vs Protein Languages [1/3]]]></title>
            <link>https://akgunsalihtalha.medium.com/protein-language-models-plms-modelling-natural-vs-protein-languages-1-3-4ab36b72d33f?source=rss-d425f5d2c34d------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ab36b72d33f</guid>
            <category><![CDATA[language]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[bioinformatics]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[protein]]></category>
            <dc:creator><![CDATA[Salih Talha Akgün]]></dc:creator>
            <pubDate>Sun, 21 Apr 2024 08:59:52 GMT</pubDate>
            <atom:updated>2024-04-21T08:59:52.969Z</atom:updated>
            <content:encoded><![CDATA[<p>Proteins are main building blocks of our bodies, with variety of tasks. Understanding how they form and function can enable us, humans, to do impactful projects in several important areas such as medicine and environment. Protein language model are trying to model the proteins and focuses on several tasks similar to natural language models.</p><p>One thing that comes to my mind is to have a specifically designed protein to collect greenhouse gases to slow down the climate change. But how is this possible? Maybe by designing proteins. This would be similar to a text generation task in our NLP world. Let’s see.</p><h3>Letters and Words in the Protein World</h3><p>I am not a biology expert, so read the below with a grain of salt.</p><p>From the perspective of a computer scientist, this is how a protein is created: Our DNA contains codings represented by four letters: ACTG. These letters reside within the core of our cells. To create a protein, a mechanism reads the DNA and generates an mRNA (messenger ribonucleic acid). The mRNA carries the coding for the protein to the exterior of the core, initiating the process of protein synthesis. The protein chain is formed by sequentially adding the corresponding amino acids, guided by the codes in the mRNA, to the end of the protein chain.</p><p>Different combinations of three letters correspond to different amino acids. There are 64 possible combinations, but some of them correspond to the same amino acid. Consequently, there are 20 unique amino acids. Amino acids serve as the building blocks of proteins. Each protein consists of a specific number of amino acids, and the sequence of these amino acids defines the structure and function of the protein. The graphics below might provide a clearer understanding of this concept.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*cFo_zBLXF6GTQLmk.jpg" /><figcaption><a href="https://www.technologynetworks.com/applied-sciences/articles/essential-amino-acids-chart-abbreviations-and-structure-324357">https://www.technologynetworks.com/applied-sciences/articles/essential-amino-acids-chart-abbreviations-and-structure-324357</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/0*2rTJBHB-ANO9l55q.png" /><figcaption><a href="https://www.khanacademy.org/science/ap-biology/gene-expression-and-regulation/translation/a/the-genetic-code-discovery-and-properties">https://www.khanacademy.org/science/ap-biology/gene-expression-and-regulation/translation/a/the-genetic-code-discovery-and-properties</a></figcaption></figure><p>This table illustrates the amino acids and their corresponding codes. The letters are represented in the mRNA-transformed way of DNA codes, which involves converting G to C, C to G, A to U, and T to A during the mRNA creation process explained earlier. Details of this process are not crucial for our discussion.</p><p>AUG serves as the starting code, initiating the formation of the first amino acid in each protein chain, while the ending codes are UAA, UGA, or UAG.</p><p>For a more in-depth understanding of proteins, particularly from a machine learning perspective, I recommend you to read this article: <a href="https://huggingface.co/blog/deep-learning-with-proteins#introduction-for-machine-learning-people-what-the-hell-is-a-protein">Deep Learning with Proteins</a></p><h3>Differences Between Natural Language and Protein Language</h3><p>I assume that you know, depending on the definition of a language, languages can include natural language, music, dna sequences and so on.</p><p>While using a Natural Language model in another domain such as proteins, we must consider the differences of these domains.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*noTQRR7zqCNuXr0ispXH8A.png" /></figure><p>Above image gives 2 examples to map the protein domain into natural language domain.</p><p>For the first one, we just have 4 letters. Most natural languages have more than 20 letters, and even some of them such as Tamil has 247 letters. Also there are unlimited ways to create words in the natural language, but there are only 20 words possible in the protein domain.</p><p>For the second mapping, we use 20 amino acids as letters and we use some number of amino acids as a word. This makes the two domains a little similar, since using 4 amino acids as a word, gives us 160,000 possible words. This number of words are even enough for a natural language, thus we can say the mapping is now similar in terms of numbers.</p><p>Also, graphs below shows the number of words in a natural language dataset. LM1B is a natural language dataset with around 1B words, and its mean sentence length is 24 words.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*wJTyd7SUJsQeVX43D4EgLw.png" /><figcaption>LM1B dataset has an average of around 24 words in each sentence.</figcaption></figure><p>And this graph below, shows the number of amino acids in a protein sequence. If we accept 4 amino acids as a word, we got a mean of 45 words in the protein domain. These numbers may give us insights in the future where we look at the model architectures.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*Usmz24NkzEkPamXlp2MSuQ.png" /><figcaption>SCOP dataset has an average of around 182 amino acids in each sequence</figcaption></figure><h3>Language Models and Down-streaming</h3><p>After the year 2018, BERT has become a model that most tasks can be down-streamed from. The reason for its wide acceptance was its quick success in down-streaming other tasks with fine-tuning. The trend didn’t end with NLP; BERT has been applied across various domains, including Vision, Speech, Finance, and, of course, Proteins.</p><p>BERT itself is a Language Model that is trained with <strong>Masked Language Model</strong> and <strong>Next Sentence Prediction</strong> tasks.</p><p>In the next part of the Protein Language Models blog series, we will see the tasks and language model architectures in the protein world.</p><p>I am doing my masters thesis on protein language models. I will benefit your comments and ideas on this and the following articles, please feel free to share them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ab36b72d33f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ML Kuralları [4/4]: Özellik Mühendisliği ve Optimizasyon]]></title>
            <link>https://akgunsalihtalha.medium.com/ml-kurallar%C4%B1-4-4-%C3%B6zellik-m%C3%BChendisli%C4%9Fi-ve-optimizasyon-9219a66b7a6d?source=rss-d425f5d2c34d------2</link>
            <guid isPermaLink="false">https://medium.com/p/9219a66b7a6d</guid>
            <category><![CDATA[makine-öğrenmesi]]></category>
            <category><![CDATA[feature-engineering]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[optimization]]></category>
            <dc:creator><![CDATA[Salih Talha Akgün]]></dc:creator>
            <pubDate>Sun, 21 Aug 2022 05:56:26 GMT</pubDate>
            <atom:updated>2022-08-21T05:56:26.623Z</atom:updated>
            <content:encoded><![CDATA[<p>Bu serinin kaynağı olan Rules of Machine Learning yazısında, tüm bu kurallar 3 faz altında işleniyor. Şimdiye kadarki ilk 3 yazımda birinci faz üzerinde duruyorduk, yani ilk pipeline’ın oluşturulması. Şimdi ise diğer iki fazı kısaca anlatacağım.</p><p>Her zamanki gibi ürünü yayınlayıp üzerinde iteratif olarak çalışmayı amaçlayacağız (Kural #16).</p><h4>Feature Engineering</h4><p>İkinci fazımız feature engineering yani özellik mühendisliği. Bu faz uçtan uca sistemimizin birim ve sistem testlerinin yapılır hale gelmesinden sonra başlar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IAE6CJWm9iccPaMSRnh4KQ.png" /></figure><p>Özellik Çıkarımı (Feature Extraction) temelde ham veriden anlamlı özellikler çıkarmak için yaptığımız iştir. Feature Engineering (Özellik Mühendisliği) ise bu modülün üzerinde mühendislik yapmamızdır. Önceden de söylediğim gibi, iyi bir modelin arkasında iyi bir mühendislik yatmaktadır. İki terim çoğunlukla birbirinin yerine kullanılmaktadır.</p><p>Bu iş sonucunda feature’larımız yani özelliklerimiz belli olur.</p><p>Bir model eğitimi sırasında kullanacağımız özellik sayısının elimizde olan veri ile doğru orantılı olarak artması beklenmektedir. Eğer az verimiz var ise çok fazla özelliğe sahip bir modeli eğitirken model tüm özellikleri düzgün bir şekilde öğrenemez. (Kural #21)</p><p>Eğer yeterince fazla veriye ulaştıysak, mesela milyarlar düzeyinde veriye sahipsek, artık daha spesifik özellikleri kullanabiliriz. Eğer yapabiliyorsak spesifik özellikleri kullanalım (Kural #19).</p><p>İş her zaman veride bitiyor. Eğer verimiz yeterince çok ise, daha fazla özellik oluşturup daha yüksek başarı elde edebiliriz. Özellik oluşturmanın en iyi yollarından birisi de feature crossing (özellik çarpımı) yöntemdir. Burada iki veya daha fazla özellik birleştirilerek tek bir özellik gibi kullanılır. (Kural #20)</p><p>Örneğin bir insan için ‘yaşadığı yer’ ve ‘cinsiyet’ özelliklerimiz olsun. Normalde bu özellikler ‘Kanadalı’, ‘Türk’, ‘Erkek’, ‘Kadın’ gibi sınıflara sahipken feature crossing sonrasında ‘Kanadalı Erkek’, ‘Türk Kadın’, ‘Türk Erkek’ … gibi sınıflara sahip olacaktır. Böylece aslında her bir insan için daha spesifik özelliklerimiz olacaktır.</p><p>Bu kısımda son olarak bir şey hatırlatayım. Bu serinin ilk yazısında tehdit olarak bahsettiğim training serving skew, hala dikkat etmemiz gereken bir şey. Bununla ilgili ayrı bir yazı yazdığım için detayına girmeyeceğim. Sadece, modele girdi olarak gelen her şeyi modeli sunarken loglamamız gerektiğini unutmayalım (Kural #29).</p><h4>Optimizasyon</h4><p>Baştan beri amacımız olan yere geldik. Artık modelimizi sunuyor ve düzenli olarak yeni model eğitip sunulan modelle yeni modeli değiştiriyoruz. Bu değişimi yaparken bu iki modeli yan yana koyuyor ve değerlendiriyoruz. Bu değişimler sonrasında kazançlarımız azalmaya başladıysa, bir metriğin değeri artarken diğer metriğin değeri azalıyorsa optimizasyon fazına girmişiz demektir. Optimizasyon fazında, artık daha kompleks modellere geçmenin zamanı geliyor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3F4YifgEf2METeydGaVMIQ.png" /></figure><p>Yeni modele geçmek için genelde izlenen yol, modele gelen trafiğin %10&#39;luk kısmını yeni modele yönlendirmektir. Sonrasında modelin başarısını ölçmek için takip ettiğimiz metriklerin değerlerini karşılaştırır ve yeni model daha başarılı ise trafiği yavaş yavaş artırırız.</p><p>Eğer yeni modeli eğittiysek ve kendi bilgisayarımızda veya sunucumuzda çalıştırdığımızda güzel sonuçlar alıyorsak fakat ona rağmen modeli canlıya almaktan vazgeçtiysek bir problem var demektir. Böyle bir durumda modele yeni özellikler (feature) eklemeye çalışmak yerine objektifimizi yeniden gözden geçirmemiz gerekmektedir (Kural #38).</p><p>Objektifimizin orta ve uzun dönemli hedeflerimize uygun başka bir objektif ile değiştirilmesi gerekebilir. Objektif seçimi ve pasif yapmamız gereken işler için önceki yazıma göz atmanızı tavsiye ederim.</p><p>Diyelim bu problemi atlattık ve sağlıklı bir launch &amp; iterate (başlat ve yenile) döngüsüne girdik, yani her 3 ayda bir daha iyi sonuçlar veren bir model eğitip canlıya alabiliyoruz. Böyle bir durumda her canlıya alacağımız modelin aslında uzun dönem hedefimizin bir izdüşümü olduğunu bilmeliyiz (Kural #39).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JMezZFly9Ly-s82_cZO8_A.png" /></figure><p>Biz ML mühendisleri olarak bir ML objektifi belirler ve bu objektifin değerini artırırsak yeni modelimizin canlıya alınacağını düşünürüz. Fakat bu objektif her zaman iş objektifini, iş hedefini tam yansıtmayabilir. Bu durumla ilgili Martin Zinkevich, makine öğrenmesinin geleceğinin, tık sayısını tahmin etmek için daha karmaşık modeller kullanmakta değil, uzun dönem hedeflerimize ulaşmanın yollarını belirlemek için insanların makinalarla nasıl beraber çalışabileceğini bulmakta olduğunu düşünüyor.</p><p>Martin Zinkevich’in yazdığı bu kurallar aslında bir kere okuyup kenara bırakılmaktan ziyade bir problem ile karşılaştıkça dönülüp gözden geçirilecek kurallardır. Kuralları okuyup “ben de böyle yaptım mı?” diye kendimize sormamız ve yapmadıysak bir hatamızı fark etmemiz çıkardığımız ürünlerin başarısını artıracak veya hızlandıracaktır.</p><p>Bu serinin amacı çoğu ML mühendisinin günlük hayatta karşısına çıkma ihtimali olan, daha sık kullanılacağını düşündüğüm kurallardan bazılarını anlatmaktı. Umarım faydalı olmuştur.</p><p><strong>Referanslar:</strong></p><p>1 — ML Kuralları Yazısı (Martin Zinkevich):</p><p><a href="https://developers.google.com/machine-learning/guides/rules-of-ml">Rules of Machine Learning: | Google for Developers</a></p><p>2 — ML Kuralları Serisi</p><ul><li><a href="https://akgunsalihtalha.medium.com/ml-kurallar%C4%B1-1-4-ml-olmadan-%C3%BCr%C3%BCn%C3%BC-yay%C4%B1nlamaktan-korkma-cc93b3fd567f">ML Kuralları [1/4]: ML Olmadan Ürünü Yayınlamaktan Korkma!</a></li><li><a href="https://akgunsalihtalha.medium.com/ml-kurallar%C4%B1-2-4-altyap%C4%B1y%C4%B1-ayr%C4%B1ca-test-et-5b1fa0a2822">ML Kuralları [2/4]: Altyapıyı Ayrıca Test Et!</a></li><li><a href="https://akgunsalihtalha.medium.com/ml-kurallar%C4%B1-3-4-pasif-i%CC%87%C5%9Fler-objektif-ve-metrikler-697329e7a58">ML Kuralları [3/4]: Pasif İşler, Objektif ve Metrikler</a></li></ul><p>3 — Konsept Kayması ve Veri Kayması Nedir — ML Problemleri:</p><p><a href="https://akgunsalihtalha.medium.com/konsept-kaymas%C4%B1-ve-veri-kaymas%C4%B1-nedir-ml-problemleri-153ac760a587">Konsept Kayması ve Veri Kayması  Nedir — ML Problemleri</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9219a66b7a6d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ML Kuralları [3/4]: Pasif İşler, Objektif ve Metrikler]]></title>
            <link>https://akgunsalihtalha.medium.com/ml-kurallar%C4%B1-3-4-pasif-i%CC%87%C5%9Fler-objektif-ve-metrikler-697329e7a58?source=rss-d425f5d2c34d------2</link>
            <guid isPermaLink="false">https://medium.com/p/697329e7a58</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[makine-öğrenmesi]]></category>
            <category><![CDATA[metrics]]></category>
            <category><![CDATA[mlops]]></category>
            <dc:creator><![CDATA[Salih Talha Akgün]]></dc:creator>
            <pubDate>Sun, 14 Aug 2022 05:48:53 GMT</pubDate>
            <atom:updated>2022-08-14T05:48:53.262Z</atom:updated>
            <content:encoded><![CDATA[<p>Diyelim ki önceki yazıları okudunuz ve tüm bu adımları takip ederek bir model oluşturdunuz. Bu model, bir if/else ile başladı, sonra uçtan uca altyapısı kuruldu, altyapının her elemanı teker teker test edildi, model kullanıcıya ulaştı, zamanla veri toplandı ve if/else modeli atılıp yerine gerçek bir ML modeli geldi. Peki şimdi ne yapacağız?</p><p>Şimdi sürekli yapıyor olmamız gereken bazı pasif işlerimiz var:</p><ul><li><strong>Sistemin tazeliğinden emin ol</strong>: Martin Zinkevich diyor ki eğer Google Play Search için ML modeli güncellenmezse, bir aydan kısa sürede olumsuz bir etkisi olabilir (Kural #8). Bu sebeple modelimizin başarılı tahmin oranını takip ediyor olmamız lazım.</li><li><strong>Model export etmeden önce sanity check yani bilinçli kontrol yap: </strong>Export ettiğin modelin test verisi üzerindeki ROC-AUC değerlerini incele. Daha kullanıcıya ulaşmamış bir modelin sorunlarını konuşmak bir mail ile hallolurken, kullanıcıya ulaşmış bir model için bir sayfa rapor gerekebilir. (Kural #9)</li><li><strong>Sessiz sorunlara dikkat et:</strong> Arka planda gelip giden veride bir değişiklik yaşanıyor olabilir. Bir veri tabanındaki tablo aylardır güncellenmemiş olabilir. Martin Zinkevich, Google Play için çalışan bir model için örnek veriyor ve 6 aydır güncellenmemiş bir tabloyu güncellemenin, modelin başarısını %2 arttırdığını söylüyor. (Kural #10)</li><li><strong>Sorumluluk ve Dokümantasyon:</strong> Eğer büyük bir şirkette çalışıyorsanız farklı veri saklama altyapıları kullanıyor olabilirsiniz. Bu altyapılar içerisinde herkes veri ekliyor ve okuyor olabilir. Bu sebeple ham veriden bir feature, yani özellik oluştuğu zaman onu oluşturan kişi bu özellik ile ilgili bilgiye sahip olsa da şirketteki herkes bunu bilmeyebilir. En iyi çözüm, özelliklere sahip (sorumlu kişi) atamaktır. Onu kim oluşturduysa o özellik ile ilgili bilgiler ondan sorulacak, dokümanyasyonunu o yapacak, eğer işten ayrılıyorsa başka birisine o özelliği aktardığından emin olacaktır. (Kural #11)</li></ul><p>Bu pasif işleri bir yandan yapmaya devam ederken modelimizin performansını korumaya ve artırmaya çalışıyoruz. Bu performansı belirleyen şey, hedefimiz yani objektifimizdir. Bu performansı artırmak için takip ettiğimiz değerler ise metriklerdir. Objektifimizi bu metrikler arasından seçerek belirleriz. Eğer model, bir işletme için hazırlandıysa, bir iş objektifimiz olacaktır. Bu iş objektifi (business objective) sonrasında bir ML objektifine dönüştürülecektir. Genellikle objektifimiz olarak seçtiğimiz metrik, tam olarak objektifimizi, hedefimizi yansıtmaz. Fakat güzel bir yakınsama sağlar. Modelimiz bu değerleri optimize etmeye çalışırken eğitilmiş olacaktır.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p1_MYINaGhB8Z7uiovqahA.png" /></figure><p>Algorithmia’nin 2020 yılında yaptığı araştırmaya göre kuruluşların machine learning kullanma amaçları oldukça farklıdır fakat hepsi kazancı optimize etmeyi amaçlar. Bu amacı ML metriklerine çevirmek zordur.</p><p>Mesela MLOps üzerine bir kitap (Designing Machine Learning Systems) yazan ve Stanford’da bir kurs (CS 329S) veren Chip Huyen, kitabında şöyle bir örnek veriyor. Hazırladığımız bir model, müşterilere özelleştirilmiş çözümler sunup onları daha mutlu ederek daha fazla para harcamalarını sağlayabilir, veya sorunlarını çok daha hızlı çözüp daha az para harcamalarına neden olabilir.</p><p>Bu yüzden ML projelerinin iş objektiflerine katkısını anlamak zordur. Birçok takım, yatırımcıların kârını düşünmek yerine precision, f1 gibi metrikleri düşündüğü için yararsız görülüp kapatılmıştır.</p><p>Kurallara dönecek olursak, hangi metriği optimize edeceğimizi düşünmek için çok zaman harcamamalıyız (Kural #12). Modelimizin bir işletmeye katkısı olduğunu hızlıca kanıtlamak istiyoruz, bu sebeple zaman bizim için çok önemli. Ayrıca az önce bahsettiğimiz gibi, bazen iş objektiflerini anlamak da zor oluyor. En iyi çözüm, basit ve anlaşılır olan ve iş objektifinin yansıması olan (müşteri memnuniyeti —&gt; platformda geçirilen süre) bir metriği seçip başlangıcı yapmaktır (Kural #13).</p><p>Örneğin tıklama sayısı ve izleme süresi gibi metriklerin birbiriyle doğru orantılı olduğunu, birinin arttığında diğerinin de arttığını göreceğiz. Bu sebeple ikisi arasında uzun karşılaştırmalara girmemize gerek yoktur. İlk seçtiğimiz metrik olabildiğince basit ve direk olmalıdır. “Kullanıcı yarın tekrar giriş yaptı mı?” gibi metrikler yerine “Kullanıcı ne kadar süre harcadı?” metriğini kullanmak direk ve mantıklı olacaktır. Diğer metrikleri objektifimiz olarak kullanmasak da takip etmeye devam etmeliyiz, çünkü yine modelimiz için yararlı olacaktır (Kural #2).</p><p>Eğer objektif olarak seçtiğimiz metriği optimize ediyorsak ama buna rağmen eğitim sonucunda oluşan modeli yayınlamamaya karar veriyorsak (diğer metriklerdeki başarısızlığımızdan ötürü olabilir), objektifimizi gözden geçirmenin zamanı gelmiştir.</p><p>MLOps üzerine çalışmayı düşünüyorsanız referans olarak verilen kitabı takip etmenizi tavsiye ederim. Kitaba başlar başlamaz ilk chapter’ı okudum. Gayet anlaşılır ve basit yazılmış ve çok önemli konulara değiniyordu. Yazarın kursuna da göz atmanızı tavsiye ederim, sitenin içerisinde ders notlarını da bulabilirsiniz.</p><p><strong>Referanslar:</strong></p><p>1 — ML Kuralları Yazısı (Martin Zinkevich):</p><p><a href="https://developers.google.com/machine-learning/guides/rules-of-ml">Rules of Machine Learning: | Google for Developers</a></p><p>2 — Designing Machine Learning Systems, Chip Huyen</p><p><a href="https://www.amazon.com/Designing-Machine-Learning-Systems-Production-Ready/dp/1098107969">Designing Machine Learning Systems: An Iterative Process for Production-Ready Applications</a></p><p>3 — CS 329S:</p><p><a href="https://stanford-cs329s.github.io/index.html#overview">CS 329S | Home</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=697329e7a58" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ML Kuralları [2/4]: Altyapıyı Ayrıca Test Et!]]></title>
            <link>https://akgunsalihtalha.medium.com/ml-kurallar%C4%B1-2-4-altyap%C4%B1y%C4%B1-ayr%C4%B1ca-test-et-5b1fa0a2822?source=rss-d425f5d2c34d------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b1fa0a2822</guid>
            <category><![CDATA[makine-öğrenmesi]]></category>
            <category><![CDATA[mlops]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Salih Talha Akgün]]></dc:creator>
            <pubDate>Sat, 06 Aug 2022 21:39:03 GMT</pubDate>
            <atom:updated>2022-08-06T21:39:03.566Z</atom:updated>
            <content:encoded><![CDATA[<p>Bu yazı serisinde Google mühendislerinden Martin Zinkevich’in yayınladığı ML Kuralları yazısındaki kuralları detaylandıracağız. Bazılarını tek başına, bazılarını birleştirerek anlatacağım. Tüm kuralları Google Developers[1] sitesinden bulabilirsiniz.</p><p>ML Kuralları diye bir seri yazıp yapay zeka modeli dışında kalan kısımlara bu kadar dikkat edilmesini önermek garip bir durum gibi görünüyor. Fakat bunun tabi ki mantıklı bir sebebi var.</p><h4>1 — Amaç</h4><p>Ana akım olmayan bir modelde başarı elde etmek istiyoruz. Bizim ulaşmak istediğimiz Machine Learning modeli, hazır bir veri seti alınıp, state-of-the-art model seçilip eğitilecek bir model değil. Bu modeli zaten herkes internetten birkaç kurs takip edip eğitebilir. Belki bir POC hazırlamak için bu yöntem yeterli olabilir. Fakat bizim ulaşmak istediğimiz model, elimizdeki duruma özel olarak birçok kez test edilip tekrar eğitilmiş olmalıdır.</p><p>Öyle ki, modelimiz birçok kez eğitilirken biz de modelimizi insanlara sunup onun eksik yanlarını her an monitör ediyor ve düzeltmek ile uğraşıyor olmalıyız.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XU4SzjgU-bP77qkKDhmLKQ.jpeg" /></figure><p>Bir Machine Learning modeli üstünde iteratif olarak çalışılması sonucu, gerçek dünyada başarılı hale gelir. Bu model önce gerçek dünyada sorunlar ile karşılaşmalı, sonra biz o sorunları fark edip gerekli aksiyonları almalıyız.</p><p>Kendi üzerimizden düşünelim. Öğrenmeye çalıştığımız bir konudaki (matematik, yazılım, edebiyat…) başarımızı belirleyen şey nedir? Bunu tanımlamaya çalışan kişisel gelişim yazarları şu formülü önermişler:</p><blockquote>( Çalışma Verimi ) x ( Çalışılan Toplam Saat ) = Başarı</blockquote><p>Aynı formülü modelimiz için uyarlarsak, her bir iterasyondaki verim (çözmeye çalıştığımız problemi ne kadar çözdük) ile iterasyon sayımızın çarpımı modelimizin başarısını verecektir. Bu yüzden olabildiği kadar çok problem çözmek ve olabildiğince çok iterasyon yapmak istiyoruz. Olabildiğince çok iterasyon yapmak için önceki yazımda bahsettiğimiz kuralı (Kural #4) uygulayarak basit bir modelle başlayıp hızlıca altyapı oluşturmalıyız. Sonrasında ise bu altyapı içerisindeki modeli çok kolay bir şekilde değiştirebilmeliyiz. Bunu sağladıktan sonra hızlı iterasyonlar yapabiliriz.</p><h4>2 — Tehdit</h4><p>Kullanıcılarımıza ulaşmış olan modelimizi sürekli eğitmeyi amaçlıyoruz. Bunu yapmak için modelin eksiklerini sürekli fark etmek istiyoruz.</p><p>Fakat önceki yazımdan da hatırlayacağınız gibi ML algoritması, kullanıcıya ulaşması için kurduğumuz sistemin yanında çok küçük kalıyor. Bu sebeple, hata olduğunu düşündüğümüz şeylerin ML algoritmasından değil bu altyapıdan kaynaklı olma ihtimali gayet yüksek.</p><h4>3 — Çözüm</h4><p>Kurduğumuz altyapı yüzünden karşılaşacağımız hataları en aza indirmeliyiz. Bunun için en iyi yol, altyapımızı olabildiğince test edilebilir olarak hazırlamak ve modelden ayrı bir şekilde test etmektir (Kural #5). Ayrıca, oluşabilecek her türlü hatayı baştan itibaren anlayabilmek için, ilgili metrikleri ölçüyor olmamız lazım(Kural #2).</p><p>Mesela modelimizin girdi ve çıktı dağılımı nasıl? Eğitim yaptığımız verinin dağılımı ile uyuşuyor mu?</p><p>Eğer uyuşmuyor ise sorun birden fazla yerde kaynaklanıyor olabilir. Belki sorun modelimizdedir. Veya belki eğitimde yaptığımız bir ön işlemeyi canlıya alınan modelimize eklemeyi unuttuk.</p><p>Asıl hedefimizi tekrar düşündüğümüz zaman, model haricinde bir yerde herhangi bir hata sebebiyle başarısızlık yaşanmasını istemeyiz. O yüzden pipeline’daki her bir komponenti ayrı ayrı test etmeliyiz. Veri düzgün bir şekilde okunuyor mu? Yapmak istediğimiz ön işlemeler düzgün bir şekilde yapılıyor mu? Eğitim ortamında oluşturduğumuz model sunulduğunda aynı test verisi üstünde aynı sonucu veriyor mu? Bunlar tamamen altyapı ile ilgili sorulardır ve cevapları evet olmalıdır.</p><p>Peki ya model ile ilgili yaşanabilecek sorunlar?</p><p>Modelde yaşanacak hataları test etmemizin tek yolu test verisi üzerindeki başarısını incelemektir. (Kural #9)</p><ol><li>Eğer test verimiz gerçek dünyayı yansıtıyor ve model test verisinde başarılı ise modeli yayınlayabiliriz.</li><li>Eğer test verimiz gerçek dünyayı yansıtıyor ama modelimiz test verisinde başarısız oluyor ise, modelimiz üzerinde çalışıp bu sonucu iyileştirmeliyiz.</li><li><strong>Eğer test verimiz gerçek dünyayı yansıtmıyor ise </strong>elimizde pek seçenek yoktur. Modelimiz başarılı olsa bile onu yayınlamak doğru değildir.</li></ol><p>Gördüğünüz gibi ML modelleri dikkat edilmesi gereken ve tahmin edilemez olan bir çok şey içerir. Production’a geçmiş bir model ise birçok komponentten oluşmasıyla birlikte aslında çok küçük bir kısmı ML algoritmasıdır. Bu sebeple diğer komponentlerin doğru çalıştığından emin olmadan ML modeli üstünde çalışmak doğru değildir.</p><p>Bu yazıyı kısa ve net tutmak istedim. Eğer daha fazla okuma yapmak istiyorsanız başka bir Google mühendisi tarafından hazırlanmış şu[2] dokümana da göz atabilirsiniz.</p><p>Bu dokümanda Patrick Riley, birçok önemli şeyin yanında, konumuz ile alakalı olan şu sözü söylüyor: Measure twice, or more. Kendisi bu sözü veri analizi için söylüyor olsa da ML sistemleri tahmin edilemeyecek çıktılar üretmeye elverişli sistemler, bu sebeple aynı şeyi biz de söyleyebiliriz. Aynı dokümanda Patrick Riley, başarılı olarak tanımlanan iş arkadaşlarının, aslında <strong>dikkatli ve sistemli çalışan kişiler</strong> olduğunu da söylüyor.</p><p>Okuduğunuz için teşekkürler.</p><p><strong>Referanslar:</strong></p><p>1 — ML Kuralları Yazısı (Martin Zinkevich):</p><p><a href="https://developers.google.com/machine-learning/guides/rules-of-ml">Rules of Machine Learning: | Google for Developers</a></p><p>2 — Büyük, Kompleks Veri Setlerinin Analizi İçin Pratik Tavsiyeler (Patrick Riley):</p><p><a href="https://www.unofficialgoogledatascience.com/2016/10/practical-advice-for-analysis-of-large.html">Practical advice for analysis of large, complex data sets</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b1fa0a2822" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Konsept Kayması ve Veri Kayması  Nedir — ML Problemleri]]></title>
            <link>https://akgunsalihtalha.medium.com/konsept-kaymas%C4%B1-ve-veri-kaymas%C4%B1-nedir-ml-problemleri-153ac760a587?source=rss-d425f5d2c34d------2</link>
            <guid isPermaLink="false">https://medium.com/p/153ac760a587</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[ml-engineering]]></category>
            <category><![CDATA[makine-öğrenmesi]]></category>
            <category><![CDATA[mlops]]></category>
            <dc:creator><![CDATA[Salih Talha Akgün]]></dc:creator>
            <pubDate>Thu, 04 Aug 2022 06:18:44 GMT</pubDate>
            <atom:updated>2022-08-04T06:27:17.754Z</atom:updated>
            <content:encoded><![CDATA[<h3>Konsept Kayması ve Veri Kayması Nedir — ML Problemleri</h3><p>Daha önceki yazılarımda kısaca bahsetmiş olsam da bu konunun kendine ait bir yazıyı hakettiğini düşünüyorum.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/0*KfSZh54PaXc1C_YK.jpg" /></figure><h3>1 —Konsept Kayması</h3><p>Öncelikle konsepti tanımlayarak başlayalım. Google’a konsept nedir yazarsanız, anlayış ve kavrayış anlamına geldiğini görebilirsiniz. Bu anlayış ve kavrayış bizi A noktasından B noktasına, X girdisinden Y çıktısına götürür. Bu sebeple aslında konsept, bizim modelimizin anlaması gereken şeydir. Konsepti anlamak modelin gerçek başarısını ölçer.</p><p>Biz bazı konseptleri biliriz. Mesela kedi, tatlı, tüyleri olan, kulakları olan bir hayvandır. Fakat bu söylediklerim bir köpek için de geçerli olabilir. Peki ya tüyleri olmayan bir kedi kedi değil midir, örneğin sphynx kedisi?</p><p>Gördüğümüz gibi gerçek dünyada konseptler değerlendirilmesi gereken bir çok değişken içerebilir (tüyler, kulaklar, tatlılık…). Ayrıca konseptler zaman ile değişebilir. Mesela telefon kelimesi eski yunancada uzak ses anlamına gelir. Fakat şuan telefon, uzaktaki kişilerle konuşmak dışında bir sürü işleve sahiptir.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/0*EehH8ETcXa4jQayx" /></figure><p>İşte konseptlerin zamanla değişmesine, konsept kayması denir. Artık aynı girdiler gerçek dünyada farklı anlamlara gelmektedir. Konsept kaymaları gerçek dünyada, uzun süreler içerisinde gerçekleşir.</p><p>Fakat bu değişiklikler gerçekleşirken bizim modelimizde bir değişiklik yoksa hala aynı çıktıyı vermeye devam edecektir ve yanlış kararlar verecektir.</p><h3>2 — Veri Kayması</h3><p>Hadi bu sefer de veriyi tanımlayarak başlayalım. Veri nedir? Google bu soruya “bir araştırmada, bir tartışmada, bir akıl yürütmede sonuca ulaşabilmek için gereken ilk bilgi” olarak cevap veriyor. Aynı tanım modelimiz için de geçerlidir. Modelimiz sonuca ulaşmak için veriye bakacak ve karar verecektir. Modelimizin öğrenme süreci ise, bu karar mekanizmasının güncellenmesidir.</p><p>Fakat yine bir sorun var. Aynı bizim, okulda öğrendiğimiz çoğu şeyin gerçek hayatta farklı olması gibi, veya yeri olmaması gibi, modelimizin bizim bilgisayarımızda öğrendiklerinin de gerçek hayatta yeri olmayabilir.</p><p>Örneğin bir araba fabrikasında hazırlanan metal tabakalarda çizik olup olmadığını bulan bir model eğitmek istiyoruz. Bu modeli eğitirken, fabrikadan önceden alınmış görüntüleri kullanıyoruz. Bu görüntüleri train ve test verisi olarak ayırıyoruz. Sonra modeli eğitip test ediyoruz. Belli bir başarıya ulaşana kadar uğraşıyoruz ve sonunda %99 başarı oranına ulaşıyoruz. Müthiş.</p><p>Bu modeli gidip fabrikaya kurduğumuz zaman görüyoruz ki modelimiz gerçek dünyada çok hata yapıyor. Çünkü eğitildiği görüntüler hep aynı kameradan, aynı açı ile, aynı ışıklandırma ile çekilmiş görüntüler. Fakat fabrikada çalışırken birçok farklı açı ve ışıklandırmada karar vermesini bekliyoruz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jMOa1WzAAFaSgWi7.png" /><figcaption>Drift (Kayma)</figcaption></figure><p>Burada iki farklı kavramdan söz edip bunları ayırt etmenin vakti geldi. Skew ve Drift. Skew; eğrilik, yamukluk anlamına gelirken, drift kayma anlamına geliyor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/0*z-47m9e7nsJe4E8d.jpg" /><figcaption>Skew (Eğrilik)</figcaption></figure><p>İkisi de temelde aynı şeyi ifade etseler de skew, yani eğrilik hemen fark edilir (yukarıdaki fabrika örneği gibi). Fakat kayma, bir süreçtir ve hemen fark edilemez.</p><p>Mesela yukarıda verdiğimiz fabrika örneği train-serve skew olarak bilinir, eğitim yaptığımız veri dağılımı, tahmin yürüteceğimiz dağılımdan farklıdır, bu fark sonucunda model serve edilir edilmez başarısızlık fark edilir.</p><p>Diğer bazı skew çeşitleri;</p><ol><li><strong>Distribution Skew</strong> yani dağılım eğriliği, input değerlerinin beklenen dağılımda gelmemesinden kaynaklanır. Training sırasında kullanılan bir normalizasyon işleminin serving sırasında unutulması buna sebep olabilir.</li><li><strong>Schema Skew</strong> yani şema eğriliği, training sırasındaki inputların veri tiplerinin serving ile uymamasıdır. Training sırasında yapılan bir preprocessing sırasında float bir değer integer’a çevirilmişse ve serving sırasında bu işlem tekrarlanmamışsa, schema skew gerçekleşir.</li></ol><p>Konumuz olan Data Drift yani veri kayması ise skew’a göre daha yavaş gerçekleşir. Zamanla modelimize gelen girdiler, eskisinden farklı olmaya başlar. Model daha önce bu girdilerle karşılaşmadığı için doğru kararlar veremez.</p><p>Veri kayması üzerine eğitimden verdiğimiz örneği biraz daha ilerletelim. Mesela iyi eğitim verilen bir üniversitede yazılım eğitimi aldınız ve çalışmak istediğiniz alanda yetkinliğe sahipsiniz. Fakat gelin görün ki eğer bahsettiğimiz eğitimi 1980 yılında almış olsaydınız, aldığınız Pascal eğitimi zamanla günümüzün ihtiyaçlarını karşılamaz hale gelmiş olurdu. İnsanlar blockchain’den, web3&#39;den, farklı database konseptlerinden, yapay zekadan konuşuyor artık.</p><p>Modelimiz üzerinden konuşacak olursak, veri kayması, daha önceden karşılaşmadığımız bir veri dağılımı ile karşılaşmamız demektir ve bu zamanla gerçekleşir. Mesela diyelim ki Facebook’da çalışıyoruz ve arkadaş öneri sistemini hazırlayacağız. Facebook ilk yayınlandığı zaman aynı üniversitede okuyan insanları birbirlerine önerebiliriz, çünkü çoğu kullanıcımız zaten üniversite öğrencisi. Fakat ileride farklı yaş gruplarından ve farklı eğitim ve kariyer düzeyinden insanlar platforma dahil olacak. Böyle olunca, Harvard’da okuyan 20 yaşındaki bir öğrenci, Harvard’ı bitirmiş 50 yaşındaki (platformumuza yeni katılan) bir iş adamını tanımıyor olacak. Bizim modelimiz ise önlem almazsak zamanla daha kötü öneriler yapmaya devam edecek. Başta başarılı olan model, veri dağılımının değişmesi ile başarısızlık göstermeye başlar. İşte veri kayması budur.</p><h4>Özet</h4><p>Kısaca skew ve drift arasındaki fark, skew genellikle modelin ürün haline geldiği an var olan, anlık bir problem iken drift, yavaş yavaş büyüyen bir problemdir.</p><p>Kısaca veri kayması ve konsept kayması arasındaki fark, konsept kaymasında girdimiz X ile çıktımız Y’nin arasındaki ilişki değişirken, veri kaymasında girdimiz X’in dağılımı değişir.</p><p><strong>Kaynaklar:</strong></p><ol><li><a href="https://cloud.google.com/architecture/ml-modeling-monitoring-analyzing-training-server-skew-in-ai-platform-prediction-with-tfdv">https://cloud.google.com/architecture/ml-modeling-monitoring-analyzing-training-server-skew-in-ai-platform-prediction-with-tfdv</a></li><li><a href="https://deepchecks.com/data-drift-vs-concept-drift-what-are-the-main-differences/">https://deepchecks.com/data-drift-vs-concept-drift-what-are-the-main-differences/</a></li><li><a href="https://evidentlyai.com/blog/machine-learning-monitoring-data-and-concept-drift">https://evidentlyai.com/blog/machine-learning-monitoring-data-and-concept-drift</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=153ac760a587" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ML Kuralları [1/4]: ML Olmadan Ürünü Yayınlamaktan Korkma!]]></title>
            <link>https://akgunsalihtalha.medium.com/ml-kurallar%C4%B1-1-4-ml-olmadan-%C3%BCr%C3%BCn%C3%BC-yay%C4%B1nlamaktan-korkma-cc93b3fd567f?source=rss-d425f5d2c34d------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc93b3fd567f</guid>
            <category><![CDATA[google]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[makine-öğrenmesi]]></category>
            <category><![CDATA[mlops]]></category>
            <dc:creator><![CDATA[Salih Talha Akgün]]></dc:creator>
            <pubDate>Sat, 30 Jul 2022 21:24:29 GMT</pubDate>
            <atom:updated>2022-07-30T21:24:29.664Z</atom:updated>
            <content:encoded><![CDATA[<p>Bu yazı serisinde Google mühendislerinden Martin Zinkevich’in yayınladığı ML Kuralları yazısındaki kuralları detaylandıracağız. Bazılarını tek başına, bazılarını birleştirerek anlatacağım. Tüm kuralları Google Developers[1] sitesinden bulabilirsiniz.</p><p>Bu yazıda ise genellikle birinci, üçüncü ve dördüncü kurallar üzerinde duracağız.</p><h4>1 — Amaç</h4><p>Herhangi bir konu üzerinde eğitilmiş, kullanıcılarımızın ihtiyaçlarını karşılayacak, kendi iş modelimizin tatmin edilmesini sağlayacak bir ML modelini kullanıcılara ulaştırmak istiyoruz.</p><p>Peki bu modelin başarısını nasıl ölçeceğiz? Toplamış olduğumuz veri setimizin bir kısmını test için ayırıp bununla bir başarı oranı ölçsek, yeterli olur mu?</p><h4>2 — Tehdit</h4><p>Çoğu yapay zeka modeli, veri kayması ve konsept kayması gibi tehlikelerle karşı karşıyadır. Veri kayması, production’daki modelin eğitilmediği bir veri dağılımı ile karşılaşmasıdır. Konsept kayması ise ele aldığımız problemin gerçek dünyada değişmesidir.</p><p>Bu tehditler ilerleyen zamanda modelimizin başarısının düşmesine sebep olacaktır.</p><h4>3 — Çözüm</h4><p>Bu sebeple çoğu model, kullanıcı ile etkileşim içerisinde olmalı, sürekli tahmin yürütmeli, tahminlerinin başarısı incelenmelidir. Modelin başarısının ölçülmesi için en iyi yol gerçek dünyadaki tahminlerini değerlendirmektir.</p><blockquote>Gerçek dünya ile etkileşim içerisinde olmayan, daha önceden belirlenmiş statik bir test seti ile başarısı ölçülen model her zaman gerçek dünyada başarısız olma ihtimali ile karşı karşıyadır.</blockquote><p><strong>Gerçek Dünya Problemi:</strong> Peki ya elimizde yeterli veri yoksa veya verimiz temiz değilse? Oturup binlerce sentetik veri mi oluşturacağız? Unutmayalım ki hazırladığımız modellerin başarısının arkasında her zaman veri yatıyor. Eğer elimizde kullanmak isteyeceğimiz veri yok ise, olabildiğince hızlı bir şekilde ürünümüzü kullanıcılarımız ile buluşturmak için kendi sezgilerimize göre kural tabanlı bir algoritma yazabiliriz (Kural #1).</p><p><strong>Örnek: </strong>YouTube gibi bir sosyal medya platformu içerisinde içerik öneri sistemi yapmak istiyoruz diyelim. Eğer daha ürünümüzü yayınlamadıysak hangi içerikler bizim platformumuzda daha fazla izlenecek, hangileri beğenilecek bilemeyeceğiz. Peki kullanıcıların platformda daha fazla vakit geçirmesini sağlamak için başarılı önerileri nasıl sunacağız?</p><p>Elimizde yeterli veri olmadan başarılı bir ML algoritması eğitmemiz mümkün değil. Oturup elle veri hazırlamak veya toplamak yerine, ürünün ilk halinde kendi sezgilerimize göre bir başlangıç yapabiliriz. Mesela ürün yayınlandıktan sonra kullanıcılara videoların izlenme sayısına veya toplam izlenme süresine göre öneride bulunabiliriz. Bu mantığımızı biraz daha geliştirip video izlenme sayısı, izlenme süresi, beğeni sayısı gibi değerleri bazı katsayılar ile çarpıp, videoları skorladığımız bir sistem kullanabiliriz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gh0W3dKkWfhnYIQ-df_J5Q.png" /></figure><p>Kendi hazırladığımız sezgisel sistem bir noktadan sonra saçma önerilerde bulunuyor olabilir. Bu saçma önerileri tespit etmek için ortaya koyduğumuz sezgisel modelin dışında, uçtan uca altyapımızın doğru olduğundan emin olmamız, modelin başarısını monitör ediyor olmamız lazım (Kural #4). Bu da basit bir model ile başlamak için başka bir neden. Çünkü eğer uçtan uca altyapıyı iyi kuramazsak modelin başarısız olduğu noktada sorunun nerede olduğunu çözemeyebiliriz.</p><p>Eğer altyapımızdan emin isek ve yeterince veri de topladıysak sezgisel modeli bir kenara bırakıp gerçek ML algoritmaları kullanmaya başlamalıyız(Kural #3). Çünkü ML algoritmaları, yeterince veri ile beslendiği zaman sezgisel modellerden her zaman daha yüksek başarı gösterecektir.</p><p>Yazım burada bitti fakat son olarak şunu söylemekte fayda var. Evet biz ML mühendisleriyiz, işimiz ML yapmak. Neden ML olmayan bir ürün yayınlıyoruz?</p><p>Çünkü biz aynı zamanda bir mühendisiz. ML modelleri de mühendislik yapmayı yani temiz kod yazmayı, kodu test etmeyi, yan masadaki çalışma arkadaşının görüşlerini almayı, versiyon kontrölü yapmayı, başarıyı takip etmeyi ve model üzerinde iteratif olarak çalışmaya devam etmeyi gerektiriyor. İşimiz sadece model eğitmek ile sınırlı değil. Biz aynı zamanda bu adımları tekrar edebilmek istiyoruz. Fakat ihtiyacımız olan veriye ulaşmak için de ML olmayan bir altyapıyı hazırlamak zorunda kalabiliriz. Bu altyapının, istediğimiz an modeli değiştirip sorunsuz bir şekilde çalışmaya devam edeceğinden de emin olmalıyız. Bu bir sonraki yazının konusu.</p><p>Okuduğunuz için teşekkürler.</p><p><strong>Referanslar:</strong></p><p>1 — ML Kuralları Yazısı (Martin Zinkevich):</p><p><a href="https://developers.google.com/machine-learning/guides/rules-of-ml">Rules of Machine Learning: | Google for Developers</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc93b3fd567f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[3 Steps to Coding Pythonic]]></title>
            <link>https://medium.com/carbon-consulting/3-steps-to-coding-pythonic-90b8f1edcd20?source=rss-d425f5d2c34d------2</link>
            <guid isPermaLink="false">https://medium.com/p/90b8f1edcd20</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[tips]]></category>
            <category><![CDATA[pythonic]]></category>
            <category><![CDATA[clean-code]]></category>
            <dc:creator><![CDATA[Salih Talha Akgün]]></dc:creator>
            <pubDate>Thu, 20 Jan 2022 11:33:23 GMT</pubDate>
            <atom:updated>2022-01-20T11:33:23.567Z</atom:updated>
            <content:encoded><![CDATA[<p>Pythonic comes from Idiomatic.</p><p><strong>Idiomatic </strong>means something that can’t be translated one-to-one but everyone understands what it means, like “hit the books” means “study hard”. The one-to-one translation is not enough to understand that phrase, you have to understand it with some prior knowledge.</p><p><strong>Pythonic </strong>means a code is written with idiomatic style, you can’t understand what it does with one-to-one translation (you can’t use python basics to understand it), you have to understand it with some prior knowledge. This article aims to give you some of that knowledge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iD6FXwrLSntrv-KzIqYB2w.jpeg" /><figcaption>Image from Real Python [5]</figcaption></figure><h3>1- Built-in Functions</h3><p>Let’s start with an easy one.</p><p>To get a slice from a list, you will probably use this annotation:</p><p>array[:2]</p><p>This annotation actually calls a built-in function called <strong>slice. </strong>As it is obvious in this example, using <em>for loops</em> to get a slice of your data will result in a bad usage of resources.</p><p>So for any algorithm you developed, you should first check if you can use built-in functions [1] instead of trying to implement them by yourself.</p><h3>2- Context Managers</h3><p>There will always be some data that will be used in your code. This data can be coming from a file or database.</p><p>When you finished the job with your file or database, you may want to close the file or disconnect from the database. This is why people use <strong><em>with </em></strong>statement in python. But there is always a probability for an exception to happen. Are you going to handle it with lots of <em>try and except</em>s?</p><p>A good way to handle these situations is to use a class with __enter__ and __exit__ magic functions. These are the functions that will be called when entered or exited the runtime context related to the object of that class with the <strong><em>with </em></strong>statement.</p><p>Here is an example code from the book Clean Code in Python[2]. This code is trying to disconnect from the database to take a backup. To handle any unexpected errors, it rewrites the __exit__ magic function to connect again with the database when the backup ended or when any exception is thrown.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c521361bd518f4d00a36e16fd87293d/href">https://medium.com/media/9c521361bd518f4d00a36e16fd87293d/href</a></iframe><p>This is definitely better than writing lots of code to handle all of the exceptions that may happen. The exception arguments in __exit__ function will be None if no exception happens.</p><p>Also, there is a better version of this that uses contextmanager.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/85cf171a86144e6d441a9cc4939976bf/href">https://medium.com/media/85cf171a86144e6d441a9cc4939976bf/href</a></iframe><p>This is what I call a Pythonic code. You first have to know how context managers work and second, you have to know that <strong><em>try </em></strong>represents <strong>__enter__</strong>, <strong><em>finally </em></strong>represents <strong>__exit__</strong>.</p><p>Contextlib is a python standard library having utilities for with-statement contexts. You can check all python standard libraries here: <a href="https://docs.python.org/3/library/">https://docs.python.org/3/library/</a></p><p>Also, these codes are from the book[2], and I highly recommend you to read the book. It has more examples on this topic which you may want to learn.</p><h3>3 — Data Classes</h3><p>Data classes are classes that are meant to hold data. The purpose of dataclass is to make classes easier to use as data containers. It makes your code more compact and understandable. Here is an example of dataclass from a great article[3].</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d49e56e6a18254b181c3a8f8a5697016/href">https://medium.com/media/d49e56e6a18254b181c3a8f8a5697016/href</a></iframe><p>Let’s look at it one by one.</p><ul><li>You don’t have to define an __init__ function, instead, you give the variable names and their types, it handles the rest for you.</li><li>It forces you to use type annotations, which is good for many things.</li><li>You can easily give default values (not mandatory), if you wanted to use this with default classes, you’d have to use lots of if else statements.</li><li>You can easily compare two instances if they have same values for same variables. If you wanted to use this with default classes, you’d have to overwrite __eq__ magic function.</li></ul><p>These are just the beginning, you can check more details on this topic at [3] and [4]. There are much more things that can be done with dataclass but this example is enough to start using it.</p><p>I hope you enjoyed and learned something. I highly recommend you implement these yourself and then read the references to get a deeper understanding.</p><p>If you have read this far, you may want to check other articles we have been publishing as Carbon Consulting.</p><p><a href="https://medium.com/carbon-consulting">https://medium.com/carbon-consulting</a></p><p>References:</p><p>1 —Python Built-in Functions, <a href="https://docs.python.org/3/library/functions.html">https://docs.python.org/3/library/functions.html</a></p><p>2 — Clean Code in Python, Develop Maintainable and Efficient Code, 2nd Edition, Mariano Anaya <a href="https://www.amazon.com/Clean-Code-Python-maintainable-efficient/dp/1800560214">https://www.amazon.com/Clean-Code-Python-maintainable-efficient/dp/1800560214</a></p><p>3— 9 Reasons Why You Should Start Using Python Dataclasses, <a href="https://towardsdatascience.com/9-reasons-why-you-should-start-using-python-dataclasses-98271adadc66">https://towardsdatascience.com/9-reasons-why-you-should-start-using-python-dataclasses-98271adadc66</a></p><p>4— Data Classes in Python 3.7+ (Guide), <a href="https://realpython.com/python-data-classes/">https://realpython.com/python-data-classes/</a></p><p>5 — <a href="https://realpython.com/learning-paths/writing-pythonic-code/">https://realpython.com/learning-paths/writing-pythonic-code/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=90b8f1edcd20" width="1" height="1" alt=""><hr><p><a href="https://medium.com/carbon-consulting/3-steps-to-coding-pythonic-90b8f1edcd20">3 Steps to Coding Pythonic</a> was originally published in <a href="https://medium.com/carbon-consulting">CARBON CONSULTING</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Customizing Training with TensorFlow in Python]]></title>
            <link>https://medium.com/carbon-consulting/custom-training-with-tensorflow-in-python-dae0dcc693bd?source=rss-d425f5d2c34d------2</link>
            <guid isPermaLink="false">https://medium.com/p/dae0dcc693bd</guid>
            <category><![CDATA[keras]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[vgg16]]></category>
            <dc:creator><![CDATA[Salih Talha Akgün]]></dc:creator>
            <pubDate>Wed, 27 Oct 2021 11:51:21 GMT</pubDate>
            <atom:updated>2021-10-27T11:51:21.620Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve searched the internet for an easy and complete introduction to custom model building in TensorFlow but I didn’t find it. So I decided to share it and the best reason is, the code explains itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*aouBWf3ffmOCORzJ.jpg" /><figcaption>Just show me the code!</figcaption></figure><p>Sequential API is a very easy way to create sequential fully connected neural networks. I recommend you to read about it if you don’t know, before continuing this article.</p><p>There are several ways to customize your training. Let’s start with custom flows.</p><h3>1. Custom Flows</h3><p>You can create custom flows with Functional API. This helps you make models where you have two outputs like MaskRCNN where you have bounding box and class predictions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/0*ssAOlVnS5sGtQ9c3.jpg" /><figcaption>An Output of the MaskRCNN Model</figcaption></figure><p>For this, you have to use Functional API as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*GFTxazWUSsomlXavNBdVbA.png" /><figcaption>Custom Model Flow</figcaption></figure><p>The base model will not give the best results but the final model will output a bounding box and a classification prediction. You can change the base model as you want.</p><h3>2. Custom Loss Function</h3><p>In the training of a neural network, the loss function is very important to find good results. If you want to customize your loss function, I’ll assure you it’s the easiest customization you can make.</p><p>To show it, we’ll implement RMSE (root mean squared error), even though it already exists in TensorFlow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/1*bPfMNZ3BBX0JK40t1tIxhw.png" /><figcaption>Custom Loss Function Definition</figcaption></figure><p>You can change the definition of the function as you want. Don’t forget to pass it to the compile function. I recommend you to check <a href="https://www.tensorflow.org/api_docs/python/tf/keras/losses/Loss">this site</a> if you want to create it as a class.</p><h3>3. Custom Layers</h3><p>Here we’ve come to the most important parts.</p><p>For this article, we’ll define a quadratic layer wherein for every neuron, we’ll use <strong>w0 * x² + w1 * x + b</strong> instead of <strong>w0 * x + b.</strong></p><p>To make it, we define a class that inherits from the Layer class and overwrites three functions.</p><ul><li>The <strong>__<em>init__ </em></strong>function will be called when the layer we defined is called. Here we will need to <strong>get the variables we want to give to the Layer</strong>.</li><li>The <strong><em>build </em></strong>function will be called to create the first state of our variables. Don’t forget to define them as trainable.</li><li>The <strong><em>call </em></strong>function will be called when we want to get the output of this layer. It <strong>computes the values that we want to pass to the next layer</strong> and returns them.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*IhQ3lEWLRyXWmEcrtzOgGA.png" /><figcaption>Custom Model Class Definition</figcaption></figure><p>After that, you can just use this layer just like a Dense layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*roTvoBQ-FUawikqTih629Q.png" /><figcaption>Model Definition</figcaption></figure><p>I highly recommend you try to change it as default, where you use the linear function <strong>w0 * x + b.</strong></p><h3>4. Custom Model</h3><p>Let’s create a custom <a href="https://towardsdatascience.com/vgg-neural-networks-the-next-step-after-alexnet-3f91fa9ffe2c">VGG model</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/0*hGbWyJrgw9o_70l0.png" /><figcaption>VGG Model — source: <a href="https://paperswithcode.com/method/vgg">https://paperswithcode.com/method/vgg</a></figcaption></figure><p>I’ll first create a Layer that has <strong>Max Pooling + k * Convolution + ReLU. </strong>Then I’ll create the whole model by repeating it and giving how much convolution layer I want.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*SWc_KsFQ0x266UEPTnVAFg.png" /><figcaption>Definition of a VGG Block</figcaption></figure><p>After I defined the Block, I’ll create the MyVGG model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*YNBPUQ1PNLiCZlHJInKxCA.png" /><figcaption>MyVGG Model Definition</figcaption></figure><p>Thus we can customize our model by giving different filters and repetitions to Block or changing the last layers of the VGG. We can customize it as we want, but if you define another layer just don’t forget to call it in the call function otherwise it’ll not change.</p><p>And that was the last one. In the last couple of weeks, I’ve finished the <a href="https://www.coursera.org/specializations/tensorflow-advanced-techniques">TensorFlow: Advanced Techniques Specialization</a> and most of the source code of this article is from the assignments in the course. They have great courses, I highly recommend them to everyone. You can check the all codes from my Github.</p><p><a href="https://github.com/SalihTalha/tensorflow_notes/tree/main/coursera%20assignments">tensorflow_notes/coursera assignments at main · SalihTalha/tensorflow_notes</a></p><p>Ask me if you have any questions. Please give your feedback. Thank you for reading to the end.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dae0dcc693bd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/carbon-consulting/custom-training-with-tensorflow-in-python-dae0dcc693bd">Customizing Training with TensorFlow in Python</a> was originally published in <a href="https://medium.com/carbon-consulting">CARBON CONSULTING</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>