<?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: Mizuno Sutoiko</title>
    <description>The latest articles on DEV Community by Mizuno Sutoiko (@mizunosutoiko).</description>
    <link>https://dev.to/mizunosutoiko</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%2F1216623%2Ff74ad9e4-6962-4369-a93b-7a44ed54d196.png</url>
      <title>DEV Community: Mizuno Sutoiko</title>
      <link>https://dev.to/mizunosutoiko</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mizunosutoiko"/>
    <language>en</language>
    <item>
      <title>🌊 How to navigate a monotonous Job?</title>
      <dc:creator>Mizuno Sutoiko</dc:creator>
      <pubDate>Mon, 14 Oct 2024 23:44:39 +0000</pubDate>
      <link>https://dev.to/mizunosutoiko/focus-on-what-you-like-3d9b</link>
      <guid>https://dev.to/mizunosutoiko/focus-on-what-you-like-3d9b</guid>
      <description>&lt;p&gt;&lt;em&gt;Be like water my friend.&lt;/em&gt;&lt;br&gt;
&lt;em&gt;Bruce Lee&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;How great it would be if everyone have a meaningful job, something that we truly like, with a good enough pay, and doing things that solve real world problems, or at least problems of our interest.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Most of us will have undoubtedly boring, simple, or pointless jobs&lt;/strong&gt;. The professionals that end up doing what they studied for are scarce, and ultimately if they get a job on their area of interest, it would be a job with a lower pay, doing the boring things that their more senior peers don't want to do, or things that only benefit a few people.&lt;/p&gt;

&lt;p&gt;This post is an analysis of some options to consider if we are not where we want to be, the options are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Adapt.&lt;/li&gt;
&lt;li&gt;Have a side project.&lt;/li&gt;
&lt;li&gt;Merge your purpose with your job.&lt;/li&gt;
&lt;li&gt;Change jobs.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's check them!&lt;/p&gt;

&lt;h2&gt;
  
  
  Adapt
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F19go1lsj4jaidhzp3vsb.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F19go1lsj4jaidhzp3vsb.jpg" alt="Glass of water with a plant growing inside" width="640" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A boring job that pay the bills is a great job, since it is not as sexy, there would be fewer people studying to work on the same thing, you'll have less competence, and if it's easy, you'll excel doing some simple things, there are not many cons of that job.&lt;/p&gt;

&lt;p&gt;Society needs this monotony to work as it works today, most boring jobs are necessary and the fact that you are doing them means that you are contributing to something bigger than yourself.&lt;/p&gt;

&lt;p&gt;You may not be living to your fully potential, you may not be working on something that interest you, and you may not be happy in the long run when you look back and that job was the only thing that you did for the past 10 years.&lt;/p&gt;

&lt;p&gt;But these kind of jobs could be what you need to support a family, yourself, to have more free time, and to gain the financial security for the other things that matter the most to you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Flowing and adapting to a boring job requires a lot of resilience and discipline&lt;/strong&gt;, and ultimately, when you become too good at something, either you start again in something that you don't know how to do, or you adapt to the predictability of the job where you gained such mastery.&lt;/p&gt;

&lt;p&gt;To be happy and fulfill you just have to be grateful with what you have and what you've done, probably you'll still remember your job, if you are mindful at it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Have a side project
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Frautirilc0038ll28jjb.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Frautirilc0038ll28jjb.jpg" alt="Two mushrooms growing side by side" width="640" height="426"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It will be hard, it will require additional time, and it could lead to nowhere, but &lt;strong&gt;doing something that you enjoy will give you a feeling that otherwise would be difficult to get, and that's enough&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If the side project is focused on a skill that you want to improve, if it could give you additional money in the future, or if you are helping someone while doing so, it is a great plus.&lt;/p&gt;

&lt;p&gt;You may be wondering if this could make your days easier or calmer in the future, don't think so. It is possible that you end up working a lot more, making your life unbalanced, sacrificing your free time, and being exhaust at nights, you can sort this out by being organized and having good habits, but it will be hard still.&lt;/p&gt;

&lt;p&gt;The good thing is that even if you are working more and unbalancing your life, you'll look back and have something to remember, lessons, failures, hard nights, dummy projects and bad decisions, but something to remember anyways.&lt;/p&gt;

&lt;p&gt;Focusing on a side project where you do few things you like or want may be great to remember your days more and build something in the long run, you can use your vacations to work on it deeply.&lt;/p&gt;

&lt;h2&gt;
  
  
  Merge your purpose with your job
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F4xkntk3j2zq0b3894fv6.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F4xkntk3j2zq0b3894fv6.jpg" alt="Three waterfalls merging" width="640" height="427"&gt;&lt;/a&gt;&lt;br&gt;
If you decided to have a side project, or improve your skills outside of work, you could be a bit sparse hoping to get out of the office so you could work on your purpose, this is a good signal, you are enjoying it, but most of the day you are still working.&lt;/p&gt;

&lt;p&gt;One awesome alternative is to &lt;strong&gt;look for ways to apply your recently acquired knowledge, or skills of the project you were doing into your current job&lt;/strong&gt;. For example, if your project is about looking for duplicate images in your Phone photos, you could end up using a Dhash or something related to drop similar images, that knowledge could be useful for a project at work.&lt;/p&gt;

&lt;p&gt;Another example could be that your project is about writing a blog, writing skills are really useful to interact with colleages, make documentation for your repos, or presenting new ideas to customers.&lt;/p&gt;

&lt;p&gt;By merging both, you make your job more exciting bit by bit, however, if the two things are totally unrelated, your boss is close minded, or your team doesn't endorse your new contributions, you can try the last option.&lt;/p&gt;

