<?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 Roman Kyslyi, PhD on Medium]]></title>
        <description><![CDATA[Stories by Roman Kyslyi, PhD on Medium]]></description>
        <link>https://medium.com/@kvrware?source=rss-b5c75617c637------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*cT2PcMWTXrODW8q4EE8dpQ.jpeg</url>
            <title>Stories by Roman Kyslyi, PhD on Medium</title>
            <link>https://medium.com/@kvrware?source=rss-b5c75617c637------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 05:31:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kvrware/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[The Data Weekly — 20.03.2023]]></title>
            <link>https://medium.com/the-data-weekly/the-data-weekly-20-03-2023-6c97293deae?source=rss-b5c75617c637------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c97293deae</guid>
            <dc:creator><![CDATA[Roman Kyslyi, PhD]]></dc:creator>
            <pubDate>Mon, 20 Mar 2023 06:49:52 GMT</pubDate>
            <atom:updated>2023-03-20T06:49:52.557Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Data Weekly — 20.03.2023</h3><p>Hello there! Another episode of The Data Weekly. <br>This week was again all about big language models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XBMGTqkHioer2aUL" /><figcaption>Photo by <a href="https://unsplash.com/@pllnt?utm_source=medium&amp;utm_medium=referral">zhan zhang</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><ul><li>After releasing LLaMa model by Meta, Stanford trained its own chat-style model:<br><a href="https://crfm.stanford.edu/2023/03/13/alpaca.html">https://crfm.stanford.edu/2023/03/13/alpaca.html</a><br>Interesting fact that for boosting the training set davinchi model from OpenAI was used</li><li>PyTorch 2.0 was released:<br><a href="https://pytorch.org/blog/pytorch-2.0-release/">https://pytorch.org/blog/pytorch-2.0-release/</a></li><li>Opensource chat model was released:<br><a href="https://huggingface.co/spaces/togethercomputer/OpenChatKit">https://huggingface.co/spaces/togethercomputer/OpenChatKit</a></li><li>C/C++ release of LLaMa model:<br><a href="https://github.com/ggerganov/llama.cpp">https://github.com/ggerganov/llama.cpp</a></li><li>Also Google launches PaLM API:<br><a href="https://developers.googleblog.com/2023/03/announcing-palm-api-and-makersuite.html">https://developers.googleblog.com/2023/03/announcing-palm-api-and-makersuite.html</a><br>Api with access to AI models, mostly for the Google office apps, but also beyond</li></ul><p>That is all for the previous week, subscribe to stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c97293deae" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-data-weekly/the-data-weekly-20-03-2023-6c97293deae">The Data Weekly — 20.03.2023</a> was originally published in <a href="https://medium.com/the-data-weekly">The Data Weekly</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Data Weekly — 13.03.2023]]></title>
            <link>https://medium.com/the-data-weekly/the-data-weekly-13-03-2023-6d06ea8aa37f?source=rss-b5c75617c637------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d06ea8aa37f</guid>
            <dc:creator><![CDATA[Roman Kyslyi, PhD]]></dc:creator>
            <pubDate>Mon, 13 Mar 2023 06:18:14 GMT</pubDate>
            <atom:updated>2023-03-13T06:18:14.661Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Data Weekly — 13.03.2023</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lrQTZTW3nKJO_k3I" /><figcaption>Photo by <a href="https://unsplash.com/@billow926?utm_source=medium&amp;utm_medium=referral">billow926</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><a href="https://pandas.pydata.org/docs/dev/whatsnew/v2.0.0.html"><strong>Pandas 2.0 is here!</strong></a><br>Biggest changes:<br>- Faster and more memory-efficient operations <em>(added support for pyarrow in the backend)</em><br>- Copy-on-Write Optimisation <em>(now it is similar to PySpark and how it executes code)</em><br>- Index can now hold NumPy numeric types <em>(now it can be any NumPy numeric dtype, including int8, int16, int32, int64, uint8, uint16, uint32, uint64, float32, and float64. <br>Previously, only int64, uint64, and float64 types were supported.)</em></p><p><strong>Alternative Chat LLMs are now available oh huggingface:</strong><br><a href="https://huggingface.co/spaces/olivierdehaene/chat-llm-streaming">https://huggingface.co/spaces/olivierdehaene/chat-llm-streaming</a></p><p><strong>PaLM-E</strong> a 562-billion parameter, general-purpose, embodied visual-language generalmodel is released: <a href="https://palm-e.github.io/">https://palm-e.github.io/</a></p><p><strong>Prismer</strong> — a parameter-efficient vision-language model powered by an ensemble of domain experts is in opensource: <a href="https://twitter.com/DrJimFan/status/1633179734803890177">https://twitter.com/DrJimFan/status/1633179734803890177</a><br>Seems that the next step would be large multimodal models.</p><p><a href="https://www.kaggle.com/discussions/product-feedback/391200?utm_source=substack&amp;utm_medium=email"><strong>Introducing Kaggle Models</strong></a><strong> </strong>— after the Huggingface, Kaggle launches its own model hub.</p><p><a href="https://lightning.ai/pages/community/serve-stable-diffusion-three-times-faster/"><strong>Way to serve stable diffusion 3 times faster with Lightning</strong> </a>— optimisations to serve model concurrently in production.</p><p>Also, we had a wonderful discussion about ChatGPT:</p><p><a href="https://www.youtube.com/watch?v=-6g9tMwAGpY">https://www.youtube.com/watch?v=-6g9tMwAGpY</a></p><p><em>That is all for the week, please subscribe and stay tuned!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d06ea8aa37f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-data-weekly/the-data-weekly-13-03-2023-6d06ea8aa37f">The Data Weekly — 13.03.2023</a> was originally published in <a href="https://medium.com/the-data-weekly">The Data Weekly</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Data Weekly — 6.03.2023]]></title>
            <link>https://medium.com/the-data-weekly/the-data-weekly-6-03-2023-92ac498e8b17?source=rss-b5c75617c637------2</link>
            <guid isPermaLink="false">https://medium.com/p/92ac498e8b17</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[newsletter]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[Roman Kyslyi, PhD]]></dc:creator>
            <pubDate>Mon, 06 Mar 2023 08:08:15 GMT</pubDate>
            <atom:updated>2023-03-06T08:08:15.402Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>The Data Weekly — 6.03.2023</strong></p><p>First “The Data Weekly” digest is here! There are some exiting news from the world of AI and LLM. Let’s get started:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/0*6pxi1Od4TzRw3l-t.jpg" /></figure><ul><li>Meta introduce its large language model LLaMa (<a href="https://ai.facebook.com/blog/large-language-model-llama-meta-ai/">https://ai.facebook.com/blog/large-language-model-llama-meta-ai/</a>) and creates a queue for the weights access, meanwhile it appears on torrents: <a href="https://github.com/shawwn/llama-dl">https://github.com/shawwn/llama-dl</a></li><li>OpenAI releases API access to the gpt-3.5-turbo model (<a href="https://openai.com/blog/introducing-chatgpt-and-whisper-apis">https://openai.com/blog/introducing-chatgpt-and-whisper-apis</a>), same as used in ChatGPT. It is not free, but quite affordable with the price of $0.002 per 1k tokens. And if it is also more then you want to spend on it, there are always free alternatives like GPT-J or <a href="https://www.ai21.com/studio?utm_source=google-search&amp;utm_medium=cpc&amp;utm_campaign=Studio_Search_US_EN_Singup_Branded&amp;ad_set_name=Jurassic&amp;utm_term=jurassic-1&amp;gclid=CjwKCAiAmJGgBhAZEiwA1JZolpxYB88ef3AYkGLbmVdNvdvckHZZTMPEtnP0HXo6T33coQz7kxO1bhoC1_AQAvD_BwE">Jurassic-1</a>.</li><li><a href="https://openai.com/blog/whisper/">Whisper</a>, the speech-to-text model that was opensourced already got its v2 update and direct OpenAI API with the price of $0.006 / minute. Previous version can be found on HuggingFace (<a href="https://huggingface.co/openai/whisper-large">https://huggingface.co/openai/whisper-large</a>)</li><li><a href="https://github.blog/2023-02-14-github-copilot-for-business-is-now-available/">Copilot for Business is now available</a> — Copilot is a development tool created by GitHub and OpenAI to help developers was previously available for individuals with rate 10$ per month, now also available for organisations at 19$ per user per month</li><li><a href="https://blog.tensorflow.org/2023/02/updates-tensorflow-decision-forests-is-production-ready.html?linkId=8569552&amp;m=1">TensorFlow Decision Forests is production ready</a> — a new release of FT decision forests library. Not sure why to use it though, while good-old sklearn is still available.</li></ul><p>That is all wor this week. Thanks for reading “The Data Weekly”! Subscribe to receive new posts and updates.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92ac498e8b17" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-data-weekly/the-data-weekly-6-03-2023-92ac498e8b17">The Data Weekly — 6.03.2023</a> was originally published in <a href="https://medium.com/the-data-weekly">The Data Weekly</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Good API design, bad API design]]></title>
            <link>https://levelup.gitconnected.com/good-api-design-bad-api-design-2405dcdde24c?source=rss-b5c75617c637------2</link>
            <guid isPermaLink="false">https://medium.com/p/2405dcdde24c</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[api-development]]></category>
            <category><![CDATA[patterns]]></category>
            <category><![CDATA[rest]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Roman Kyslyi, PhD]]></dc:creator>
            <pubDate>Tue, 18 Jan 2022 23:38:10 GMT</pubDate>
            <atom:updated>2022-01-18T23:38:10.855Z</atom:updated>
            <content:encoded><![CDATA[<p>Principals and rules of modern REST API design</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ovDeW5qkd5SmXcfc" /><figcaption>Photo by <a href="https://unsplash.com/@redaquamedia?utm_source=medium&amp;utm_medium=referral">Denny Müller</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Usually, updating or developing an API of some service, there are a long discussions on the structure of he API, naming and functions. Although, through the years there are created certain rules, that can be applied to the process and help getting to the common ground while developing.</p><p>First — some basics.</p><p>API - is the acronym <strong>for Application Programming Interface</strong>, which is a software that allows two applications to talk to each other. In this article, we’ll focus on web API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oWaI10Ug4wRrIM4O5yzCRw.png" /><figcaption>Web application structure</figcaption></figure><p>Basically, each time you use a web app, send a message, or go to some URL, you’re using an API of some application wherever it is a client application or server one.</p><p>As all the communication between API and everything else is done by HTTP, is important to remember that HTTP has a set of different methods that has to be used for the specific purposes. Most important of them are:</p><ul><li>GET — requests a representation of the specified resource. Requests using GET should only retrieve data.</li><li>POST — submits data to the specified resource.</li><li>PUT — replaces all current representations of the target resource with the request data.</li><li>DELETE — deletes the specified resource.</li><li>PATCH — applies partial modifications to a resource.</li></ul><p>About the rest of them can be read <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods"><strong>here</strong></a> in more details.</p><p>Through years, there were several different types of the API architectures and protocols. They are different on how they specify data types and commands as well as they are different in their capabilities. For some time most popular was XML based protocol, but it is mostly replaced now by JSON.</p><p>Most common API architecture in todays world is REST (<em>representational state transfer</em>). When using REST, it is obligatory to follow JSON rules and form your requests in valid JSON. Except of that, good API should follow the following rules:</p><ul><li>API have to be separated from the backend, data storage, client etc. It has to be separate layer due to security and flexibility.</li><li>State less — different request should know nothing about each other and be processed independently. That also means that each request needs to include all the information necessary for processing it.</li><li>API should work same way independently of a client sending request (e.g. is it a web-server or load-balancer or any other client).</li><li>REST APIs usually send static resources, but in rear cases, responses can also contain executable code (such as Java applets). In these cases, the code should only run on-demand.</li><li>Cacheability — when possible, resources should be cacheable on the client or server side. The goal is to improve performance on the client side, while increasing scalability on the server side. Although, there are special headers like <a href="https://restfulapi.net/caching/"><strong>Cache-Control</strong></a> to control the cache behaviour.</li><li>Handle errors and return corresponding error codes. All errors have their specific codes, and instead throwing internal error to user, handle it and send corresponding code and message (e.g. 404 — not found. List of codes can be found<strong> </strong><a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status"><strong>here</strong></a>)</li><li>Don’t forget that API should be idempotent (that means that can be invoked many times with the same result). Users sometimes can duplicate requests coming to the API. These duplicate requests may be unintentional (or intentional due to timeout or network issues). So API have to be fault-tolerant in such a way that the duplicate requests should have the same results (only POST request is not idempotent).</li><li>Use swagger or other tool to write documentation on your API. Documentation is super important part (if someone going to use that API some day)</li></ul><p>There are also some good manners in naming endpoints as well:</p><ul><li>Use only nouns: endpoint should be named with nouns that specify the contents of the resource, rather than adding a verb for the function that is being performed (e.g. name endpoint <em>/users</em> and use different HTTP methods for working with users entity instead of creating several endpoints like <em>/get-user</em>, <em>/add-user</em>, etc.).</li><li>Use clear names: name of endpoint should be clear and intuitive (don’t use any shortcuts or abbreviations, unless it is obvious — <em>/ids</em> is understandable and preferable to <em>/identification-numbers</em>).</li><li>Build hierarchy by forward slashes: group endpoints into logical groups (<em>/departments/ids</em> and <em>/departments/managers</em> is better then <em>/departments-ids</em> and <em>/departments-managers).</em></li><li>Use only lowercase: URIs are case-sensitive (according to <a href="https://datatracker.ietf.org/doc/html/rfc3986"><strong>specification</strong></a>) so it is better to try to avoid upper case, unless it is necessary.</li><li>Use “-” to separate words: different words in the endpoint name usually divided by “-” rather then underscores or camel case.</li><li>Avoid special characters: URLs can only be sent and received using the ASCII character set, so it is possible to use only characters from that set (also there are some expectable but unsafe characters like “%”,”[]”,”{}”,”|”,” “,”&lt;&gt;” and it is better try to avoid using them as well).</li></ul><p>Most of the REST API is made together with micro service architecture. In that case such API structure will provide flexibility to change underlaying logic, add or remove components etc. without changing other communication protocol with other services.</p><p>With all rules in place, let’s take a look at the example of the API:</p><ul><li>Stripe (online payment system): <a href="https://stripe.com/docs/api">https://stripe.com/docs/api</a></li><li>Twilio:<a href="https://www.twilio.com/docs/usage/api"> https://www.twilio.com/docs/usage/api</a></li><li>Linkedin: <a href="https://docs.microsoft.com/en-us/linkedin/">https://docs.microsoft.com/en-us/linkedin/</a></li></ul><p>If you want to dive deeper into API design here are some useful resources:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FaAb7hSCtvGw%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DaAb7hSCtvGw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FaAb7hSCtvGw%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e19a0c98c52b1ea24810a3b941ad2292/href">https://medium.com/media/e19a0c98c52b1ea24810a3b941ad2292/href</a></iframe><ul><li><a href="https://www.manning.com/books/the-design-of-web-apis">The Design of Web APIs</a></li><li><a href="https://stackoverflow.blog/2020/03/02/best-practices-for-rest-api-design/">Best practices for REST API design</a></li></ul><p>Thank you, and take care!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2405dcdde24c" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/good-api-design-bad-api-design-2405dcdde24c">Good API design, bad API design</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Usage of Gunicorn for deploying python web applications]]></title>
            <link>https://levelup.gitconnected.com/usage-of-gunicorn-for-deploying-python-web-applications-1e296618e1ab?source=rss-b5c75617c637------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e296618e1ab</guid>
            <category><![CDATA[system-engineering]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Roman Kyslyi, PhD]]></dc:creator>
            <pubDate>Tue, 07 Sep 2021 17:24:32 GMT</pubDate>
            <atom:updated>2021-09-07T17:24:32.889Z</atom:updated>
            <content:encoded><![CDATA[<h4>Tutorial on how to use and configure Gunicorn</h4><h3><strong>Introduction</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OV280p6geP0_-g6R" /><figcaption>Photo by <a href="https://unsplash.com/@clemhlrdt?utm_source=medium&amp;utm_medium=referral">Clément Hélardot</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>First of all, what is a Gunicorn and what do we need it for? According to the definition from the official site:</p><blockquote>Gunicorn ‘Green Unicorn’ is a Python WSGI HTTP Server for UNIX.</blockquote><p>So what is a WSGI server and what makes it different from a web server? WSGI stands for <em>Web Server Gateway Interface</em> and it is needed for Python web applications, because traditional web servers like Apache don’t have the ability to run them.</p><p>In other words, WSGI server is an application server. The main difference between a web server and application server is that a web server is meant to serve static pages like HTML and CSS, while an Application Server is responsible for working with data by executing server-side code. Usually for serving static content we use servers like Nginx, but it can also be any other web server or CDN. In that case, Nginx is used as a <strong>reverse proxy server</strong>, which is also responsible for:</p><ul><li><strong>load balancing</strong> — it is responsible for determining on which application server incoming HTTP request will be sent (ensuring load balancing over existing application servers)</li><li><strong>acceleration</strong> — it also cashes some common responses with static content</li></ul><p>The typical set up for a python web app is on the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*0qUOB1vfLQ4KPPFVxNoGEg.jpeg" /><figcaption>Typical python web app set up</figcaption></figure><p>Gunicorn as well as other WSGI servers work with all popular web frameworks like flask or django. But contrary to other servers like waitress it uses pre-fork worker model. <a href="https://docs.gunicorn.org/en/latest/design.html#design">This means</a> that there is a central master process that manages a set of worker processes. The master never knows anything about individual clients. All requests and responses are handled completely by worker processes.</p><p>Workers in their turn can be Sync or Async (there are also some other types of available workers, but they are not very popular, so we’ll focus only on these 2).</p><p><strong>Sync</strong> workers are workers that handle a single request at a time. They do not support persistent connections - each connection is closed after the response has been sent.</p><p><strong>Async</strong> workers available are based on Greenlets (Greenlets are an implementation of cooperative multi-threading for Python) In general, an application should be able to make use of these worker classes with no changes.</p><p>Regarding numbers of workers, Gunicorn should only need <a href="https://docs.gunicorn.org/en/latest/design.html#how-many-workers">4–12 worker</a> processes to handle hundreds or thousands of requests per second.</p><p>Gunicorn relies on the operating system to provide all of the load balancing when handling requests. Generally, it is recommended to have:</p><blockquote>2 * Number of cores + 1</blockquote><p>workers. It is based on the assumption that for a given core, one worker will be reading or writing from the socket while the other worker is processing a request. Although this can be tuned further for the particular application.</p><h3><strong>Setting up a simple app and serving with Gunicorn</strong></h3><p>Let’s set up a small Flask app and serve it with the Gunicorn. For that we’ll need a “Hello world” Flask app with 1 endpoint:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/520172a16240c14191c1e6046f57667c/href">https://medium.com/media/520172a16240c14191c1e6046f57667c/href</a></iframe><p>Now, let’s create an entry point for serving our application:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c22b2cefeaae1f250ba3c14fdf023129/href">https://medium.com/media/c22b2cefeaae1f250ba3c14fdf023129/href</a></iframe><p>Running this will start Gunicorn with 4 workers, 2 threads by each worker and serving our application on port 5000.</p><p>Create a Dockerfile:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/526e2c92a93a18e5dd1e60c8db8638cf/href">https://medium.com/media/526e2c92a93a18e5dd1e60c8db8638cf/href</a></iframe><p>Now build and run our image:</p><pre>docker build -t hello .<br>docker run -p 5000:5000 hello</pre><p>And accessed with http request:</p><pre>$ curl localhost:5000<br>Hello world!</pre><h3>Summary</h3><p>In this tutorial, we have looked through the Gunicorn and how it works. We have seen that adding Gunicorn is fast and easy.</p><h3>References</h3><ol><li><a href="http://docs.gunicorn.org/en/latest/design.html"><em>Gunicorn architecture</em></a></li><li><a href="https://stackoverflow.com/questions/38425620/gunicorn-workers-and-threads"><em>Stack Overflow answers</em></a></li><li><a href="https://towardsdatascience.com/my-favorite-python-servers-to-deploy-into-production-d92289764fbe">Python in production</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e296618e1ab" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/usage-of-gunicorn-for-deploying-python-web-applications-1e296618e1ab">Usage of Gunicorn for deploying python web applications</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Embedding similarity search]]></title>
            <link>https://medium.com/@kvrware/embedding-similarity-search-25c6911240af?source=rss-b5c75617c637------2</link>
            <guid isPermaLink="false">https://medium.com/p/25c6911240af</guid>
            <category><![CDATA[embedding]]></category>
            <category><![CDATA[k-nearest-neighbours]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[similarity-search]]></category>
            <dc:creator><![CDATA[Roman Kyslyi, PhD]]></dc:creator>
            <pubDate>Tue, 10 Aug 2021 20:05:02 GMT</pubDate>
            <atom:updated>2021-08-10T20:05:02.099Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ArauOFg8i1yAIWZ4" /><figcaption>Photo by <a href="https://unsplash.com/@lazycreekimages?utm_source=medium&amp;utm_medium=referral">Michael Dziedzic</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Searching for something similar is a key concept in many information retrieval systems, recommendation engines, synonyms searching, etc. Basically everywhere, where exact search through the database is not an option (as an example, you cannot just save the word and also save the representation its meaning and context).</p><p>In that case, most of the tools, deep learning algorithms or statistical ML methods are operating with initial items representations in the form of vectors in high dimensional space, called embeddings. This allows to represent initial items (like text, images, etc.) in much more efficient and flexible way also saving its features and sometimes even context.</p><p>So, basically searching for similar items means searching for its vector representations that are close to each other in their representation space (finding Euclidean or other distance between them).</p><p>Considering the above, searching for the similar item will follow the algorithm:</p><ul><li>Represent all the items from the dataset as an embeddings</li><li>Define a <a href="https://developers.google.com/machine-learning/clustering/similarity/measuring-similarity">metric</a> for a pair of embeddings. This measure could be <a href="https://wikipedia.org/wiki/Cosine_similarity">cosine similarity</a>, <a href="https://wikipedia.org/wiki/Euclidean_distance">Euclidean distance</a> or dot product.</li><li>Search the embedding of the query object</li><li>Select the embeddings close to the query object</li></ul><p>Retrieving those results is a <a href="https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm"><em>k-nearest neighbours</em></a> search that can be done in a several different ways. If there are not so many items in the dataset (few hundreds or thousands), it is possible to compute distance metric between all vectors. Although if result is needed in the real time, and the dataset is really big, searching for nearest neighbours needs to be approximate. This can be done by creating an index data structure that allows fast search of the items.</p><p>Lets review the different ways of searching k-nearest neighbours, from the simplest, to the methods that can be used for the big datasets:</p><p><strong><em>Using direct calculation</em></strong></p><p><strong>From scratch using numpy: </strong>the simplest approach is to compute the distance from query vector X to <em>every other vector</em> in S, and identify the k vectors that have minimum distances. As all the possible matches are evaluated, this is a <em>brute force</em> search. This operation requires the computation of N*N distances and then finding the bottom k values:</p><pre>import numpy as np<br>N = 10000<br>d = 10<br>k = 5<br># create an array of N d-dimensional vectors (our search space)<br>S = np.random.random((N, d)).astype(&#39;float32&#39;)<br># create a random d-dimensional query vector<br>x = np.random.random(d)<br># compute distances<br>distances = np.linalg.norm(S - x, axis = 1)<br># select indices of vectors having the lowest distances from the X<br>neighbours = np.argpartition(distances, range(0, k))[:k]</pre><p><strong>Using scikit-learn: </strong>scikit-learn provides a simple way to search for k-nearest neighbours (using <a href="https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.NearestNeighbors.html">sklearn.neighbors.NearestNeighbors</a> ):</p><pre>from sklearn.neighbors import NearestNeighbors<br>knn = NearestNeighbors(n_neighbors=k)<br>knn.fit(S)<br># select indices of k nearest neighbours<br>neighbours = knn.kneighbors([x], return_distance = False)<br>print(neighbours)</pre><p>Results are the same as with using numpy (as exact distances are computed). In both approaches we need to fit the whole matrix of distances into memory, which may be a little problematic.</p><p><strong><em>Using approximate similarity</em></strong></p><p>When dataset is much bigger then RAM or the answer should be provided in real-time — there are 2 main approaches to approximate embedding similarity: tree-based approach and hashing approach.</p><p>Basic idea is similar to building database indexes. In tree-based approaches is to recursively partition the data in a divide-and-conquer fashion, which puts similar vectors near each other in the tree. Tree indexes require large amounts of memory, and the performance degrades with higher-dimensional data.</p><p>In hash-based approach, the idea is to learn a model that converts an item into a code, where similar items will produce the same or similar code. This approach significantly reduces the memory needed.</p><p>There are <a href="https://github.com/erikbern/ann-benchmarks">several open source libraries</a> that implement approximate similarity matching techniques. Let’s review the most popular of them.</p><p><strong>Non-Metric Space Library (NMSLIB)</strong> The core-library does not have any third-party dependencies. It is included in <a href="https://aws.amazon.com/about-aws/whats-new/2020/03/build-k-nearest-neighbor-similarity-search-engine-with-amazon-elasticsearch-service/">Amazon Elasticsearch Service</a>. It is written in C++ and can be used both ways — directly in C++ and Python.</p><p>The queries can be answered either exactly, i.e., by returning a complete result set that does not contain erroneous elements, or, approximately, e.g., by finding only some neighbors. Thus, the methods are evaluated in terms of efficiency-effectiveness trade-offs rather than merely in terms of their efficiency. One common effectiveness metric is recall, which is computed as an average fraction of true neighbors returned by the method (with ties broken arbitrarily).</p><pre>import hnswlib<br>import numpy as np</pre><pre># Declaring index<br>p = hnswlib.Index(space=&#39;l2&#39;, dim=d)  # possible options are l2, cosine or ip</pre><pre>p.init_index(max_elements=N+1, ef_construction=100, M=16)<br># Controlling the recall by setting ef:<br># higher ef leads to better accuracy, but slower search<br>p.set_ef(10)<br>p.add_items(S)<br># Query the elements for themselves and measure recall:<br>labels, distances = p.knn_query(S, k=1)<br>print(&quot;Recall:&quot;, np.mean(labels.reshape(-1) == np.arange(len(S))), &quot;\n&quot;)</pre><pre># Query the elements for themselves and measure recall:<br>labels, distances = p.knn_query(x, k=k)<br>print(labels[0])</pre><p>As we are testing on a very small dataset, used search methods do not necessarily outperform brute-force search. Typically, the larger is the corpora, the larger is the improvement in efficiency over the brute-force search.</p><p><strong>Faiss (Facebook AI search)</strong></p><p>Faiss is a library made by Facebook to be efficient with large datasets and high dimensional sparse data. It contains several methods for similarity search. Most of them, use a compressed representation of the vectors and do not require to keep the original vectors. This generally comes at the cost of more approximate search but these methods can scale to billions of vectors in main memory.</p><p>Faiss is built around an index type that stores a set of vectors, and provides a function to search in them with L2 and/or dot product vector comparison. Some index types are simple baselines, such as exact search. Most of the available indexing structures correspond to various trade-offs with respect to</p><ul><li>search time</li><li>search quality</li><li>memory used per index vector</li><li>training time</li><li>need for external data for unsupervised training</li></ul><p>There are several different possibilities to chose index types using Faiss:</p><ul><li>if there will be not that many searches, memory is a concern and exact match is needed, then the best choice is “Flat” index</li><li>if dataset is big and memory is a concern then NHSW need to be chosen. As well as in NMSLIB, we chose the M parameter. The 4 &lt;= M &lt;= 64 is the number of links per vector, higher is more accurate but uses more RAM. The memory usage is (d * 4 + M * 2 * 4) bytes per vector.</li></ul><p>Also there are different settings for the clustering of the dataset has to be done beforehand. After clustering, “Flat” parameter just organizes vectors into the buckets, and does not compress them, the storage size is the same as that of the original dataset. The tradeoff between speed and accuracy is set via the nprobe parameter which can reduce dimensionality, make quantization of the vectors into <em>M</em> 4-bit codes etc (<a href="https://github.com/facebookresearch/faiss/wiki/Guidelines-to-choose-an-index">more here</a>).</p><pre>import faiss<br>import numpy as np</pre><pre># Param of PQ<br>M = 8  # The number of sub-vector. Typically this is 8, 16, 32, etc.<br>nbits = 8 # bits per sub-vector. This is typically 8, so that each sub-vec is encoded by 1 byte<br># Param of IVF<br>nlist = 100  # The number of cells (space partition). Typical value is sqrt(N)<br># Param of HNSW<br>hnsw_m = 32  # The number of neighbors for HNSW. This is typically 32<br># Setup<br>quantizer = faiss.IndexHNSWFlat(d, hnsw_m)<br>index = faiss.IndexIVFPQ(quantizer, d, nlist, M, nbits)<br># Train<br>index.train(S)<br># Add<br>index.add(np.array([x])<br># Search<br>index.nprobe = 8  # Runtime param. The number of cells that are visited for search.<br>dists, ids = index.search(x=np.array([x])[:3], k=k)<br>print(ids)</pre><p><strong>Spotify’s </strong><a href="https://github.com/spotify/annoy"><strong>Annoy library</strong></a></p><p>Annoy is a C++ library with Python bindings that builds <a href="http://wikipedia.org/wiki/Locality-sensitive_hashing#Random_projection">random projection</a> trees. An index is built with a forest of k trees, where k is a tunable parameter that trades off between precision and performance. It also creates large read-only, file-based data structures that can be shared among many processes.</p><pre>from annoy import AnnoyIndex<br>import random</pre><pre>t = AnnoyIndex(d, &#39;angular&#39;)  # Length of item vector that will be indexed<br>for i in range(len(S)):<br>    t.add_item(i, S[i])<br>    <br>t.build(10) # 10 trees<br>print(u.get_nns_by_vector(x, k)) # will find the k nearest neighbours</pre><p><strong>Conclusions</strong></p><p><a href="https://github.com/erikbern/ann-benchmarks">Here</a> represented benchmarks for all libraries with the different datasets and distance metrics. As we can see, that as dataset is smaller — the less difference is between speed of work of different methods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HldpfF6adu5xTmlY" /><figcaption>Benchmarks for different datasets [<a href="https://github.com/erikbern/ann-benchmarks">from here</a>]</figcaption></figure><p>So , in this tutorial, we have built a brut-force and an approximate k-NN similarity search feature using different libraries and approaches. Also, reviewed different types of indexes used in approximate k-NN similarity.</p><p>The code can be tried out with <a href="https://colab.research.google.com/drive/18kCP5TpSScL2SbujJORiQcxRfNaxT0FN?usp=sharing">Google Colab</a>.</p><p><strong>Sources:</strong></p><ul><li><a href="https://github.com/facebookresearch/faiss">GitHub - facebookresearch/faiss: A library for efficient similarity search and clustering of dense vectors.</a></li><li><a href="https://github.com/spotify/annoy">GitHub - spotify/annoy: Approximate Nearest Neighbors in C++/Python optimized for memory usage and loading/saving to disk</a></li><li><a href="https://github.com/nmslib/hnswlib">GitHub - nmslib/hnswlib: Header-only C++/python library for fast approximate nearest neighbors</a></li><li><a href="https://davidefiocco.github.io/nearest-neighbor-search-with-faiss/">First steps with Faiss for k-nearest neighbor search in large search spaces</a></li><li><a href="https://github.com/erikbern/ann-benchmarks">GitHub - erikbern/ann-benchmarks: Benchmarks of approximate nearest neighbor libraries in Python</a></li><li><a href="https://github.com/facebookresearch/faiss/wiki/Guidelines-to-choose-an-index">Guidelines to choose an index</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25c6911240af" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Inverting binary tree]]></title>
            <link>https://medium.com/@kvrware/inverting-binary-tree-b0ff3a5cb0df?source=rss-b5c75617c637------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0ff3a5cb0df</guid>
            <category><![CDATA[binary-tree]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[coding-interviews]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Roman Kyslyi, PhD]]></dc:creator>
            <pubDate>Mon, 01 Jun 2020 10:41:31 GMT</pubDate>
            <atom:updated>2020-06-01T10:58:22.685Z</atom:updated>
            <content:encoded><![CDATA[<p>Inverting binary tree — one of the very basic questions on the Software Developer interviews. It is not very applied task itself, but it shows how you can manipulate such structures as a tree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*GfkUEFwQYJl00rjY9xe3BA.jpeg" /><figcaption><a href="https://www.pinterest.co.uk/pin/542402348875234787/">Source</a></figcaption></figure><p>Lets start with some definitions.</p><h3>Definition</h3><p>In computer science, a binary tree is a tree data structure in which each node has at most two children, which are referred to as the <em>left child</em> and the <em>right child</em>. A recursive definition using just set theory notions is that a (non-empty) binary tree is a tuple (<em>L</em>, <em>S</em>, <em>R</em>), where <em>L</em> and <em>R</em> are binary trees or the empty set and <em>S</em> is a singleton set. However, if a node has no child, it’s called a leaf. (from <a href="https://en.wikipedia.org/wiki/Binary_tree">Wikipedia</a>)</p><p>An <strong>inverted</strong> form of a binary tree is another binary tree with left and right children of all non-leaf nodes interchanged. Assume that we have the following tree:</p><pre>     4<br>   /   \<br>  2     7<br> / \   / \<br>1   3 6   9</pre><p>then, inverted tree would look like:</p><pre>     4   <br>   /   \<br>  7     2<br> / \   / \<br>9   6 3   1</pre><h3>Problem solution</h3><p>First, lets create a tree structure itself. Each node should have its value and links to right and left child nodes (instances of the same class):</p><pre>public class TreeNode {<br>  private int value;<br>  private TreeNode rightChild;<br>  private TreeNode leftChild;<br>}</pre><p>There are several ways to reverse a binary tree. Using iterative method, we have to create a linked list and initialize tree root there. Then, while bypassing the tree, we all nodes children to the list, changing left one to the right and right to the left, until we reach tree leaves.</p><p>It is nice to know this method, but on the interview you will have to tell about inverting tree, using <strong>recursion</strong>. It is simple: first, we will need to call our method using the tree’s root, and then apply it on the left and the right children respectively until we reach the tree’s leaves:</p><pre>public void reverseRecursive(TreeNode treeNode) {<br>  if(treeNode == null) {<br>    return;<br>  }<br>  TreeNode temp = treeNode.getLeftChild();<br>  treeNode.setLeftChild(treeNode.getRightChild());<br>  treeNode.setRightChild(temp);<br>  reverseRecursive(treeNode.getLeftChild());<br>  reverseRecursive(treeNode.getRightChild());<br>}</pre><p>Since we have to travel to each leaf once, the time complexity is O(n), which means that we will need to visit each node only one time.</p><p>Thank you!</p><p><em>Sources: <br></em><a href="https://en.wikipedia.org/wiki/Binary_tree">https://en.wikipedia.org/wiki/Binary_tree</a><br><a href="https://www.baeldung.com/java-reversing-a-binary-tree"><em>https://www.baeldung.com/java-reversing-a-binary-tree</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0ff3a5cb0df" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why many companies try and fail to use DS in their business?]]></title>
            <link>https://medium.com/@kvrware/why-many-companies-try-and-fail-to-use-ds-in-their-business-392fde62a58e?source=rss-b5c75617c637------2</link>
            <guid isPermaLink="false">https://medium.com/p/392fde62a58e</guid>
            <category><![CDATA[business]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[project-management]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Roman Kyslyi, PhD]]></dc:creator>
            <pubDate>Sun, 05 Aug 2018 20:56:20 GMT</pubDate>
            <atom:updated>2018-08-06T07:08:30.768Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1LI9TzwDU1l6IyJFBRcULw.jpeg" /></figure><p>While ML and DL is hyping, many companies tries to put it inside their business model, at the same time, to implement ML inside already working business may be quite a difficult task. There are several reasons, why it so difficult:</p><p><strong>Business stakeholders don’t understand how they will win, using ML</strong>. This is quite common situation in the not software business that wants to improve its results with new solutions. Quite often, in this situation stakeholders do not really understand what they want, cost of the solution and time for implementation. They relay on their experience from the other industry, and do not expect the DS project to be kind of research project and last long.</p><p><strong>Business is not ready for long semi-research project </strong>(or just don’t have enough resources), and tries to lead DS project using standard techniques like Scrum. This leads to misunderstanding between stakeholders and DS teams — in research projects you cannot predict exact efforts and time estimations.</p><p><strong>No data — no business.</strong> Sometimes, business expects DS solution for some problem, without providing enough data to the team. Another problem may be receiving a huge amount of rough data, without any labeling (data labeling could take a lot of time and efforts, and also some external people).</p><p><strong>Data Scientists are tries to implement as fancier and as complicated model as possible. </strong>Other problems comes from data scientists themselves — they often tries to implement some new fancy things, instead of trying to start with simple approaches. <em>Golden rule of data science — start with as simple approach as possible, it may work out!</em></p><p><strong>Even if this things are not happening, adding infrastructure for data science can be quite tricky and expensive.</strong> Usually data infrastructure will require some other stack of technologies then other parts of the business. And considering that usually DS solutions are built using python or R, they may require a lot of resources. But considering that computational power and memory are becoming cheaper through the time, this should be the smallest problem.</p><p>All these things, and many others can stand between successfully completed data science project and data team. So, to make it easier, try to discuss as many of your concerns before project starts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=392fde62a58e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>