<?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 Kiran Achyutuni on Medium]]></title>
        <description><![CDATA[Stories by Kiran Achyutuni on Medium]]></description>
        <link>https://medium.com/@kiranachyutuni?source=rss-2891f1860cc8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*pbz0PP8IXTvhbTeK.</url>
            <title>Stories by Kiran Achyutuni on Medium</title>
            <link>https://medium.com/@kiranachyutuni?source=rss-2891f1860cc8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 19:31:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kiranachyutuni/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[How to design a high-performance neural network on a GPU]]></title>
            <link>https://medium.com/deep-dives-into-computer-science/how-to-design-a-high-performance-neural-network-on-a-gpu-2f7ada309724?source=rss-2891f1860cc8------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f7ada309724</guid>
            <category><![CDATA[matrix-multiplication]]></category>
            <category><![CDATA[high-performance]]></category>
            <category><![CDATA[nvidia]]></category>
            <category><![CDATA[gpu]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Kiran Achyutuni]]></dc:creator>
            <pubDate>Sat, 11 Jul 2020 04:50:27 GMT</pubDate>
            <atom:updated>2020-07-11T04:50:27.116Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BvuSWZ4dJlpuVE07aEweww.jpeg" /></figure><p>GPUs are essential for machine learning. One could go to AWS or Google Cloud to spin up a cluster of these machines with ease. NVIDIA has industry-leading GPU with Tensor cores with the Volta V100 and Ampere A100 accelerators. Which one to pick for the best performance? What configuration? Which works best for your neural network? There are a number of questions that the machine learning architect must deal with in order to design the fastest neural network at the lowest cost. Besides, just using a machine with GPU and Tensor Cores does not guarantee peak performance. So, as a machine learning architect, how should one approach this problem? <em>For sure, you cannot be hardware agnostic</em>. You need to aware of the capabilities of the hardware in order to get the most performance at the lowest cost.</p><blockquote>As a machine learning architect, how should you design the neural network to maximize the performance on a GPU?</blockquote><p>In this article, we will deep dive to understand the levers that the machine learning architect has to maximize performance. In particular, we will focus on <strong><em>matrix-matrix multiplication</em></strong> in this article because it is the most frequent and heavy-duty (O(n³)) mathematical operation in machine learning.</p><p>Let’s start with a simple fully connected 1 hidden layer neural network:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-DlqSpSMrLGOVEokuEXwdA.png" /><figcaption>Figure 1: Matrix multiplications at each layer of the neural network with the shapes of the matrix multiply at each step indicated in parenthesis. For example, (B, L1) is the shape of the matrix with B rows and L1 columns. MM1, MM2, … MM5 are various matrix-matrix multiplications.</figcaption></figure><p>From the basic neural network, we can see that at layer L2, we perform 3 matrix-matrix multiplications (1 forward, and 2 backward). At layer L1, we perform 2 matrix-matrix multiplications (1 forward, and 1 backward). In fact, at every layer other than the first layer (L1), we perform 3 matrix multiplications. If there are <em>n </em>layers in a neural net, there are <em>3n-1</em> matrix-matrix multiplications, i.e., it increases linearly as the size of the neural network.</p><p>One quick observation is the case when batch size <em>B=1, </em>i.e., we learn one data point at a time. In this case, matrix-matrix degenerates to matrix-vector multiplication. However, in practice, the batch size is never 1. In Gradient Descent, the entire dataset is considered during each learning step, whereas in Stochastic Gradient Descent, a batch B &gt; 1 (but much less than the entire dataset) is considered at each learning step.</p><p>Going forward in this article, let’s focus on a single matrix-matrix multiplication between 2 matrices A and B of dimensions (M, K) and (K, N) respectively resulting in a matrix C of dimension (M, N).</p><p>The dimensions M, N, K are determined by the architecture of the neural network at each layer. For example, in <a href="https://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks.pdf">AlexNet</a>, the batch size is 128 with a few dense layers of 4096 nodes and an output layer with 1000 nodes. This will result in multiplication of (128,4096) and (4096, 1000) matrices. These are pretty large matrices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*90lbbHN-thfWExoTSRDUOw.png" /><figcaption>Figure 2. Source: Reference 1. Tiled matrix multiplication</figcaption></figure><p>What does “large” mean and how are these matrices multiplied? By “large”, we mean any matrix that does not fit in memory. Let’s dive deeper into large matrix multiplication. The matrix multiplication we have learnt in textbooks assumes that the matrix fits in memory. In reality, this may not be the case, especially in machine learning. In addition, finely tuned matrix multiplication algorithms must take into account the memory hierarchy in the computer for optimal performance. The workhorse for multiplying matrices that don’t fit in memory is the <em>tiled/blocked matrix multiplication</em> algorithm. In tiled/block matrix multiplication, the matrices are split into smaller tiles/blocks that will fit into memory, and then compute the portion of the resultant product matrix (See figure 2). Figure 3 shows how the tiled/block matrix-multiplication is recursively applied at every level of the memory hierarchy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*515Zr7GgL_31BGEGeWETTw.png" /><figcaption>Figure 3: Tiled/Block matrix-matrix multiplication recursively applied through the complete memory hierarchy of an NVIDIA CPU-GPU system. GEMM stands for General Matrix Multiplication. Figure source: AnandTech.</figcaption></figure><p>We won’t get into the precise tiled matrix multiplication algorithms here, the interested reader is referred to <a href="https://dl.acm.org/doi/10.1145/2063384.2063431">this paper</a>. The library routine in <a href="https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms">BLAS</a> for <strong>Ge</strong>neral <strong>M</strong>atrix <strong>M</strong>ultiplication is called <strong>GEMM. </strong><a href="https://docs.nvidia.com/cuda/nvblas/index.html">NVBLAS</a> is the Nvidia implementation of GEMM that takes advantage of the internal GPU architecture and implements the tiled/block matrix multiplication. PyTorch and TensorFlow link to this library on machines with Nvidia GPU. The library does all the heavy lifting for you. But a poorly designed neural network will almost certainly reduce the performance.</p><p>For us, the immediate goal is to figure out the conditions under which matrix-matrix multiplication executes as fast as possible. This is possible only if the GPU is 100% busy and not idling for data tiles. For this, we need to look at the memory hierarchy and how fast data can potentially move through the memory hierarchy levels.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*cICXwQUjCy3OtesmDttuoQ.png" /><figcaption>Figure 4: Roofline Model</figcaption></figure><p>Memory hierarchy offers key advantages for improving performance: 1) they hide the latency differences between CPU, GPU, memory components, 2) they take advantage of program locality. Also, a well-designed memory hierarchy offers the highest performance at the lowest cost/byte. To keep the GPUs continuously busy, the data tiles have to rapidly fed to the GPUs. This is determined by the data transfer bandwidth and how fast the GPU is processing the data. This performance metric is captured by the <a href="https://en.wikipedia.org/wiki/Roofline_model"><em>ops: bytes ratio</em></a><em> </em>in the <a href="https://dl.acm.org/doi/10.1145/1498765.1498785">Roofline model </a>(Figure 4).<em> </em>Figure 5 shows how to calculate this from the vendor specs. We see that the ops: bytes ratio is 139 for Volta V100, and 416 for Ampere A100. The larger the ops: bytes ratio, more speedup is possible if the computation was memory or arithmetic bound earlier. In other words, a system with higher ops: bytes ratio is more powerful than a lesser one. This is why Ampere A100 is more powerful than Volta V100.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8NzkWnx9DbFSAf0-vZZK3g.png" /><figcaption>Figure 5: Calculating the ops: bytes ratio from the vendor specs.</figcaption></figure><p>What does the ops: bytes ratio mean for machine learning and matrix multiply? To see this, we must now look at the compute and data requirements of matrix multiply. <a href="https://en.wikipedia.org/wiki/Roofline_model">Arithmetic intensity</a> is defined as the ratio of the floating-point operations/sec to the bytes. Figure 6 shows how to compute the arithmetic intensity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sa1jWzXruMOlfUVVBq7UZg.png" /><figcaption>Figure 6: Computing the arithmetic intensity for matrix multiplication</figcaption></figure><blockquote>If arithmetic intensity &gt; ops:bytes, then matrix multiplication is arithmetic bound else it is memory bound.</blockquote><p>Therefore, the first take away is that the dimensions of the matrices involved should be designed such that the arithmetic intensity is greater than ops: bytes. This will ensure that the GPU is fully utilized. For example, if batch size = 512, N=1024, and M=4096, the arithmetic intensity will be 315, which is greater than 139 for the Volta V100 GPU. Therefore, this matrix multiplication is arithmetic bound on Volta V100 and the GPU will be fully utilized. Figure 7 shows the arithmetic intensities for some common operations in machine learning. The second row corresponds to batch size = 1. The linear layer becomes memory bound and not arithmetic bound in this case. This is the reason why a batch size of 1 is generally not used in production machine learning algorithms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ajuyD3oENYbi1sKwn_0l8A.png" /><figcaption>Figure 7. Arithmetic intensities for some common operations in machine learning. Source: NVIDIA documentation. See Reference 1.</figcaption></figure><p>However, ensuring the right arithmetic intensity by choosing the right matrix dimensions is not sufficient to achieve peak arithmetic performance which requires keeping all the tensor cores busy as well. In order to effectively use Nvidia’s Tensor Cores, M, N, K must be a multiple of 8 for FP16 arithmetic or multiple of 16 for FP32 arithmetic. Nvidia core libraries check the dimensions of the matrices and if the conditions are satisfied, then the operations are routed to the Tensor cores. This can result in a 6x speedup on Volta using Tensor cores as compared to using without the Tensor cores. Therefore, the second takeaway is that if the dimensions are not a multiple of 8 or 16, then it is recommended that the dimensions are padded appropriately.</p><p>In your quest to speed up the performance as a machine learning architect, you will invariably face the decision whether to upgrade from Volta to Ampere and pay a higher cost. To this end, you must determine if your neural network is either arithmetic bound or memory bound using the Roofline model. If it is neither, then there is no value in upgrading to a more powerful machine. This is the third takeaway. Nvidia offers tools such as <a href="https://developer.nvidia.com/nsight-compute">Nsight Compute</a> to perform application analysis.</p><p>To summarize:</p><ul><li>matrix-matrix multiply is the most frequent operation in neural network training and inference. The number of matrix multiplications is almost <em>3n</em> the number of layers in a neural network. Hence it is important to compute these as fast as possible.</li><li>The matrices are very large in a neural network. Therefore, we will invariably use a GPU to speed up the matrix multiplications. In order to do, we must understand the ops: bytes ratio of the GPU and design the layers in such a way that the arithmetic intensity is greater than the ops: bytes ratio if possible.</li><li>In order to achieve peak arithmetic performance such that all the Tensor cores are used, the dimensions of the matrices must also meet the requirements imposed by the NVIDIA architecture to use the Tensor core. Usually, it is a multiple of 8 (for FP16 arithmetic) or 16 (for FP32 arithmetic). It is best to see the documentation to ensure the requirement is met.</li><li>You should determine if the application is memory bound or arithmetic bound. If it is neither, then there is no point in upgrading to a more powerful GPU. Otherwise, we can accelerate further by upgrading.</li></ul><p>Being aware of the hardware capabilities and the requirements it imposes for maximizing performance will help in choosing the matrix dimensions and batch size judiciously. This will lead to a design of the neural network such that the training can be completed in the shortest possible time at the lowest cost.</p><p>This article touched on one aspect of accelerating machine learning. There are other dimensions to this problem as well. We will look at some more in the future. Hope you found this article useful. Happy architecting.</p><p><strong>References</strong></p><ol><li><a href="https://docs.nvidia.com/deeplearning/performance/dl-performance-gpu-background/index.html#gpu-arch">Nvidia docs: Deep Learning performance documentation</a></li><li><a href="https://www.anandtech.com/show/12673/titan-v-deep-learning-deep-dive/3">Nvidia: It’s all about Tensor Cores</a>, AnandTech Blog 2018</li><li><a href="https://dl.acm.org/doi/10.1145/2063384.2063431">Fast Implementation of DGEMM on Fermi GPU</a>, Proceeding of the 2011 International Conference on High Performance, Storage, and Analysis</li><li><a href="https://dl.acm.org/doi/10.1145/1498765.1498785">Roofline: An Insightful Visual Performance Model for Floating-Point Programs and Multicore Architectures,</a> <em>Comm. of the ACM</em>, April 2009</li><li><a href="https://developer.download.nvidia.com/video/gputechconf/gtc/2019/presentation/s9624-performance-analysis-of-gpu-accelerated-applications-using-the-roofline-model.pdf">Performance Analysis of GPU-Accelerated Applications using the Roofline Model</a>, NVIDIA, 2019</li><li><a href="https://www.codeproject.com/Articles/1169323/Intel-Advisor-Roofline-Analysis">Intel Advisor Roofline Analysis</a></li><li><a href="https://developer.nvidia.com/nsight-compute">Nvidia Nsight Compute</a></li><li><a href="https://www.nvidia.com/content/dam/en-zz/Solutions/Data-Center/a100/pdf/nvidia-a100-datasheet.pdf">Nvidia Ampere A100 Datasheet</a></li><li><a href="https://images.nvidia.com/content/technologies/volta/pdf/tesla-volta-v100-datasheet-letter-fnl-web.pdf">Nvidia Volta V100 Datasheet</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f7ada309724" width="1" height="1" alt=""><hr><p><a href="https://medium.com/deep-dives-into-computer-science/how-to-design-a-high-performance-neural-network-on-a-gpu-2f7ada309724">How to design a high-performance neural network on a GPU</a> was originally published in <a href="https://medium.com/deep-dives-into-computer-science">Deep Dives into Computer Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deep dive into the internals of NumPy's linalg.polyfit()]]></title>
            <link>https://medium.com/deep-dives-into-computer-science/deep-dive-into-the-internals-of-numpys-linalg-polyfit-b60156bc5d1e?source=rss-2891f1860cc8------2</link>
            <guid isPermaLink="false">https://medium.com/p/b60156bc5d1e</guid>
            <category><![CDATA[numpy]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[linear-algebra]]></category>
            <category><![CDATA[linear-regression]]></category>
            <category><![CDATA[deep-dives]]></category>
            <dc:creator><![CDATA[Kiran Achyutuni]]></dc:creator>
            <pubDate>Thu, 21 May 2020 10:04:53 GMT</pubDate>
            <atom:updated>2020-05-21T10:04:53.140Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BvuSWZ4dJlpuVE07aEweww.jpeg" /><figcaption>Image Source: Unsplash: Willian Justen de Vasconcellos</figcaption></figure><p>Today, a linear regression program in machine learning can be written in just a few lines so easily that we can fail to appreciate the depth of the progress in math and computer systems that enables this simplicity for us. Behind the powerful <a href="https://numpy.org/">numpy</a> and <a href="https://www.scipy.org/">scipy</a> libraries, a huge amount of math and numerical complexity is hidden from us. In this article, we do a deep dive into the <em>internal implementation</em> of linear regression to get a better understanding of what exactly is going on under the covers. In the process, we will discover a variety of elegant linear algebra techniques, the complexity of calling Fortran functions from python, etc.</p><p>In a linear regression problem, we need to solve <em>Ax = b</em>. Here (A, b) is the set of observed data, and we need to find the parameters <em>x</em> that fits this data. There are innumerable mathematical ways by which we can solve the system of linear equations. We are interested in the <em>internal</em> mathematical methods that underly machine learning packages such as numpy/scipy.</p><p>Let’s start with an example of how numpy.linalg.polyfit() is used. (You can download the python code at Github <a href="https://gist.github.com/kirachy/402ed5062cf21c8b94635fa265b02d25">linear regression using numpy polyfit</a>).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c03141b7a1bb00d03bb3651944d6fec/href">https://medium.com/media/5c03141b7a1bb00d03bb3651944d6fec/href</a></iframe><p>Here is the visualization of the result. The “*” is the observed data (or generated in our case) and the line is drawn by the parameters that were computed by polyfit. Clearly, polyfit is doing a good job of linear regression.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SdX28iZVkA_IO1LKHMWIZA.png" /></figure><p>Most articles on the web stop at this point and don’t go any deeper. However, diving deep and trying to understand what is going on will help us appreciate how the solution was computed. So let’s deep dive into np.linalg.polyfit().</p><p>The first observation we make is that np.linalg.polyfit() is <strong>not</strong> fully implemented in python. The heart of its computation happens in a library that was written in highly optimized FORTRAN code! Let’s see how this is so. The call to polyfit() works its way through the following blocks as shown below. I have cut and paste relevant calls from a variety of files so that you can see how it all stitches together:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*-ItR9MTfrU4xKHb4Acvluw.png" /></figure><p>In block 2, the call to polyfit() will construct a <a href="https://en.wikipedia.org/wiki/Vandermonde_matrix">Vandermonde matrix</a> via a call to numpy.linalg.polyvander(), a special matrix where the columns are in a geometric progression. Assuming the user wants to fit a polynomial of degree 5, then columns up to <em>x</em>⁵ are constructed. Note that the user only needs to supply a 1-D column of <em>x</em> values and polyfit() generates the Vandermonde matrix. By doing so, it is preparing for a polynomial linear regression for this equation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*0qcC5UwE3_12WmlZUdH5vw.png" /></figure><p>The original matrix A has transformed as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*7iiKKPtsDWZwYbsjCC9e9g.png" /></figure><p>Note that this is a rectangular matrix with <em>m</em> &gt; <em>n</em> (deg). Depending on the number of data observations, <em>m</em> can be very large whereas n<em> </em>is usually a small number. Once this matrix is set up, preparations begin to call the matrix implementation in LAPACK (linear algebra library).</p><p>The LAPACK library was written in Fortran 90 way back in the 1980s and 1990s but is updated regularly. The latest open-source LAPACK version is 3.9.0 and was released in 2019. It is also optimized by processor vendors such as Intel, Apple etc. The Fortran library is compiled into a dynamic library based on the architecture of the platform and comes with the operating system. In addition, when you install numpy, 2 shared objects (.so) also comes along with it to make the calls to the C API easy. To view these files, go to the &lt;path to your python installation&gt;/lib/python3.7/site-packages/numpy/linalg/ and you will see the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*uMGAb8kAoQt2RmtkMJizmQ.png" /></figure><p>The two important files here:</p><ol><li><em>_umath_linalg.cpython-37m-darwin.so</em>. : This file converts python data structures into C data structures so that the C interface to the LAPACK can be invoked.</li><li><em>lapack_lite.cpython-37m-darwin.so</em>: This file is the C interface to the LAPACK routines. It calls the LAPACK routines and converts the returns values back to python data structures. The actual LAPACK routines are provided by the OS. For example, on Apple macOS, you can find the platform optimized version at /System/Library/Frameworks/vecLib.framework/libLAPACK.dylib</li></ol><p>Let’s resume how the call flow happens.</p><ol><li>The main entry point to computing the least-squares solution is np.linalg.lstsq(), as shown in block 3.</li><li>In block 4 in the above diagram, np.linalg.lstsq() calls the C interface in <em>_umath_linalg.lstsq_m().</em></li><li>Blocks 5–8 are templates to generate the python-C interface. For example, in block 6, <em>call_@lapack_func@</em> becomes <em>call_sgelsd()</em> defined in block 7. In block 7, <em>LAPACK(@lapack_func@)(…)</em> becomes the call to <em>sgelsd_(…)</em>. This is an extern function that is implemented in the libLAPACK.dylib provided by Apple.</li></ol><p>Now depending on the LAPACK method invoked, there are many ways to compute the linear least squares as shown in block 9.</p><ol><li>QR or LQ factorization</li><li>Complete Orthogonal factorization</li><li>Singular Value Decomposition (SVD) factorization</li><li>Divide and conquer SVD</li></ol><p><em>numpy.linalg.lstsq()</em> has chosen to use the divide-and-conquer SVD methods. How do we know? Look in block 6, and you will find these functions that are specified for template generation. So the chosen functions are SGELSD, CGELSD, ZGELSD, and DGELSD.</p><p>How does the divide and conquer SVD work? The high-level description of the algorithm is described in block 9 is part of code comments, but you can look at all the details in the original <a href="http://www.netlib.org/lapack/lawnspdf/lawn88.pdf">paper</a>. It shows exactly how the least-squares solution is computed. Here is the abstract of the paper:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*HmWWbUstuDkmKVCQ45pMlA.png" /></figure><p>In order to read the above paper, here are core linear algebra concepts that one needs to know: 1) <a href="https://en.wikipedia.org/wiki/Singular_value_decomposition">Singular Value Decomposition</a> (SVD) 2) <a href="https://en.wikipedia.org/wiki/QR_decomposition">QR Factorization</a> 3) <a href="https://en.wikipedia.org/wiki/Moore%E2%80%93Penrose_inverse">Moore-Penrose Pseudoinverse matrix</a>. There are a number of good YouTube videos on linear algebra but the one I would recommend is the <a href="https://www.youtube.com/playlist?list=PL49CF3715CB9EF31D">Gibert Strang Lectures on Linear Algebra (MIT)</a>. His <a href="https://www.amazon.com/Introduction-Linear-Algebra-Gilbert-Strang/dp/0980232775">textbook</a> is equally fabulous. (I am capturing all the essential math concepts required for machine learning <a href="https://medium.com/deep-dives-into-computer-science/essential-math-concepts-to-understand-machine-learning-d852c57a7341">here</a>). From the paper, we see that the current implementation for least squares, i.e, SGELSD, in LAPACK is 9 times faster than its predecessor on bidiagonal matrices! This is the reason why as a first step, SGELSD converts the input matrix to a bidiagonal matrix so that we can benefit from the speedups. Once the SVD is computed, it is trivially easy to compute the least-squares solution. We compute the Moore-Penrose pseudoinverse and then derive the least-squares solution from it. The final step is also detailed in the paper.</p><p>In summary, we have traced the complete path of numpy.linalg.polyfit() all the way down to the core Fortran code. We have discovered that it uses important numerical linear algebra techniques such as singular value decomposition. We also looked at the original paper that came up with the algorithms that numpy.linalg.polyfit() uses and found that the algorithms are significantly faster than the prior implementations. To interface Fortran code seamlessly with Python, careful implementation of the C and Python API interfaces were developed so that the process would not crash. High-quality software engineering practices are required to make this robust. In addition, the OS vendors provided highly tuned libraries to make the LAPACK implementation more efficient for their processor architecture. Thus, advances in math, software engineering, computer architectures, and open source have made numpy.linalg.polyfit() possible and fast.</p><p>Hope you enjoyed the deep dive journey into nump.linalg.polyfit().</p><p>References:</p><ol><li><a href="http://www.netlib.org/lapack/">LAPACK — Linear Algebra Package</a>, <a href="http://www.netlib.org/lapack/lug/">LAPACK User’s guide</a>, <a href="https://www.netlib.org/lapack/lug/node27.html">LAPACK Least squares functions</a></li><li><a href="https://github.com/numpy/numpy">Numpy source code on Github</a></li><li><a href="https://software.intel.com/content/www/us/en/develop/documentation/mkl-developer-reference-c/top/lapack-routines.html">Developer Reference for Intel® Math Kernel Library 2020 — C</a> Processor vendors like Intel offer optimized libraries for LAPACK and other mathematical libraries.</li><li><a href="https://software.intel.com/content/www/us/en/develop/tools/math-kernel-library.html">Intel Math Kernel Library</a></li><li><a href="https://developer.apple.com/documentation/accelerate/veclib">vecLib: Apple macOS implementation of LAPACK</a></li><li>You can download the source code of LAPACK <a href="http://www.netlib.org/lapack/#_lapack_version_3_9_0">here</a> to see the Fortran files.</li><li><a href="http://www.netlib.org/lapack/explore-html/d0/db8/group__real_g_esolve_gabc655f9cb0f6cfff81b3cafc03c41dcb.html">SGELSD Fortran source code</a></li><li><a href="http://www.netlib.org/lapack/lawnspdf/lawn88.pdf">Efficient Computation of the Singular Value Decomposition with Applications to Least Squares Problems.</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b60156bc5d1e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/deep-dives-into-computer-science/deep-dive-into-the-internals-of-numpys-linalg-polyfit-b60156bc5d1e">Deep dive into the internals of NumPy&#39;s linalg.polyfit()</a> was originally published in <a href="https://medium.com/deep-dives-into-computer-science">Deep Dives into Computer Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Essential math concepts to understand machine learning]]></title>
            <link>https://medium.com/deep-dives-into-computer-science/essential-math-concepts-to-understand-machine-learning-d852c57a7341?source=rss-2891f1860cc8------2</link>
            <guid isPermaLink="false">https://medium.com/p/d852c57a7341</guid>
            <category><![CDATA[linear-algebra]]></category>
            <category><![CDATA[calculus]]></category>
            <category><![CDATA[probability]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Kiran Achyutuni]]></dc:creator>
            <pubDate>Sun, 10 May 2020 12:54:23 GMT</pubDate>
            <atom:updated>2020-05-13T18:06:09.780Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3I8YZJmkEXt7nHJfQuiAhQ.jpeg" /></figure><p>Machine Learning involves lots of mathematics — linear algebra, calculus, and probability and statistics. They work closely with each other in machine learning algorithms. Linear algebra concepts are used to represent and manipulate data and weights. Calculus is used in the iterative optimization algorithms (e.g., stochastic gradient) to arrive at the optimal weights from loss functions. Probability concepts are used to minimize the uncertainty between the optimal model and the real but unknown data generating process.</p><p>Understanding these math concepts and how they complement each other is fundamental to understanding why and how machine learning algorithms work. Having a firm grasp of these concepts will help you in your machine learning career. In this article, I list some of the important concepts in each of the math areas.</p><p>Important Concepts from Linear Algebra</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e30f058a9a27c70230de7c62bd27a0ea/href">https://medium.com/media/e30f058a9a27c70230de7c62bd27a0ea/href</a></iframe><p>Important Concepts from Probability and Statistics</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d54ca4cb9ae6ad5beb078e514bc8734a/href">https://medium.com/media/d54ca4cb9ae6ad5beb078e514bc8734a/href</a></iframe><p>Important Concepts from Calculus</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ccf4ae53280e7c6858f1ef1b7236345/href">https://medium.com/media/3ccf4ae53280e7c6858f1ef1b7236345/href</a></iframe><p>Here is a sample of some important research papers in machine learning that have made an impact, and the (pre-requisite) math concepts they use. Familiarize yourself with these math concepts and you will be able to read the paper first-hand and appreciate its contributions.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fairtable.com%2Fembed%2FshrmmiBFKa55xwkan&amp;display_name=Airtable&amp;url=https%3A%2F%2Fairtable.com%2FshrmmiBFKa55xwkan&amp;image=https%3A%2F%2Fstatic.airtable.com%2Fimages%2Foembed%2Fairtable.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=airtable" width="800" height="533" frameborder="0" scrolling="no"><a href="https://medium.com/media/d505c1b36ac20b639a171d0a0849a0d7/href">https://medium.com/media/d505c1b36ac20b639a171d0a0849a0d7/href</a></iframe><p>(<em>Note: I intend to update this article regularly with more information. So please revisit frequently to be up-to-date</em>).</p><p>Here are some excellent books to refresh your math concepts:</p><ol><li><a href="https://mml-book.github.io/book/mml-book.pdf">Mathematics for Machine Learning</a> by Marc Peter Deisenroth, A. Aldo Faisal, Cheng Soon Ong, To be published by Cambridge University Press</li><li><a href="https://www.amazon.com/Introduction-Linear-Algebra-Gilbert-Strang/dp/0980232775">Linear Algebra and its Applications</a>, Gilbert Strang (MIT)</li><li><a href="https://www.amazon.com/Introduction-Probability-2nd-Dimitri-Bertsekas/dp/188652923X">Introduction to Probability</a>, Bertsekas and Tsitsiklis</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d852c57a7341" width="1" height="1" alt=""><hr><p><a href="https://medium.com/deep-dives-into-computer-science/essential-math-concepts-to-understand-machine-learning-d852c57a7341">Essential math concepts to understand machine learning</a> was originally published in <a href="https://medium.com/deep-dives-into-computer-science">Deep Dives into Computer Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Like backpropagation, is there forward-propagation as well?]]></title>
            <link>https://medium.com/deep-dives-into-computer-science/like-backpropagation-is-there-forward-propagation-as-well-fedb22828b36?source=rss-2891f1860cc8------2</link>
            <guid isPermaLink="false">https://medium.com/p/fedb22828b36</guid>
            <category><![CDATA[backpropagation]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[automatic-differentiation]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Kiran Achyutuni]]></dc:creator>
            <pubDate>Mon, 23 Mar 2020 19:04:33 GMT</pubDate>
            <atom:updated>2020-05-13T17:04:26.726Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NzyxsrkiLjjyjiIuCf123w.png" /><figcaption>By Berland at English Wikipedia — Transferred from en.wikipedia to Commons by JRGomà., Public Domain, <a href="https://commons.wikimedia.org/w/index.php?curid=4860262">https://commons.wikimedia.org/w/index.php?curid=4860262</a></figcaption></figure><h3>The role of automatic differentiation in machine learning</h3><p>Backpropagation is fundamental to machine learning. It is a technique for computing the gradient of a function. Given there is a technique called <em>back</em>propagation, one wonders if there is a technique called forward-propagation as well? Turns out, there is. Let’s dive into differentiation techniques here to understand which differentiation technique is most relevant for a given machine learning architecture.</p><p>The derivative of a function is a fundamental tool of calculus. There are 3 fundamental ways:</p><ol><li>Symbolic differentiation: Here, we manipulate mathematical functions and produce closed from derivates. The output is what you would see if you were to compute the derivatives by hand. For example, you can visit <a href="https://www.wolframalpha.com/input/?i=derivative+of+x%5E4+sin+x&amp;lk=3">wolfram alpha</a> and see symbolic differentiation in action as follows. The problem with symbolic differentiation is <em>expression swell </em>which can result is high inefficiencies.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RS2I-sfQ1yugq1Txg0BP4g.png" /></figure><p>2. <a href="https://en.wikipedia.org/wiki/Numerical_differentiation">Numerical differentiation</a>: This method involves the use of finite differences to compute the derivative of a function. This is quite a common method and is used in many areas of engineering such as aerospace engineering. fluid dynamics etc. However, one needs to be careful about round-off errors. Hence, these techniques go to a great extent to avoid these problems. In machine learning, such a high level of precision is not required in computing the gradient since the purpose of machine learning is not optimizing the gradient but optimizing the parameters. So the learning method (such as stochastic gradient descent) can eventually learn the most optimal parameters even if the gradient is not accurate. Also, the complexity of a numerical differentiation method such as <a href="https://en.wikipedia.org/wiki/Euler_method">Euler’s method</a> or <a href="https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods">Runge-Kutta method</a> is <em>O(n) </em>where<em> n </em>is the number of basic math operations in the function whose derivative needs to be performed (e,g, the function in the neuron such as sigmoid etc). Given that there are a large number of derivatives to be performed in a neural network, an <em>O(n)</em> factor slows down the computation of the gradient. For these reasons, numerical differentiation is not used in machine learning.</p><p>3. <a href="https://en.wikipedia.org/wiki/Automatic_differentiation">Automatic differentiation</a>: In this method, the basic insight is that any <em>arbitrary</em> function coded into a computer program can be broken down to basic mathematical functions such as arithmetic, trigonometric, logarithmic functions. Now any function can be constructed as a computational graph consisting of the basic functions. And the derivative (also a function) can be constructed as a computational graph and the chain rule of calculus can be used to compute the derivative at any node in the graph. Both these graphs can be constructed simultaneously as we build out the neural network. In fact, this is what Tensorflow does. Let’s call these graphs the main graph (MG) and the derivative graph (DG).</p><p>Before we proceed, let’s recap what we are trying to compute. In <a href="https://en.wikipedia.org/wiki/Stochastic_gradient_descent">stochastic gradient descent</a> (SGD), the machine learning algorithm iterates in batches of examples to learn the weights of the network. During each iteration, we need to compute the Jacobian before we proceed to the next iteration. We are trying to compute the Jacobian as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/351/1*_1RtXBQWjFQ9kF7TmVfQbA.png" /></figure><p>Here the neural network has <em>n</em> inputs and <em>m</em> outputs. For example, in linear regression with sigmoid output, <em>m</em> = 1 and <em>n</em> ≥ 1. In image recognition neural net like <a href="https://en.wikipedia.org/wiki/AlexNet">AlexNet</a>, <em>m</em> = 1000 (outputs), and <em>n</em> = 224x224x3 = 150528 (inputs). The gradient in the latter case is a 1000x150528 matrix.</p><p>There are 2 modes for automatic differentiation for computing MG and DG:</p><p>1. Reverse more accumulation: During each iteration of SGD, evaluate MG first. Compute the loss and then compute the DG on the way back to compute the gradient using the loss. Then the weights are adjusted and the next iteration is performed. Computing DG on the way back is exactly the <em>backpropagation</em>.</p><p>2. Forward mode accumulation: Evaluate DG along with MG in each iteration. At the end of the forward step, DG is also available. The gradient can then be applied and the next iteration can be started.</p><p>Do note that with either reverse mode or forward mode, the end result is the same — the value of the gradient computed is the same. But the difference is the cost of computation. Why so? Matrix-matrix operations in the forward accumulation mode are more expensive than matrix-vector operations in the reverse accumulation mode (<em>O(n³)</em> vs <em>O(n²)</em> respectively.).</p><p>As a rule of thumb, if <em>n</em> &gt; <em>m </em>(i.e, inputs are more than outputs),<em> </em>then backpropagation is more efficient. Otherwise, forward mode accumulation would be better. Therefore, while designing your neural net, you must carefully choose your gradient computation algorithm that is most efficient for your application. In many popular neural nets today, the outputs are far less than the inputs, and hence backpropagation is more popular.</p><p>Tensorflow supports both modes of automatic differentiation: <a href="https://www.tensorflow.org/api_docs/python/tf/autodiff/ForwardAccumulator">Tensorflow Forward accumulato</a>r, and <a href="https://www.tensorflow.org/api_docs/python/tf/GradientTape">Tensorflow Gradient Tape (backpropagation</a>). Both are implemented in software. But this is gradually getting pushed to lower levels of computation (see <a href="https://www.intel.ai/fully-automatic-differentiation-for-tensor-expressions/#gs.0t1plz">Intel</a>). There is active research on automatic differentiation (see reference #3 below) and we can expect further advances in the future.</p><p>Hope this article gave you insight into why a specific gradient computation is chosen. For those who want to dive in further, please look at the references below.</p><p>References:</p><ol><li><a href="https://arxiv.org/abs/1502.05767">Automatic Differentiation in Machine Learning: A Survey</a> 2018</li><li><a href="https://arxiv.org/pdf/1811.05031.pdf">A review of Automatic Differentiation and its Efficient Implementation</a> 2019</li><li><a href="https://autodiff-workshop.github.io/2016.html">Autodiff Workshop</a> 2016</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fedb22828b36" width="1" height="1" alt=""><hr><p><a href="https://medium.com/deep-dives-into-computer-science/like-backpropagation-is-there-forward-propagation-as-well-fedb22828b36">Like backpropagation, is there forward-propagation as well?</a> was originally published in <a href="https://medium.com/deep-dives-into-computer-science">Deep Dives into Computer Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Is there logic behind probability?]]></title>
            <link>https://medium.com/deep-dives-into-computer-science/is-there-logic-behind-probability-e6cca75c3f42?source=rss-2891f1860cc8------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6cca75c3f42</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[frequentists]]></category>
            <category><![CDATA[logic]]></category>
            <category><![CDATA[probability-theory]]></category>
            <category><![CDATA[bayesian-machine-learning]]></category>
            <dc:creator><![CDATA[Kiran Achyutuni]]></dc:creator>
            <pubDate>Mon, 09 Mar 2020 16:33:46 GMT</pubDate>
            <atom:updated>2020-03-09T16:33:46.435Z</atom:updated>
            <content:encoded><![CDATA[<p>Probability theory plays a fundamental role in machine learning. Why? This is because probability theory concerns reasoning when there is uncertainty. In machine learning, we are given some data to learn from, and we need to reason if the machine learning model that we come up with will function well with <em>uncertain and unseen future</em> data. This seems like a silly question to ask, but can we trust probability theory? Are its foundations solid? Believe it or not, for over 300 years there has been a raging debate on this!</p><p>In 1713, <a href="https://en.wikipedia.org/wiki/Daniel_Bernoulli">Bernoulli</a> first came up with some basic rules to figure out the odds in a game of dice that is rolled repeatedly. This was the start of what is known as “<em>frequentist</em> probability theory”. However, there was a limitation in this — namely, what if you could not repeat the experiment repeatedly? For example, what is the probability of the Earth’s temperature rising by 5 degrees by 2030? We cannot apply the “frequentist probability theory” since we cannot repeat the Earth warming experiment again and again. It’s a one-time event. This limitation was noted by Bayes and Laplace very early on. In 1812, Laplace proposed a set of rules as to what is known as “Bayesian probability theory”. In this approach, one takes into account prior knowledge (Bayes’ law) and can “subjectively” assigns a probability to an event based on the available information at that point in time.</p><p>Assigning probability “subjectively” and taking prior information into account was the bone of contention between the two camps. The frequentists would not accept the “subjectivity” of the Bayesian approach, and the Bayesian’s would find the frequentists theory too limiting to be applied elsewhere. Yet for some strange reason, both the camps were working off of theorems that were eerily identical but derived in different ways, namely the product and sum rules of probability.</p><p>There were 4 important advances in the 20th century that finally put an end to this raging 300-year controversy:</p><ol><li>Kolmogorov, 1933 — <a href="https://www.york.ac.uk/depts/maths/histstat/kolmogorov_foundations.pdf">Foundations of the theory of Probability</a>. He proposed a set of axioms to derive the rules of frequentist probability theory. This is the classical probability theory that we still learn in schools and colleges today. This is easy to understand and hence used to introduce probability to students. Bernoulli’s law is easy to deduce from these axioms. The set of axioms he chose were arbitrary.</li><li>Cox, 1946 — <a href="http://jimbeck.caltech.edu/summerlectures/references/ProbabilityFrequencyReasonableExpectation.pdf">Probability, Frequency, and Reasonable Expectation </a>— published in the American Journal of Physics, 1946. Cox showed that the rules of probability can be derived by applying Boolean logic and calculus. This was the first time it was established that probability can be thought of as an extension of boolean logic. Cox had 2 arbitrary axioms as well.</li><li>Polya, 1954 — <a href="https://www.amazon.com/Mathematics-Plausible-Reasoning-Two-Volumes/dp/1614275572/ref=sr_1_4?keywords=polya&amp;qid=1583751975&amp;sr=8-4">Mathematics and Plausible Reasoning</a>. In this treatise, Polya goes to extensive length in showing how mathematicians and scientists reason when they are in the process of scientific discovery. He came with up with a set of simple rules (<a href="https://en.wikipedia.org/wiki/Syllogism">syllogisms</a>) to explain the thinking process. This treatise has influenced scientists for many generations since.</li><li>Jaynes, 2003 —<a href="https://www.amazon.com/Probability-Theory-Science-T-Jaynes/dp/0521592712/ref=sr_1_1?crid=C3CUUA7FMB9Y&amp;keywords=jaynes+probability+theory+the+logic+of+science&amp;qid=1583752010&amp;sprefix=jaynes+%2Caps%2C382&amp;sr=8-1"> Probability Theory, The Logic of Science</a>. One issue with both Kolmogorov and Cox is that they are based on axioms that are different but arbitrary. So what is it to say that there won’t be a dozen more theories tomorrow for probability theory. So Jaynes does not start with a set of axioms, but instead, he asks what common sense logic do humans follow while reasoning with uncertainty? He calls these the <em>desiderata. </em>These are not axioms but only requirements that any set of axioms must satisfy if it has to make sense for human reasoning. He is inspired by Cox and Polya in this endeavour and then goes about to derive the fundamental rules of probability from the desiderata using Boolean algebra and calculus. And lo and behold, there are only 2 fundamental rules of probability — the product rule and the sum rule. On top of this, he shows that the axioms which Cox and Kolmogorov arbitrarily assumed can also be derived from the product and sum rule! He also shows that there can be no other set of axioms. If they exist, either they can be derived from these two or it must be inconsistent.</li></ol><p>Jaynes and Cox thus showed that probability is an extension of logic since it was derivable from boolean algebra. Also, more importantly, the frequentist and Bayesian probability theories have the same roots (logic). This explains why the product and sum rule are exactly the same in both frequentist and bayesian theories. This diagram shows how everything is interlinked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*LR45LcMN0Q__OnQ4KmMibQ.png" /></figure><p>Jaynes and Cox showed that it doesn’t matter which camp you are in, both the camps have the same logical origin. However, the Bayesian way of thinking allows probability rules to be applied to a much larger set of problems where experiments cannot be repeated. Hence it is advantageous to use the Bayesian way of thinking.</p><p>So where exactly are we applying Bayesian thinking in machine learning? Let’s take the simple example of linear regression.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/96/1*BwQvVBUV1cQh1mydHdSVLQ.png" /></figure><p>where <strong>w</strong><em> </em>is the weight vector, <strong>x</strong> is the input example vector, and <em>y</em> is the computed output. Now, we don’t know the exact data process/function <em>f(x)</em> that generated the given data example <em>(y,x)</em>. In machine learning, we are trying to figure out <em>f(x)</em>. Given the weights <em>w</em>, how certain can we about the computed value <em>y</em> to its true value if we use this data point <em>x</em>? This is where Bayesian way of thinking probability comes in. We can impose any probability distribution we like on this computed value. We normally impose the Gaussian distribution because, among all distributions, this captures most uncertainty (maximum entropy) and least prior assumption about how the data was generated. This is written as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/182/1*Hnm-BdndfFT_g6ZpT_bBRQ.png" /></figure><p>where <em>N </em>is the Gaussian distribution. Do note that we cannot apply the frequentist view here because we are only computing <em>y</em> once for each example <em>x</em> in the training set for a given <em>w</em>. There is no way we can do repeated experiments here. So the only choice we have here is the Bayesian view — i.e., our belief in the amount of uncertainty of <em>y</em> from its true value, which we are capturing by a Gaussian distribution.</p><p>Now, over the entire training set, we multiply the uncertainty of each example by applying the product rule of probability theory to give us the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/156/1*kjiyoB22pSpKjdp1-nlfGA.png" /></figure><p>Once we formulate this, we can compute the Maximum Likelihood Estimate to find the best <strong>w</strong>. I would refer you to any machine learning textbook to see how this is done to solve linear regression.</p><p>To summarize, we have shown that foundations of probability theory are solidly rooted in logic. Both frequentist and Bayesian approaches have the same logical foundations. However Bayesian approach is more general, powerful, and simpler. The Bayesian view is widely used in machine learning.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6cca75c3f42" width="1" height="1" alt=""><hr><p><a href="https://medium.com/deep-dives-into-computer-science/is-there-logic-behind-probability-e6cca75c3f42">Is there logic behind probability?</a> was originally published in <a href="https://medium.com/deep-dives-into-computer-science">Deep Dives into Computer Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Embed Beautiful Math equations in Medium]]></title>
            <link>https://medium.com/@kiranachyutuni/how-to-embed-beautiful-math-equations-in-medium-a041a64dd4e3?source=rss-2891f1860cc8------2</link>
            <guid isPermaLink="false">https://medium.com/p/a041a64dd4e3</guid>
            <category><![CDATA[latex]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[math-equations-on-medium]]></category>
            <dc:creator><![CDATA[Kiran Achyutuni]]></dc:creator>
            <pubDate>Sun, 26 Jan 2020 16:41:07 GMT</pubDate>
            <atom:updated>2020-01-26T16:41:07.740Z</atom:updated>
            <content:encoded><![CDATA[<p>Machine Learning is a popular field of study with rapid advances being made each day. Some people wish to understand the whys behind Machine Learning and want to deep dive into the math (yes, such people exist). After you figure out the math, you may want to make a contribution as well. You figured out a cool equation and you set out to write a new Medium post to announce it to the world. Alas, you are stuck. While Medium is an excellent platform for blogging, it doesn’t support writing Math equations natively. So, you have to do some gymnastics to embed the math equations. The question is how do you go about doing this quickly and easily. The goal of this post is to help you get started.</p><p>I picked a random equation in probability and statistics called the <a href="https://en.wikipedia.org/wiki/Kullback%E2%80%93Leibler_divergence"><strong>Kullback-Leibler (KL) divergence</strong></a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*0Po77o4rnD8xFeSErCFeaQ.png" /></figure><p>It looks beautiful, isn’t it? Let’s not focus on the meaning of this equation, just how to get this into the Medium blog. To demystify it, it’s simply an image that I have embedded. To generate this image, you need 2 things:</p><ol><li>Knowledge of Latex</li><li>A tool that will help you write in Latex and generate the image</li></ol><p><a href="https://www.latex-project.org/">Latex</a> is a high-quality typesetting system. It is the de-facto typesetting system used across the world to publish papers in conferences and journals. (I wrote my PhD thesis and conference papers in Latex). It looks forbidding at first, but it is quite simple. You can pick it up in a week.</p><p>Latex has a large set of directives to generate print-ready output for anything — from books to conference papers — of any complexity. But we don’t need the full repertoire to generate an equation. This is where some simple tools come handy. I used <a href="https://www.chachatelier.fr/latexit/">LatexIt</a> tool to generate the above equation. This is the latex code for the above equation:</p><blockquote>D_{KL}(P || Q) = \displaystyle \mathbb{E}_{x \sim P}\left[ \log \frac{P(x)}{Q(x)} \right] = \mathbb{E}_{x \sim P}[\log P(x) — \log Q(x)]</blockquote><p>Enter this text as shown below (bottom half of the window) and press “Latex It” button. The equation is displayed in the top half. Simply hover the cursor on the equation, copy the image and paste it in the Medium blog, and you are done. If you know Latex, this whole process won’t take more than 1 minute.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sUqlzYpASj16nb0F1iElyA.png" /></figure><p>So there you have it. This is how you can generate neat looking Math equations and embed them in Medium. There are many other tools available on the web. Check them out to see what is most convenient for you. The most important thing is to overcome these hurdles and start sharing your math knowledge with the world. I am looking forward to reading your posts.</p><p>Here are some links for Latex that you will find useful: <a href="https://www.andy-roberts.net/writing/latex">quick introduction</a>, and <a href="http://ctan.imsc.res.in/info/lshort/english/lshort.pdf">The not so short introduction to Latex (in 139 minutes)</a>.</p><p>Hope you found this article useful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a041a64dd4e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ola Outstation erodes my trust in Ola]]></title>
            <link>https://medium.com/@kiranachyutuni/ola-outstation-erodes-my-trust-in-ola-3677a5c5cc59?source=rss-2891f1860cc8------2</link>
            <guid isPermaLink="false">https://medium.com/p/3677a5c5cc59</guid>
            <category><![CDATA[ola]]></category>
            <category><![CDATA[uber]]></category>
            <category><![CDATA[ride-sharing-app]]></category>
            <dc:creator><![CDATA[Kiran Achyutuni]]></dc:creator>
            <pubDate>Fri, 15 Mar 2019 09:47:48 GMT</pubDate>
            <atom:updated>2019-03-15T09:54:51.028Z</atom:updated>
            <content:encoded><![CDATA[<h3>Ola Outstation erodes my trust in OlaCabs</h3><p>Real character is seen in hard times. This is true of companies and people. When things go well, Ola rides are ok. But when Ola rides go wrong, all hell breaks loose. Recently, my experience with Ola Outstation has been awful, to say the least. It has revealed so many cracks in the Ola system that I have decided to write down the issues for the benefit of Ola as well as other customers of Ola. Don’t get me wrong, I am an avid user of Ola and continue to be. It beats Uber in the overall experience. But my trust in Ola has reduced considerably. Instead of just complaining, I am offering solutions to the issues that I faced, which if implemented by OlaCabs, can restore the trust in OlaCabs. <em>(All references to Ola in this story refer to </em><a href="https://www.olacabs.com/"><em>OlaCabs</em></a><em>)</em></p><h3>Situation</h3><p>So, here’s what happened. In Feb 2019, I booked an Ola outstation cab for a 3-day trip to take my parents to a temple trip to Kanchi in neighbouring Tamil Nadu. The booking was straight forward and the estimated bill was around Rs 13,000. The night before, I transferred Rs 10,000 into Ola Money wallet since that was the wallet limit. On the day of the trip, the driver arrived on time and we were preparing to start. This is when the trouble started.</p><p>After I gave the OTP (one-time-password) to the driver, the Ola system revealed the destination to the driver! The driver was taken aback that it was a 3 -day trip to another state. He did not have original license papers to cross state boundaries. This was the driver’s first outstation trip and yet he had 4.5+ stars on his profile. He did not even bring an extra pair of clothes for the trip. He was that unprepared.</p><p>Since the OTP was entered, Ola considered the trip as started. For an outstation trip, the driver needs to enter the odometer reading which the customer has to confirm — at the start of the trip and at the end of the trip. The driver incorrectly entered the OTP (4-digit) instead of the odometer reading (113000+) — in other words, the Ola system considered that I already travelled 100,000 km before even starting at home!! Given this misstep, we panicked about its implications. There is no way to call Ola help from the app. So the driver called the partner number and after a long discussion on what to do, the support person said the start odometer cannot be changed at this point, and the help centre should be called after the trip ended to iron this out. I was very concerned about this.</p><p>The driver was getting concerned that he did not have the original license papers in the car. He was hesitant to cross the border because the vehicle could be impounded. He wanted to cancel the trip. So we call back the partner service centre and they try to dissuade me from doing it. Instead, they wanted me to take a 1-hour detour to the driver’s house to pick up the papers. I didn’t want my parents to sit in the car for an additional 2 hours for a total of 9-hour journey. After talking back and forth, they inform us about the procedure to cancel the trip. So the trip was ended before it even started. And lo and behold, I was charged Rs 13000 for the trip — Rs 10,000 was deducted from my Ola Money account, Rs 500 from a postpaid account. I was asked to pay the rest in cash to the driver!! This stunned me.</p><p>So we call the customer care again and ask them what to do. After a long discussion, I was told not to pay the remaining in cash to the driver. But the obligation of collecting the remaining Rs 3000 from me and giving it to Ola would still remain on the driver’s account — in other words, no more rides would be assigned to him until he clears his dues! He also became another victim in this Ola outstation mess.</p><p>The customer service person told me that a refund would be processed and both my account and the driver’s account would be cleared up. Now, if you know how things work in India, this is easier said than done. Companies don’t return money easily.</p><p>I called the customer service centre every day to inquire about the status. Every customer service rep would assure me the highest priority in handling the refund and it would be done in just 1 day, 2 days, 48 hours etc. But I realized the first line of customer service agents is not there to help solve the problem. Their objective is to tire the customer so that they would simply go away. When I insisted to talk to the next level, the next level is mysteriously not available or cannot be contacted. They would promise to call back and that never happens. This is the sorry state of Ola customer service.</p><p>Anyway, given the amount involved, I had no choice but to be patient and persistent. Eventually, I was able to reach a supervisor who promised that it would be refunded in 48 hours. It didn’t happen. Ola has a long list of excuses for bad customer service. I kept on persisting and after 2 weeks, the first attempt was made to refund. It turned out that they could not refund because of KYC limits which only allows Rs 10,000 a month to be added to Ola Money (I had added Rs 10,000 earlier in the month for the outstation trip. Apparently, the reversal counts as another addition which makes no sense). Having hit the limit, the only option is to either complete the KYC or wait for the following month. I planned to do both in parallel.</p><p>Ola outsources KYC verification to third parties. The KYC verification can either be done in the car or an in-person verification. I opted for in-person verification and I was in for another rude shock. I get a call one day from a person with a threatening voice to give him the OTP on the phone for KYC verification. I asked him why. I expected a person to visit me, but no such thing happened. Ola is, knowingly or unknowingly, being scammed by the KYC verification operators. There is absolutely no check of the documents whatsoever. I called the Ola Security team about this, and they said they will look into this and that was the last I heard about it. Yet another area where Ola is seriously failing. It raises serious questions on what kinds of verification is being done on drivers too.</p><p>Eventually, the new month comes around, and I expected a refund on March 1. It didn’t happen. After calling a few times, the refund finally happened. After more than 2 weeks of persistent follow-ups.</p><p>Now that Rs 10,000 has been credited to the Ola Money account, what do I do with so much balance? I would have to a whole lot of local trips. I looked to see if I could withdraw it to my bank. Turns out it is not free — I have to pay almost 5% to withdraw my own money. So I am looking at where else I could use Ola Money wallet. Ola Money app lists a bunch of companies that accept it but the list is outdated and nobody has bothered to update it. For example, I tried to use it for my ACT Fibernet account and Ola Money was refused. So the reach of Ola Money wallet is rather limited at this point. I am still on the hunt for opportunities to use Ola Money and reduce my balance to zero.</p><p>So that was my saga with Ola Outstation. The purpose of this article is to highlight issues and propose some ideas on what Ola could do, and how the customers can protect themselves.</p><h3>Issues and Proposals</h3><ol><li>Hiding the destination: Ola hides the destination from the driver until the OTP is entered. For outstation trips, this is a bad strategy. The driver can come unprepared — without documents or extra clothes. For outstation rides, Ola must reveal the destination at the very outset.</li><li>The driver should carry original insurance and license papers: Ola must alert the driver to carry original licence papers and prepare for the outstation trip before reaching the customer destination. The customer should be asked to verify the documents before giving the OTP to start the trip.</li><li>The driver getting confused between OTP and Odometer reading: This is a rather basic problem and can be misused to overcharge the customer. Customers must make sure that the driver entered the correct odometer reading before acknowledging. Ola should train the driver on the differences.</li><li>Ola Money balance: Customers should think twice before using Ola Money wallet for outstation trips. Since the amount for outstation trips is usually large, and when things go wrong, you will lose a lot of money unless you call Ola many many times. It is best to use the cash option for outstation trips. Ditch the Ola Money wallet. Make sure your balance is not over Rs 500 at any time.</li><li>Refunds by Ola Money: Ola must ensure that refunds must be initiated within 24 hours. In my case, it took more than 2 weeks. Apparently, there is too much paperwork in Ola to initiate the refund. Ola should trim the red-tape.</li><li>Customer service: The customer service agents at Ola are working hard to erode the trust of the customer and not enhance it. They should mean what they say. If they give a timeline to the customer, they should communicate with the customer each day at the end of the day to update the customer on the issue. Customer service should pre-emptively call the customer in order to prevent a repeat call. Every repeat call should be regarded as a failure of rapid action.</li><li>Ola KYC —there is a serious issue here. The whole thing is a scam. There is no verification of any sort. Ola must get its act together quickly. Customers are warned not to give the OTP to anybody on the phone. Ola security team does not seem to be following up on security issues with the level of urgency that is required.</li><li>Ola Money Wallet: This has a pretty limited acceptance. I would be concerned about recharging this if it has limited uses for the fear of having a high unusable balance. To counter this apprehension, Ola can offer free withdrawals to the bank and not charge 5%. Once people know they can withdraw for free, they won’t mind money sitting there unless really needed.</li><li>Ola Money App: The “Do more with Ola Money” tab is outdated. Every icon in it should work. Some companies listed there (ACT Fibernet) don’t accept Ola Money.</li><li>Smartphone used by the driver: Drivers use very old smartphones to save costs. In my case, the android phone he used was so bad that he could barely enter numbers (such as OTP and odometer). The Ola app may not be working as designed on older smartphones. If it is an old smartphone or is malfunctioning, how can the driver and the customer be sure that they can contact Ola at all times during the trip? This also raises security issues.</li><li>Old vehicles: Many drivers buy rather old vehicles that may be poorly maintained. On outstation trips, this can result in a breakdown of the vehicle and cause problems to the customer. Ola should guarantee to the customer that if the vehicle breaks down during the outstation trip, they will take care of all expenses. Ola should ensure that vehicles they accept for outstation are no more than 5 years old and less than 50,000 km. The driver on this trip came with an odometer reading exceeding 113000 km.</li><li>Call back at the end of the trip: Normally, if there is an issue, the customer needs to call the customer service after digging through the menus. The customer service opens an issue and they take 24–48 hours to resolve the issue. Ola can do something different. When a trip ends, they should display a prominent button that would allow customers to seek immediate call back if there is an issue with the trip. Customers can use this call for any refund issues or any other dispute during the trip. The important message to deliver to the customer is that in the time of need — that is while settling money for the trip — Ola will be available instantly to resolve any issues. This is akin to the “Emergency” button that is available for safety reasons during the trip.</li></ol><h3>Conclusions and Next Steps</h3><p>Ola Outstation is a new offering from Ola but my experience with it has revealed several flaws. While designing complex systems, companies like Ola must be paranoid about worst-case scenarios and prepare adequately. Only then they will excel in customer satisfaction. Otherwise, they will always be in fire fighting mode. All the issues I have highlighted are fixable. If fixed, Ola will gain customer loyalty, trust, and stickiness.</p><p>What say you, Ola? Will you fix these issues?</p><p><em>PS: You might be wondering whether we made the temple trip finally. Yes, we did. In my own car. So much for Ola Outstation.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3677a5c5cc59" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reducing the Spread of Fake Messages on WhatsApp]]></title>
            <link>https://medium.com/@kiranachyutuni/reducing-the-spread-of-fake-messages-on-whatsapp-42e820f22b5e?source=rss-2891f1860cc8------2</link>
            <guid isPermaLink="false">https://medium.com/p/42e820f22b5e</guid>
            <category><![CDATA[privacy]]></category>
            <category><![CDATA[fake-messages]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[whatsapp]]></category>
            <dc:creator><![CDATA[Kiran Achyutuni]]></dc:creator>
            <pubDate>Wed, 27 Feb 2019 12:16:12 GMT</pubDate>
            <atom:updated>2019-02-27T12:51:43.382Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*p1rGRuOEnObN6KBe8iXOfA.jpeg" /></figure><h3>Summary</h3><p>WhatsApp is a very popular communication app used all over the world with over 1 billion users using the service. However, it has had its share of problems, the principal one being the extremely easy ability to spread false information to a large number of people quickly. On top of it, when the message appeals to the base emotional instincts of human beings, the reactions can be unpredictable. There have been cases where people have lost lives, been mobbed, or lost money due to the viral spread of false information. In this article, we present an idea based on the provenance of the message to reduce fake messages. A simple analysis shows that the spread of fake messages can be reduced by as much as 50%-70% if not more with this proposal. The implicit assumption is that when people know where the message originated from, they will decline to forward a message if the source is untrustworthy, thereby reducing the spread of false messages.</p><h3>Problem Statement</h3><p>A malicious user creates a message containing false information. He/She then forwards the message to a few people and groups. Some unsuspecting users read the message, <em>assume it is true</em>, and then forward it further to more people and groups, and this cycle continues without an end. If the message appeals to base emotional instincts, then the impact can be seen in the real world as in riots, killings, financial losses, etc. So what can be done to mitigate or eliminate this problem of viral propagation of false information without impacting the spread of genuine information?</p><h3>Incidents of Viral Fake information</h3><p>There have been several reported incidents across the world in recent years of viral fake information that has caused <a href="https://www.nytimes.com/interactive/2018/07/18/technology/whatsapp-india-killings.html">death</a>, <a href="https://www.wired.com/story/how-whatsapp-fuels-fake-news-and-violence-in-india/">grave injury</a>, <a href="https://www.msn.com/en-gb/money/technology/5-dangerous-whatsapp-scams-you-need-to-know-about/ar-BBOElBs">financial losses</a>, and mental stress for people who are victims of such viral incidents. Facebook, Google, and Twitter have taken steps to mitigate the spread of false information but there is still more to do before the problem can be really controlled. This article provides one solution to mitigate the problem.</p><h3>Anatomy of a viral message</h3><p>In order to understand how a viral message propagates, we must dive deep into the conditions and anatomy of a viral message transmission.</p><p>A viral message must contain the following pieces of machinery:</p><ul><li>An engaging message.</li><li>An ever-expanding audience that is willing to forward it further if they want to.</li></ul><p>In order to facilitate forwarding, these conditions should be satisfied:</p><ul><li>Unlimited audience available</li><li>The monetary cost of forwarding is zero</li><li>Forwarding to multiple groups and people is not cumbersome</li></ul><p>Even when all of these enabling factors are present, in the final analysis, it is people who are clicking on the “forward” button to send the message onward, and people will share something if they feel it would be of use to their network or it will benefit them personally. So it is a deeply personal decision as to whether to forward a message or not. (<a href="https://www.indiatoday.in/fyi/story/anatomy-of-a-whatsapp-forward-why-people-spread-fake-news-1389242-2018-11-15">India Today</a> had a good analysis of why people forward a message). However, before a message is forwarded, WhatsApp can provide more relevant data to the user in order for the user to make the decision wisely.</p><h3>Tackling the Problem</h3><p>The problem of mitigating the spread of fake information can be tackled in many independent ways:</p><ul><li>Control the source of the message</li><li>Control the content of the message</li><li>Control the spread of the message</li></ul><p>Controlling the source of the message: Since one can’t really ban users on WhatsApp, this is not really an option. However, this would be useful on Facebook and Twitter platforms, and indeed this solution is being applied to cleanse the platform of bad actors.</p><p>Controlling the content of the message: This requires sophisticated technology solutions. In particular, WhatsApp should deploy machine learning algorithms to read the messages and flag it for fake content. However, determining what is fake automatically is notoriously difficult and research into this is still at a very early stage. So this solution is beyond the horizon right now.</p><p>Controlling the spread of the message: WhatsApp has implemented some controls on the spread of messages to 5 <a href="https://blog.whatsapp.com/10000647/More-changes-to-forwarding">groups/chats</a> at a time. Since a group can contain 256 users, a message can still reach 1280 users in one step, and each user can forward it to further 1280 users. In effect, it is still a very large number of users. I would categorize this to be a brute force method of limiting the spread.</p><p>Can one do better? Are there other solutions out there? Sure, they are.</p><p>The <a href="http://www.ifla.org/">International Federation of Library Associations and Institutions (IFLA)</a> provides this handy poster to spot <a href="https://en.wikipedia.org/wiki/Fake_news">fake news</a>, and this can be generalized to spot fake information as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*Z0FOGgMfB4BV73WxvxjIHw.jpeg" /></figure><p><em>Every WhatsApp forwarded message lacks crucial pieces of information — namely, who was the original author? when was the message created? </em>As a result<em>, </em>the recipient is unable to fact check and has no way to figure out if it is valid or not. He/She <em>trusts</em> it to be valid because their friend sent it, and herein lies the crux of the problem. <strong>If there was some way to tag the message with the information of the original author and keep it persistent no matter how many times the message is forwarded, then every recipient can judge for themselves if the <em>original author can be trusted</em> to forward the message further.</strong> In other words, this is a crowd-sourced way of controlling the spread of fake information. Every person that refuses to forward will ensure that 1280 people (and more) downstream will not get the messages. Only information vetted by people will get to the broadest set of the population.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*EoVZz-cppx99SvMuqvu-yg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*0ADJNDb5WJaTxqoAPHvrfA.jpeg" /><figcaption>The image on the left is the current WhatsApp forwarded message (as of Feb 2019). The image on the right is the proposed new structure for WhatsApp message that shows the original sender profile name, phone number, date created, and the number of forwards, and the business verified icon.</figcaption></figure><p>The image on the left is the current WhatsApp forwarded message (as of 2019). The image on the right is the new WhatsApp forwarded message structure I am proposing. The following icon in the message may appear</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/41/1*GL7jasZobTkFy3ARhVzmxg.png" /></figure><p>if the <em>original</em> sender is a business entity (e.g., Banks, Government Agencies, registered businesses) verified by WhatsApp. This icon is currently seen in WhatsApp in the profile name of the user but is lost when the message is forwarded. Adding this icon to the forwarded messages enhances the trust in the message.</p><p>The proposed new WhatsApp message has a number of advantages:</p><ul><li>Since the profile name and number is available, the recipients can quickly make a decision to determine if they are trustworthy.</li><li>Since the profile name and number will be sent, it would act as a deterrent to malicious users — since they can be easily traced if they create mischief.</li><li>Since the business verified icon is available, it would easy for recipients to trust that the original sender was a legitimate business.</li><li>Since the profile name and number are available, the recipients can easily verify if the messages originated outside the country and not fall prey to offshore scammers.</li><li>Since the date is available, the recipients can determine if it is old information and decide not to act on it.</li><li>Since the number of forwards is available, the users can determine how many other recipients read the message, felt it was trustworthy, and then forwarded it. So the larger the forward count, the more trustworthy it is.</li></ul><p>The disadvantages include the following:</p><ul><li>Recipients may not be able to determine if the original sender was trustworthy or not by just looking at their name and phone number. So some number of recipients will simply continue to forward as usual. However, when people see unknown phone numbers, they will usually hesitate in forwarding.</li><li>User’s privacy could be impacted when the message gets spread because the new WhatsApp message would display the original author’s information. One way to counter this is for WhatsApp to offer an option to disable forwarding of messages by default and give an option to enable it on a per message basis. WhatsApp users could use this option to prevent the forwarding of their message and by default, forwarding is off. If the users choose to allow their message to be forwarded for a particular message, then they also accept the accountability that comes with it. Unless users accept responsibility for their messages, social media would not become a safer place.</li></ul><p>Let me explain with an example of financial scams. Let’s say you get a WhatsApp message asking you to call the bank customer service centre to reset your bank password because of a breach of security. In your anxiety, you call the number. Sure enough, it is a fake. In fact, you are calling a fake customer service centre whose main job is to get the account number and password from you. A few days later, you find that your bank account has been wiped empty.</p><p>If the WhatsApp message had the original sender profile information of the bank and the verified business icon, it would enhance the trust in the message. Fake messages would not have this verified business icon. Some recipients will now recognize fake messages and would not be fooled into taking any action. If however, some recipients get tricked into taking action, they now have a remedy. Since the original sender’s phone number is available, the police can trace the person quickly and take action. Either way, the outcome is good and this will mitigate financial scams.</p><h3>Analysis</h3><p>So, by how much can the spread be controlled by this method? Let’s do a simple mathematical analysis.</p><p>For the sake of simplicity, let’s assume each time a message is forwarded, it would reach <em>n</em> people, where <em>n</em> is some number less than 1280. So after 3 forwards, the number of people it would reach are <em>n</em>³, after 4 forwards, it would be <em>n</em>⁴, after 5 forwards, it would be <em>n</em>⁵ and so on.</p><p>Given that we don’t know for sure how many people will refuse to forward after seeing the original sender’s information, let’s use the well known <a href="https://en.wikipedia.org/wiki/Pareto_principle">80–20 principle </a>— namely, 80% of the people will continue to forward as before, and a mere 20% will refuse to forward. If we do the analysis again, then after 3 forwards, the number of people it would reach are .8³*<em>n</em>³ = 0.51*<em>n</em>³. In other words, in just 3 forwards, almost 50% of the spread would be contained. After 4 forwards, it would be .8⁴*<em>n</em>⁴ = 0.4*<em>n</em>⁴ (or 60% reduction), and after 5 rounds, it would be .8⁵*<em>n</em>⁵ = 0.32*<em>n</em>⁵ (or about 68% reduction).</p><p>That’s a massive reduction in the spread of fake messages with this simple enhancement! And we are not even taking into account the deterrent effect of sharing the original sender’s profile information.</p><h3>What is provenance and why it is important</h3><p>The information about the original source is extremely important and is part of what is known as <a href="https://www.merriam-webster.com/dictionary/provenance">Provenance</a>. It has played a fundamental role in many fields across centuries — from diamond trade, food supply, art and antiques, to modern day transaction processing, banking, and even blockchain. The fact of the matter is that if the source is anonymous, bad or corrupt, it would have implications downstream. This is why KYC (know your customer) mandates exist.</p><p>In the context of social media, some fundamentals tenets of provenance are broken and hence the mess all around. For example, if you can freely forward messages anonymously, then havoc results (as in mob violence due to viral WhatsApp fake messages, or tampered elections in case of Facebook and Twitter).</p><p>By adding the provenance information — namely name, phone number, date created — malicious users will be deterred in spreading false information. Because the verified business icon is present in case of messages from genuine organizations, the spread of genuine information will not be impeded on WhatsApp.</p><h3>Design</h3><p>This section goes into the implementation aspects and is directed towards computer engineers. Others readers may skip this section safely.</p><p>It is a small design change for WhatsApp to implement these changes. In order to make the original sender’s information persistent across any number of forwards, WhatsApp will have to add a new section in the internal message format to save the original user profile information, such as phone number, name, date, and a flag to indicate whether the user has allowed the message to be forwarded. The flag is important in order to give control to the original sender the ability to control the spread of the message by the recipients.</p><p>The first time the message is sent, this information needs to be saved in the persistent section and surfaced to recipients every time. If the original has set the flag to prevent forwarding, then the recipients cannot forward the message anymore. If on the other hand, the original flag allows forwarding, then every recipient will see the original sender’s profile information.</p><p>Adding the total number of forwards to the message is a bit more complex as it would require the WhatsApp client to contact a central server to update the forward count each time it is forwarded. There are many highly scalable solutions (such as <a href="https://redis.io/">Redis</a>) to implement a simple message forward counter for a given message id.</p><p>Overall the complexity of the effort to implement these suggested changes is rather minimal. In my estimate, it would take less than 1 month for the WhatsApp team to implement these changes and deploy them.</p><h3>Conclusions and Next Steps</h3><p>In this article, I have presented a simple enhancement to WhatsApp messages that can control the spread of fake information by as much as 50%-70% if not more. In addition, the proposal is also a deterrent to would-be malicious users. The proposal itself is very simple and could be implemented in less than a month by WhatsApp.</p><p>Given that the spread of fake information is rampant with grave consequences to people and countries, the tech companies should speed up their efforts and take the ideas wherever they come from. Governments are already stepping in to contain this problem and the urgency to solve the problem can be noted in this <a href="https://www.washingtonpost.com/opinions/global-opinions/india-is-lashing-out-at-internet-platforms-it-could-threaten-communications-worldwide/2019/02/25/8fd2ac4e-392e-11e9-a2cd-307b06d0257b_story.html?utm_term=.03810978472c">Washington Post editorial.</a></p><p>It is my hope that this idea would be considered by the WhatsApp team and implemented appropriately based on the additional usage data they have internally. India’s elections are coming up in May 2019. It would be good to see a solution that mitigates the spread of false information by election time. The best part is that the solution would save many lives for years to come and make WhatsApp a safer platform.</p><p><em>PS: If you know anybody on the WhatsApp team, please share this article with them.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42e820f22b5e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>