&lt;h2&gt;
  
  
  Change jobs
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Foxcq9uy9kquypmfxabhz.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Foxcq9uy9kquypmfxabhz.jpg" alt="Surfing inside a big wave" width="640" height="427"&gt;&lt;/a&gt;&lt;br&gt;
I put this one as the last option, since the process of changing companies or teams, and starting all over again could be challenging, but &lt;strong&gt;if you feel that the current place where you are isn't aligned with your long-term goals&lt;/strong&gt;, you tried to adapt but still there are plenty of things that you want to improve in your team, or you see that there are much better opportunities somewhere else, this would be a nice option to consider.&lt;/p&gt;

&lt;p&gt;It has a great luck factor on it that you can diminish if you know:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The projects that you're going to be working on.&lt;/li&gt;
&lt;li&gt;Your teammates attitude and enjoyment of the day-to-day work.&lt;/li&gt;
&lt;li&gt;The growth roadmap.&lt;/li&gt;
&lt;li&gt;The necessary skillset.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With that info you can be sure of what to expect at the new team/company that you choose, and if that is your own company as a result of a successful side project, those questions could be great to answer to create a great company culture.&lt;/p&gt;

&lt;p&gt;Since this is the harder and more risky choice, you'll never be sure of what to expect, but if you arrive to a monotonous job again, you can read this article one more time 😅.&lt;/p&gt;

&lt;p&gt;A good signal is that after making the choice you feel a lot better everyday, and you are eager to learn new things at the new place, this is awesome and I hope that this happens to you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cross tips
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fgr02b9pmzwfbw3ev3jzu.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fgr02b9pmzwfbw3ev3jzu.jpg" alt="Two blue wooden chairs in the beach" width="640" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Talk about it
&lt;/h3&gt;

&lt;p&gt;You can &lt;strong&gt;talk about the monotony of your job with someone&lt;/strong&gt;, usually other people have monotonous jobs too, so you could support each other, give advice, or simply express how you feel. &lt;/p&gt;

&lt;p&gt;Writing about it could be great too!&lt;/p&gt;

&lt;h3&gt;
  
  
  Create good habits
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Good habits will give you the energy to tackle a side project or your main work&lt;/strong&gt;, that's a fact.&lt;/p&gt;

&lt;p&gt;A small exercise routine everyday, active pauses, reading, sleeping for at least 8 hours, eating less sugar and going outside are good habits that could improve how we feel during the day.&lt;/p&gt;

&lt;p&gt;Also, having an hour to start working, and an hour to stop working is essential to maintain a good pace.&lt;/p&gt;

&lt;p&gt;There are other good habits and tips that can be found in the &lt;em&gt;Atomic Habits Book&lt;/em&gt;. &lt;/p&gt;

&lt;h3&gt;
  
  
  Navigate with someone else
&lt;/h3&gt;

&lt;p&gt;Navigating a monotonous project could seem like being in calm waters, but in reality there is a lot of turbulence, specially in our minds. &lt;/p&gt;

&lt;p&gt;It is easier to lost focus, to feel unproductive, and to stop working altogether due to a lack of motivation, so you'll look like a kid in a small pool, but your mind would be like the cover image of the post!&lt;/p&gt;

&lt;p&gt;One way to calm down is: &lt;strong&gt;anything that you choose to do from the above list, do it with someone else.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you want to adapt to the current project, if you want to have a side project, if you want to merge your purpose with your job, or if you want to change jobs, do that while sharing the decisions or the results with someone else.&lt;/p&gt;

&lt;p&gt;A fellow navigator could be helpful to work asynchronously, to make difficult decisions, to help with parts of the project that you don't know how to do yet, so if you can, don't do it alone.&lt;/p&gt;

&lt;p&gt;Even if you don't talk about work at all, simply doing plans with friends or hanging out with coworkers will do the trick, you may still have the same problems, but &lt;strong&gt;sharing experiences makes the trip a lot easier.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Don't forget to have fun! ⛵🌟&lt;/p&gt;

</description>
      <category>career</category>
      <category>learning</category>
    </item>
    <item>
      <title>Vector Search pt. 3 - Retrieval Systems 🌌</title>
      <dc:creator>Mizuno Sutoiko</dc:creator>
      <pubDate>Sat, 06 Jul 2024 17:16:15 +0000</pubDate>
      <link>https://dev.to/mizunosutoiko/vector-search-pt-3-retrieval-systems-3598</link>
      <guid>https://dev.to/mizunosutoiko/vector-search-pt-3-retrieval-systems-3598</guid>
      <description>&lt;p&gt;If we try to remember, or retrieve something from our memory, we have to navigate the neural circuits in our brains in order to come up with the thing that we were trying to remember.&lt;/p&gt;

&lt;p&gt;Our neurons activate in multiple established patterns that brings us a concept, if that concept is close to the thing that we want to remember we keep it, if not, we discard it and came up with another thing.&lt;/p&gt;

&lt;p&gt;Here a particular thing that kind of align with this article is the difference on remembering things when we are focused or relaxed. When we are focused, we tend to narrow a lot the things in our remembering space, if we are relaxed, we have a broader remembering space, maybe take more time to remember something, but it is more probable to retrieve it at the end.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fa4852f8vwq8nnogcveu6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fa4852f8vwq8nnogcveu6.png" alt="Image of a multiple neural circuits activated to remember something, small variations in neurons will give us variations in the remembered thing, depending the focus or disperse modes" width="800" height="371"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The thing is that there are some algorithms that use similar approaches to retrieve things that are close to the one that we are looking for. &lt;/p&gt;

&lt;p&gt;Those algorithms are the &lt;strong&gt;Vector Retrieval Algorithms&lt;/strong&gt;, they are at the heart of multiple search engines, ranking results based on similarity.&lt;/p&gt;

&lt;p&gt;Here we'll try to explain them a bit.&lt;/p&gt;

&lt;h2&gt;
  
  
  Search Indexes
&lt;/h2&gt;

&lt;p&gt;Search Indexes could be treated as a sorting algorithm for Vectors, they sort based on the similarity with respect to the input Vector.&lt;/p&gt;

&lt;p&gt;So this algorithm will receive an input Vector, then it will compute the similarity between it and others, and finally it will return the identifiers of most similar vectors, as simple as that.&lt;/p&gt;

&lt;p&gt;An algorithm that will compute the similarity between the input vector and all the other ones in the Database is called a Brute Force algorithm, as it compute similarity to all vectors, then sort them.&lt;/p&gt;

&lt;p&gt;There are other algorithms that make this process a bit (or a lot) more complex, those are very sophisticated algorithms which could be better approaches than brute-force (most of the time).&lt;/p&gt;

&lt;p&gt;Great examples of those algorithms are &lt;a href="https://github.com/facebookresearch/faiss/wiki/Faiss-indexes#cell-probe-methods-indexivf-indexes" rel="noopener noreferrer"&gt;IVF&lt;/a&gt; (Inverted File), and &lt;a href="https://github.com/facebookresearch/faiss/wiki/Faiss-indexes#indexhnsw-variants" rel="noopener noreferrer"&gt;HNSW&lt;/a&gt; (Hierarchical Navigable Small World)&lt;/p&gt;

&lt;p&gt;To understand this better, I'll be using a similar metaphor to the one introduced in the &lt;a href="https://huggingface.co/learn/computer-vision-course/unit1/feature-extraction/feature-matching" rel="noopener noreferrer"&gt;HuggingFace Computer Vision Course&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  IVF based algorithms
&lt;/h3&gt;

&lt;p&gt;This kind of algorithm tries to breakdown the Vector Space in Cells, each cell will have a centroid, and that centroid is calculated using only the Vectors inside that cell.&lt;/p&gt;

&lt;p&gt;So imagine that you have a lot of puzzle pieces in the floor, they could be of the same puzzle or they could be from different ones. The goal for you is to find a piece that you need (maybe for solving another puzzle), and you'll look up for it using this IVF based algorithm.&lt;/p&gt;

&lt;p&gt;In contrast to brute Force where the puzzle pieces are sparse in the floor, and you go piece by piece checking wether it is useful to you or not, the IVF based algorithm organizes the pieces in groups based on the similarity between them, and compute a &lt;em&gt;centroid piece&lt;/em&gt; that you can use to check wether that group of pieces could be useful or not.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F9veol93wj4m3uclzb4zw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F9veol93wj4m3uclzb4zw.png" alt="Image of the puzzle pieces space divided into voronoi cells" width="800" height="801"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At search time, we check if a centroid piece or multiple centroid pieces are somewhat similar to what we are looking for, then after finding most similar centroid pieces, we start looking for the piece that we need inside its group, so instead of searching piece by piece, we'll be searching just in the groups where the centroid piece is most similar to the piece that we have in mind.&lt;/p&gt;

&lt;p&gt;This method is very fast, and depending on the number of centroid pieces and comparisons performed at search time (we could check inside one or multiple groups), we could have high precisions when searching for pieces.&lt;/p&gt;

&lt;p&gt;Remember that the similarity between pieces is calculated using the features previously extracted, those features could be based on the form, image of the piece, color, size, etc... And they are all saved in a vector form (embedding).&lt;/p&gt;

&lt;h3&gt;
  
  
  HNSW based algorithms
&lt;/h3&gt;

&lt;p&gt;These algorithms are very precise when retrieving the similar pieces. They organize the pieces in a graph-like form making them faster than brute force, and almost as precise when searching.&lt;/p&gt;

&lt;p&gt;The below explanation will combine the puzzle metaphor with &lt;a href="https://towardsdatascience.com/similarity-search-part-4-hierarchical-navigable-small-world-hnsw-2aad4fe87d37" rel="noopener noreferrer"&gt;this detailed article on HNSW algorihms&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The HNSW algorithm would be like having multiple levels of the puzzle pieces. Originally you'll have all the pieces organized in a way that similar pieces are connected by strings little strings (I could not come out with a better methaphor 😅) so the pieces and the strings form something like a graph, but the magic of this algorithm comes from having &lt;em&gt;layers&lt;/em&gt; of strings.&lt;/p&gt;

&lt;p&gt;Imagine that the string's layer could be defined by the diameter of the string (or its color), so there are pieces that have strings of multiple diameters.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fpguhwokcvqkq042m6x0c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fpguhwokcvqkq042m6x0c.png" alt="Image of the space divided into nodes on different layers" width="800" height="702"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you are looking for a puzzle piece you could start anywhere in that pieces and strings mesh, but you'll start looking just at the pieces connected with the thicker strings, after finding the most similar piece connected to the thicker strings, you'll start to look for the next thiner group of string connected pieces, that were connected to that most similar piece with the tickest string, and you continue doing this process until you have looked up in all the string's thick levels, or you've find a good enough piece.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Feqsxoz6kpm4x1i65jpzs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Feqsxoz6kpm4x1i65jpzs.png" alt="Image of the search process" width="800" height="518"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This process is more slow and requiers more memory than the IVF process, and it also consume more memory than the brute force algorithm, because this algorithm have to save all those strings (edges) that connect the pieces (vectors of features), but the results are more precise than the IVF algorithm, and faster than the brute force algorithm.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Having the fundamentals of what is a feature, how to extract Image based features, and how can we lookup for things in a very efficient way, we can now understand how the retreival systems of Google, Netflix, Youtube, Pinterest, and our brains (not so much) work in general.&lt;/p&gt;

&lt;p&gt;The full process would be something like:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Adding the Vectors to the database:&lt;br&gt;
&lt;a href="https://media2.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%2Fyct9ux2xhio4tla7akua.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fyct9ux2xhio4tla7akua.png" alt="Creating the search space" width="800" height="223"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Extracting the Features of the thing to search:&lt;br&gt;
&lt;a href="https://media2.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%2Fec0qqltfggehz5msb2ys.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fec0qqltfggehz5msb2ys.png" alt="Getting Image Features using an Algorithm" width="800" height="237"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Performing the search using a Vector Retrieval algorithm:&lt;br&gt;
&lt;a href="https://media2.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%2Fjbfu4dc691qsf2t3f7vm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fjbfu4dc691qsf2t3f7vm.png" alt="Retrieval process of a given image" width="800" height="445"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And that's it!☀️&lt;/p&gt;

&lt;p&gt;All the articles have links and materials to keep deepeing our knowledge and as the HNSW algorithms explained here that way we'll have more puzzle pieces to retrieve knowledge from, and being better developers.&lt;/p&gt;

&lt;p&gt;I hope you've learned something from this short and sparse series. And if you have suggestions or corrections, let me know.&lt;/p&gt;

&lt;p&gt;Happy coding! 😎&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>vectordatabase</category>
    </item>
    <item>
      <title>Vector Search pt. 2 - Vision Algorithms 🎑</title>
      <dc:creator>Mizuno Sutoiko</dc:creator>
      <pubDate>Tue, 21 May 2024 23:57:26 +0000</pubDate>
      <link>https://dev.to/mizunosutoiko/vector-search-pt-2-vision-algorithms-4ocn</link>
      <guid>https://dev.to/mizunosutoiko/vector-search-pt-2-vision-algorithms-4ocn</guid>
      <description>&lt;p&gt;If we want to add thousands of items with their respective vectors to a table, do we have to think and input these similarities one by one? 😓&lt;/p&gt;

&lt;p&gt;There are some algorithms that convert things from the real world, to vectors in a multidimensional space, for example, if i pass the image of a King, the algorithm will convert that image to a point in a space with numeric coordinates. These types of algorithms are called Feature Extractors, and could extract the vectors from Images, Texts, Voices, and more.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fr29jdd5ikryag3150n1u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fr29jdd5ikryag3150n1u.png" alt="General Process" width="800" height="152"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The algorithms that could be used to understand the world could be Vision Algorithms, text Algorithms, sound algorithms, and Multimodal Algorithms.&lt;/p&gt;

&lt;p&gt;Here we'll review the concept of Vision Algorithms, and hopefully in other articles we'll review the other types, also there will be some references to algorithms that you can explore and use for your own projects.&lt;/p&gt;

&lt;p&gt;To make things a bit more intuitive we'll try to explain how ourselves as humans understand the world based on features.&lt;/p&gt;

&lt;h2&gt;
  
  
  How we get the features of the world? 🌍
&lt;/h2&gt;

&lt;p&gt;The world is a place full of sounds, colors, textures, flavors, as other sensations, and we have multiple ways of sensing it, we use our eyes, ears, tongue, skin, nose, and brain. &lt;/p&gt;

&lt;p&gt;Our senses collect the information about the world, our brain interpret that information by doing a mental map and matching that map with previous learned maps, these maps are wired in us, in our neurons.&lt;/p&gt;

&lt;p&gt;For example, each time we hear a dog barking, we match that sound to the concept of dog, and we could visualize the dog, or even remember how a dog smells.&lt;/p&gt;

&lt;p&gt;But the most interesting part is that those mental maps could be shared among things that we don't fully know, giving us the ability to generalize to a lot of things.&lt;/p&gt;

&lt;p&gt;For example, if we see a picture of a Wolf or hear it howling, we can undestand that those signals come from a wolf, even if we just watched them from the TV. &lt;/p&gt;

&lt;p&gt;Since Wolfs and Dogs look similar to us but are not the same, we could infer that the neural circuit of both concepts is very similar, but due to a small difference in the neuron activations, our brains know that they are not fully the same things.&lt;/p&gt;

&lt;p&gt;This special feature of our brains allows us to infer that wolfs could bite, run very fast, and like meat, just like dogs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F96sarsqvtu8d63ta1o43.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F96sarsqvtu8d63ta1o43.png" alt="Neural mapping" width="800" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So given this ability of us, one could ask the question:&lt;br&gt;
Could this process be replicated by a computer?&lt;/p&gt;

&lt;p&gt;If it is possible, we could make a computer understand that a dog and a wolf are similar concepts, just by using words, sounds, or images!&lt;/p&gt;

&lt;h2&gt;
  
  
  Vision Algorithms 📷
&lt;/h2&gt;

&lt;p&gt;To make computers understand Image Data, we came up with this fascinate set of algorithms called Vision Algorithms. Classically they were used to detect borders, corners, letters, color histograms, etc, but these days they are used to a broad range of applications thanks to DeepLearning.&lt;/p&gt;

&lt;p&gt;The multiple types of vision algorithms usually work with a Camera as the Sensor, and the algorithm will look for shapes, colors, or textures, patterns in general to understand the captured image.&lt;/p&gt;

&lt;p&gt;The camera would be like the Eyes of the system, and the algorithm would be like the brain, it will match the sensed signal with a previous pattern or condition and will return something.&lt;/p&gt;

&lt;p&gt;The modern image algorithms for feature extraction usually are based on deeplearning, they use something called convolutions to extract important landmarks of the images sequentially and finally compress the most important landmarks into a feature vector, but overall they could be oversimplified by something like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fzwzmkqmwsy2uiv9vk20a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fzwzmkqmwsy2uiv9vk20a.png" alt="Convolve learned patterns with an Image" width="800" height="223"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These modern algorithms could be trained in two common ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Supervised.&lt;/li&gt;
&lt;li&gt;Semi-supervised/Self-supervised.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Supervised
&lt;/h3&gt;

&lt;p&gt;The supervised method to train feature-extractors consist of training a Convolutional model to classify an image into one of several labels. &lt;/p&gt;

&lt;p&gt;One common set of labels are the ones of the ImageNet Dataset, which contains 1000 object classes. After training the algorithm with the imageNet data, we get the extractor part from the full model.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F8o010d4avnu0mfevhyke.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F8o010d4avnu0mfevhyke.png" alt="Classification model with the Feature Extractor Part highlighted" width="800" height="232"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, the Feature Extractor Part could be used to get the Embeddings in the latent space. &lt;/p&gt;

&lt;p&gt;This is the method used for the &lt;a href="https://pytorch.org/hub/pytorch_vision_mobilenet_v2/" rel="noopener noreferrer"&gt;MobileNets&lt;/a&gt;, &lt;a href="https://pytorch.org/hub/nvidia_deeplearningexamples_efficientnet/" rel="noopener noreferrer"&gt;EfficientNets&lt;/a&gt;, and &lt;a href="https://pytorch.org/hub/pytorch_vision_alexnet/" rel="noopener noreferrer"&gt;ALexNet&lt;/a&gt; Models.&lt;/p&gt;

&lt;h3&gt;
  
  
  Semi-supervised/Self-supervised
&lt;/h3&gt;

&lt;p&gt;These methods consist on using an untrained model with an error function (measurement of correctness) based on Contrastive Loss.&lt;/p&gt;

&lt;p&gt;The Contrastive Loss is used to measure how similar 2 vectors are in latent space(vector space), it is useful for checking the similarity between any kind of vector, even if they were extracted using different approaches.&lt;/p&gt;

&lt;p&gt;Here we'll explain how to use this method using only images.&lt;/p&gt;

&lt;p&gt;Basically the approach using only images is called &lt;a href="https://arxiv.org/abs/2002.05709" rel="noopener noreferrer"&gt;SimCLR&lt;/a&gt; and consist on doing some kind of perturbation on a given Image, then, compute its embedding, and finally, check with the contrastive loss how similar is the embedding of the perturbed image to the embedding of the original unperturbed image.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fxn4xpznuzu91s0okzm2b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fxn4xpznuzu91s0okzm2b.png" alt="SimCLR Method explanation extracted from the DeepLearning with Pytorch Course" width="800" height="345"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The magnitude of the difference will be used to update the Feature-extractor model. Over time the model will be trained, using just multiple images and their perturbed twins, it is very useful when we don't have lots of labeled data.&lt;/p&gt;

&lt;p&gt;Other contrastive Learning techniques could be used with embeddings from images, text, audio, etc. It is the key component behind multimodal models, and probably we'll review it in a future article.&lt;/p&gt;

&lt;h2&gt;
  
  
  Image-based Latent Space
&lt;/h2&gt;

&lt;p&gt;The latent space is the space where images are represented by their vectors, after extracting the features of a given set of images we'll get a latent space.&lt;/p&gt;

&lt;p&gt;Remember the previus article how there was a space of fruits and a royal family?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fj52r1b1nu47rjbdu3oy7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fj52r1b1nu47rjbdu3oy7.png" alt="Latent space of fruits and royal people" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That space could be obtained using a lot of images of those concepts and extracting their Feature Vectors.&lt;/p&gt;

&lt;p&gt;If we have a well trained algorithm with also some animals, and a deep understanding of them, we could use that Vision Algorithm to get the vector in the latent space of a little Monkey, and we'll obtain something like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fow9up4gugsdp37ju74ow.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fow9up4gugsdp37ju74ow.png" alt="Obtaining the feature vector of a little monkey and putting it on the latent space of the previous article" width="800" height="248"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That way the Monkey concept obtained from passing a monkey image into a Vision Model would be somewhat close to a banana, and also close to the King and Queen concepts, since we are all mammals. &lt;/p&gt;

&lt;p&gt;Isn't it awesome?&lt;/p&gt;

&lt;p&gt;Businesses use this algorithms all the time, for extracting products embeddings, like clocks, toys, shoes, etc. Used in conjunction with retrieval systems one could find things that are similar in the feature space using just images!&lt;/p&gt;

&lt;h2&gt;
  
  
  Closing
&lt;/h2&gt;

&lt;p&gt;We've seen that we can represent concepts in a N-dimensional space using only images, and the algorithms mimics in some way what the brain does.&lt;/p&gt;

&lt;p&gt;I hope you've learned something new from this article, and I'll be glad if you send me your questions, correct me, or simply comment what do you think of it! 💯&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pd&lt;/strong&gt;&lt;br&gt;
The Next post could be an overview about multimodal Feature-Extractors, or the main concepts behind vector Retrieval Systems. I haven't decided yet.😅&lt;/p&gt;

&lt;p&gt;And since I'm kind of slow to write these kind of articles, I could be posting some non-technical ones in the meantime.&lt;/p&gt;

&lt;p&gt;So, take care, and keep learning!&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>computervision</category>
    </item>
    <item>
      <title>Vector Search pt. 1 - Features 🪵</title>
      <dc:creator>Mizuno Sutoiko</dc:creator>
      <pubDate>Mon, 18 Dec 2023 02:46:23 +0000</pubDate>
      <link>https://dev.to/mizunosutoiko/vector-search-pt-1-features-22dm</link>
      <guid>https://dev.to/mizunosutoiko/vector-search-pt-1-features-22dm</guid>
      <description>&lt;p&gt;I'd never asked myself how Google, Youtube, Pinterest, or Netflix perform their searches. I was just using those services to lookup for information, shows, or images, but without even consider the underlying technology behind them, and I really didn't care. &lt;/p&gt;

&lt;p&gt;That was until I encountered the concept of &lt;strong&gt;Vector Search&lt;/strong&gt;, a concept so deeply grained in ourselves that when you get to know it, you start looking at things in very different ways.&lt;/p&gt;

&lt;p&gt;This concept could be used to explain on a high level how retrieval systems work, how Facebook matches friends together, and even how we understand the world around ourselves.&lt;/p&gt;

&lt;p&gt;This article is part of a series that aims to bring light to such an interesting concept that we all know and use, but very few of us really understand.&lt;/p&gt;

&lt;p&gt;And also, how companies or individuals could use it to offer a higher value in their services.&lt;/p&gt;

&lt;p&gt;Let's get started! &lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Feature?
&lt;/h2&gt;

&lt;p&gt;Straight to the point, a feature is a characteristic that we use to describe something. The typical examples would be, that the apples (🍎) are red, a King (🤴) is a person, etc, but if we really want to go into a deeper level, we would need longer descriptions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An Apple (🍎) is a &lt;em&gt;fruit&lt;/em&gt; that could have three different colors, &lt;em&gt;red&lt;/em&gt;, &lt;em&gt;green&lt;/em&gt;, and &lt;em&gt;yellow&lt;/em&gt;, is a bit &lt;em&gt;sweet&lt;/em&gt;, and it is a great source of &lt;em&gt;fiber&lt;/em&gt; and &lt;em&gt;vitamins&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;A King (🤴) is a &lt;em&gt;person&lt;/em&gt; in position of &lt;em&gt;power&lt;/em&gt;, who is usually the &lt;em&gt;husband&lt;/em&gt; of a Queen. They live in &lt;em&gt;castles&lt;/em&gt; and wear a &lt;em&gt;crown&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If we want to add those descriptions to a table, for the first descriptions, we could have two columns, one for the name, and one for the description. To find something, we just do a column filter and search for the words &lt;em&gt;person&lt;/em&gt; or &lt;em&gt;red&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;The problem with the simple descriptions is that they would only work in a world with few objects, and in real life we should consider descriptions like the second ones to really differentiate things. There are lots of &lt;em&gt;red&lt;/em&gt; stuff, and there are hundreds of types of &lt;em&gt;persons&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;But, we can't put those long texts in a table and expect to filter them like that, we need to organize the information in the key words.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;Apple&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;fruit&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;red&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;green&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;yellow&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;sweet&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;fiber&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;vitamins&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;King&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;person&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;power&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;husband&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;castle&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;crown&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we add more objects like bananas and Queen, we could do something similar:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;Banana&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;fruit&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;yellow&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;sweet&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;fiber&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;vitamins&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;Queen&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;person&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;power&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;wife&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;castle&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;crown&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As humans, we understand the concepts behind those words without even thinking about it, because we have encountered them in real life so many times that describing them becomes easy. &lt;/p&gt;

&lt;p&gt;We know that Bananas, apples, watermelons, and strawberries are somewhat more related among them than with other concepts like King, which would be more related to Queen a lot more than it is to apples. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fkwb61uarhlxz5epofdqx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fkwb61uarhlxz5epofdqx.png" alt="Bananas, apples, watermelons, strawberries, king, and queen represented in some kind of space" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That knowledge is encoded in our brains. The name for that understanding is known as &lt;strong&gt;Semantics&lt;/strong&gt;, the relation between a concept and its meaning.&lt;/p&gt;

&lt;p&gt;Going back to the imaginary table, if you try to figure out how to save and filter features to finally obtain one single thing, you could get to a very important question:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If we want to add a lot of objects, people, landscapes, animals, and fruits, it wouldn't be possible to directly add that many descriptions in columns, so how could we do it?&lt;/em&gt;🤔 &lt;/p&gt;

&lt;p&gt;That's a real problem in Computer Science, and probably I won't answer it in the best possible way, but one solution could be: &lt;em&gt;Simplifying&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Simplifying our understanding of the world using Features
&lt;/h2&gt;

&lt;p&gt;If we compare the two descriptions given at the beginning of this article we would note that the first was oversimplified, but the second one was not.&lt;/p&gt;

&lt;p&gt;In real life scenarios, we should come up with multiple options to summarize characteristics, for example: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;name, color, gender&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;cell_type, is_human, lives_in_castle&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Looking for some mid-point, we could use both for our data, organize the information in a table, and get something like:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;word&lt;/th&gt;
&lt;th&gt;color&lt;/th&gt;
&lt;th&gt;gender&lt;/th&gt;
&lt;th&gt;cell_type&lt;/th&gt;
&lt;th&gt;is_human&lt;/th&gt;
&lt;th&gt;lives_in_castle&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Apple&lt;/td&gt;
&lt;td&gt;red&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;plant&lt;/td&gt;
&lt;td&gt;False&lt;/td&gt;
&lt;td&gt;False&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Banana&lt;/td&gt;
&lt;td&gt;yellow&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;plant&lt;/td&gt;
&lt;td&gt;False&lt;/td&gt;
&lt;td&gt;False&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;King&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;male&lt;/td&gt;
&lt;td&gt;animal&lt;/td&gt;
&lt;td&gt;True&lt;/td&gt;
&lt;td&gt;True&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Queen&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;female&lt;/td&gt;
&lt;td&gt;animal&lt;/td&gt;
&lt;td&gt;True&lt;/td&gt;
&lt;td&gt;True&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This way if we want to perform a search, create groups, or keep adding more diverse things, the summary of features will scale up, but... How much?&lt;/p&gt;

&lt;h2&gt;
  
  
  Summarizing the features even more
&lt;/h2&gt;

&lt;p&gt;First of all, if we want to really scale things up, we would need a little help describing things. Choosing a set of characteristics that could be enough to summarize any object would be a very demanding task, and depending on the items it probably will change over time.&lt;/p&gt;

&lt;p&gt;One interesting solution to this problem is to select pivot items, and score the similarity of any new item to those pivot items.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; A pivot here is like a reference point (⛳️), it allows us to guide ourselves in a space that is not well defined. &lt;/p&gt;

&lt;p&gt;Let's choose the apple and the King as pivot items, we could add more objects and then create a similarity table:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;word&lt;/th&gt;
&lt;th&gt;Apple&lt;/th&gt;
&lt;th&gt;King&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;King&lt;/td&gt;
&lt;td&gt;0.0&lt;/td&gt;
&lt;td&gt;1.0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Queen&lt;/td&gt;
&lt;td&gt;0.0&lt;/td&gt;
&lt;td&gt;0.8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Apple&lt;/td&gt;
&lt;td&gt;1.0&lt;/td&gt;
&lt;td&gt;0.0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Banana&lt;/td&gt;
&lt;td&gt;0.8&lt;/td&gt;
&lt;td&gt;0.0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dog&lt;/td&gt;
&lt;td&gt;0.2&lt;/td&gt;
&lt;td&gt;0.4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Woman&lt;/td&gt;
&lt;td&gt;0.1&lt;/td&gt;
&lt;td&gt;0.6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Watermelon&lt;/td&gt;
&lt;td&gt;0.8&lt;/td&gt;
&lt;td&gt;0.0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Strawberry&lt;/td&gt;
&lt;td&gt;0.7&lt;/td&gt;
&lt;td&gt;0.0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;em&gt;Note that the similarity here is subjective&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We summarized 5 feature columns in just 2, and we achieved something that will benefit us later, assessing &lt;strong&gt;numerically&lt;/strong&gt; the similarity to each of the pivots.&lt;/p&gt;

&lt;p&gt;This way we could sort the items accordingly to the similarity to each of the pivots, for example, let's sort things up depending on the similarity to the concept of King:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;word&lt;/th&gt;
&lt;th&gt;Apple&lt;/th&gt;
&lt;th&gt;King&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;King&lt;/td&gt;
&lt;td&gt;0.0&lt;/td&gt;
&lt;td&gt;1.0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Queen&lt;/td&gt;
&lt;td&gt;0.0&lt;/td&gt;
&lt;td&gt;0.8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Woman&lt;/td&gt;
&lt;td&gt;0.1&lt;/td&gt;
&lt;td&gt;0.6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dog&lt;/td&gt;
&lt;td&gt;0.2&lt;/td&gt;
&lt;td&gt;0.4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Apple&lt;/td&gt;
&lt;td&gt;1.0&lt;/td&gt;
&lt;td&gt;0.0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Banana&lt;/td&gt;
&lt;td&gt;0.6&lt;/td&gt;
&lt;td&gt;0.0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Watermelon&lt;/td&gt;
&lt;td&gt;0.8&lt;/td&gt;
&lt;td&gt;0.0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Strawberry&lt;/td&gt;
&lt;td&gt;0.7&lt;/td&gt;
&lt;td&gt;0.0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;You could start to see how easy it is to keep adding items, and sorting them depending on their subjective similarity to the pivots. Those pivots could be interpreted as dimensions in a 2 dimensional plane, that means that each word could have a magnitude (lenght) and a direction in that plane! Something with those characteristics is known as a &lt;strong&gt;Vector&lt;/strong&gt;, for now we'll keep plotting them as points.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fen9xtdhdr5pdcdj4juap.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fen9xtdhdr5pdcdj4juap.png" alt="2D Plane with King and apple in its axes" width="800" height="507"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, we can use sorting algorithms, instead of just filtering. We are able to find things more easily in the data, and define a similarity threshold to exclude the things that aren't of interest to us.&lt;/p&gt;

&lt;p&gt;But, If we want to add thousands of items with their respective vectors to our table, do we have to think and input these similarities one by one? 😓&lt;/p&gt;

&lt;p&gt;This question would be answered in the next part! &lt;/p&gt;

&lt;p&gt;We'll see how can we create these tables for any object, and how a computer could enhance our experience while doing it!&lt;/p&gt;

&lt;p&gt;See you soon! 😎 &lt;/p&gt;

</description>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Improve your Python Skills with Classes, decorators, and implicit parameters</title>
      <dc:creator>Mizuno Sutoiko</dc:creator>
      <pubDate>Fri, 01 Dec 2023 03:45:11 +0000</pubDate>
      <link>https://dev.to/mizunosutoiko/improve-your-python-skills-with-classes-decorators-and-implicit-parameters-4ocf</link>
      <guid>https://dev.to/mizunosutoiko/improve-your-python-skills-with-classes-decorators-and-implicit-parameters-4ocf</guid>
      <description>&lt;p&gt;Python is a very common programming language. It is easy to learn the basics and start using it right away, this is specially useful for data scientists, and people from other backgrounds that don't have a lot of coding experience.&lt;/p&gt;

&lt;p&gt;This guide aims to introduce 3 concepts that if applied correctly, you could simplify your code, add functionalities to your current methods, and pass arguments without specifying them. Also, your code will look cooler 😎.&lt;/p&gt;

&lt;p&gt;The concepts are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Classes.&lt;/li&gt;
&lt;li&gt;Decorators.&lt;/li&gt;
&lt;li&gt;*Args and **kwargs.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Classes
&lt;/h2&gt;

&lt;p&gt;Python is an Object Oriented Programming Language (OOP Language), this means that we can use classes to organize our code and group related methods together.&lt;/p&gt;

&lt;p&gt;A Python Class could be something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Pokemon&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
   &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Class containing the available Pokemon methods&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
   &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;evolve&lt;/span&gt;&lt;span class="p"&gt;(...):&lt;/span&gt;
   &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The interesting part about classes is that they introduce one of the most useful things of OOP, heritage.&lt;/p&gt;

&lt;p&gt;For example, if we have multiple classes that are somewhat related, let's say, Bulbasaur, Squirtle, and Charmander, they all should have an evolve method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Bulbasaur&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;evolve&lt;/span&gt;&lt;span class="p"&gt;(...):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Squirtle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;evolve&lt;/span&gt;&lt;span class="p"&gt;(...):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Charmander&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;evolve&lt;/span&gt;&lt;span class="p"&gt;(...):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But using the example above, we could simply define a Pokemon parent class that contains the method, and all three pokemons will have it through heritage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Pokemon&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
   &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Class containing the available Pokemon methods&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
   &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;evolve&lt;/span&gt;&lt;span class="p"&gt;(...):&lt;/span&gt;
   &lt;span class="bp"&gt;...&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Bulbasaur&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Pokemon&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Squirtle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Pokemon&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Charmander&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Pokemon&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;

&lt;span class="n"&gt;eric&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Bulbasaur&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;eric&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;evolve&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="c1"&gt;# &amp;gt;&amp;gt;Evolving to Ivisaur
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And with that all three pokemons could make use of the method defined in the parent class.&lt;/p&gt;

&lt;p&gt;This helps us make our code scalable, maintainable and also easier to read.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decorators
&lt;/h2&gt;

&lt;p&gt;Decorators are a way of altering a method's functionality by using another method that receives the target method as an argument.&lt;/p&gt;

&lt;p&gt;For example, let's say that we are going to make the evolve method of the pokemons to print the elapsed time that took the pokemon to evolve.&lt;/p&gt;

&lt;p&gt;There are several ways of doing this, but we are using a decorator for it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;measure_time&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;func&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;The elapsed time was &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; seconds!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To use it we should use the decorator with an "@" above the function definition, something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nd"&gt;@measure_time&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;evolve&lt;/span&gt;&lt;span class="p"&gt;(...)&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;evolve&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# &amp;gt;&amp;gt;The elapsed time was 7.152557373046875e-07 seconds!
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We could also have decorators with parameters. One useful resource for understanding this is &lt;a href="https://stackoverflow.com/a/26151604" rel="noopener noreferrer"&gt;this stackoverflow's answer&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let's say that we have two Bulbasaurs and one of them tackles the other.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;print_used_attack&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;attack&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;xs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kws&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;f&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;xs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kws&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Used &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;attack&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Bulbasaur&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;health&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;

    &lt;span class="nd"&gt;@staticmethod&lt;/span&gt;
    &lt;span class="nd"&gt;@print_used_attack&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;tackle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;target_pokemon&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;target_pokemon&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;health&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;

&lt;span class="n"&gt;eric&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Bulbasaur&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;tommy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Bulbasaur&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="n"&gt;tommy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;health&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;eric&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;tackle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tommy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# &amp;gt;&amp;gt;Used Tackle
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tommy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;health&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# &amp;gt;&amp;gt;85
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, anytime the tackle method is used, a string like "Used &lt;code&gt;attack_name&lt;/code&gt;" will be printed in the console, this is useful if we want to add logs to a method that receives multiple arguments. &lt;/p&gt;

&lt;p&gt;And, the magic of this decorator is that if we define more attacks like &lt;code&gt;vine_whip&lt;/code&gt; or &lt;code&gt;leech_seed&lt;/code&gt;, and we use the decorator with them, a log will be printed in the console with the used attack!&lt;/p&gt;

&lt;h2&gt;
  
  
  *Args and **Kwargs
&lt;/h2&gt;

&lt;p&gt;These are abreviations for Arguments and Key-arguments. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note that the important part is the use of &lt;code&gt;"*"&lt;/code&gt; and &lt;code&gt;"**"&lt;/code&gt;, the name could be different form args and kwargs, those names are just conventions.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  *Args
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;*args&lt;/code&gt; abreviation allow us to define a method without argument constraints.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;damage_history&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;sum_attack_damage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;num&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;sum_attack_damage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;damage_history&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="c1"&gt;# &amp;gt;&amp;gt;30
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The use of the &lt;code&gt;*args&lt;/code&gt; as a form of receiving the parameters give us the possibility of passing multiple arguments, and being able to sum them without limiting the number!&lt;/p&gt;

&lt;h3&gt;
  
  
  **Kwargs
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;**kwargs&lt;/code&gt; abreviation allows us to define a method that could receive a dict with the parameters' names as keys.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;evolve_pokemon&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pokemon&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;base_evolution&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;first_evolution&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;second_evolution&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;pokemon&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;base_evolution&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
         &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;first_evolution&lt;/span&gt;
    &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;pokemon&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;first_evolution&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;second_evolution&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;pokemon&lt;/span&gt;

&lt;span class="n"&gt;pokemon_data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;base_evolution&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Pichu&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;first_evolution&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Pikachu&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;second_evolution&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Raichu&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;evolve_pokemon&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Pichu&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;pokemon_data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; 
&lt;span class="c1"&gt;# &amp;gt;&amp;gt;Pikachu
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;evolve_pokemon&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Raichu&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;pokemon_data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; 
&lt;span class="c1"&gt;# &amp;gt;&amp;gt;Raichu
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you see in the example, it is not necessary to pass parameter by parameter to the function, we just passed a dict with the &lt;code&gt;**&lt;/code&gt; at the beginning to signal that it should be treated as a kwarg.&lt;/p&gt;

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

&lt;p&gt;Learning python could be a long process, but I hope that with this article, and some future ones, I could explain in a simple manner difficult concepts that are really useful for our journey. &lt;/p&gt;

&lt;p&gt;I hope you find this interesting, and if you want to deepen on something, have suggestions, or want me to explain some other concept, you could leave a comment below.&lt;/p&gt;

&lt;p&gt;Happy Programming!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
