<?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 Ravish Rawal on Medium]]></title>
        <description><![CDATA[Stories by Ravish Rawal on Medium]]></description>
        <link>https://medium.com/@ravishrawal?source=rss-d78a4cdb27d6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*o4-a1S5yMXKtQK7d.</url>
            <title>Stories by Ravish Rawal on Medium</title>
            <link>https://medium.com/@ravishrawal?source=rss-d78a4cdb27d6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 05:07:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ravishrawal/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 the India ULIP API Stack is Redefining Vehicle Management for the Travel Industry]]></title>
            <link>https://ravishrawal.medium.com/how-the-india-ulip-api-stack-is-redefining-vehicle-management-for-the-travel-industry-aa77b8387f0b?source=rss-d78a4cdb27d6------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa77b8387f0b</guid>
            <dc:creator><![CDATA[Ravish Rawal]]></dc:creator>
            <pubDate>Thu, 09 Jul 2026 21:32:14 GMT</pubDate>
            <atom:updated>2026-07-10T09:26:38.145Z</atom:updated>
            <content:encoded><![CDATA[<p>My family has been in the travel industry for half a century, and one thing that’s always been a stressor is knowing where their clients are in real time so they can coordinate tour guides, get ahead of delays, and curate delightful moments. Early days, I watched my parents on-call 24/7 coordinating with drivers on their phone.</p><p>At larger scale, this turns into operational chaos. How do you seamlessly track vehicles across state lines? How do you ensure your drivers are fully compliant without manual log checks? And how do you provide anxious travelers with absolute transparency regarding their journey milestones?</p><p>Traditionally, the answer has been standalone, hardware-dependent GPS tracking devices. But hardware can fail, signals can be jammed, and devices can be unplugged.</p><p>Enter the Unified Logistics Interface Platform (ULIP) API stack. Originally envisioned as a digital public infrastructure to streamline nationwide commercial logistics, this government-backed API framework is quietly becoming the ultimate competitive advantage for forward-thinking travel and passenger mobility companies.</p><h4>What is the India ULIP API Stack?</h4><p>ULIP acts as a secure, decentralized digital gateway that integrates diverse databases from multiple government ministries – such as the Ministry of Road Transport and Highways (MoRTH) – into a single, cohesive ecosystem.</p><p>Instead of navigating fragmented web portals or relying on physical paperwork, travel platforms can integrate secure, real-time APIs directly into their proprietary reservation or fleet management systems.</p><p>For the travel sector, the core value lies in three main pillars: Vahan, Sarathi, and FASTag.</p><h3>The Power Trio: Deconstructing Vahan, Sarathi, and FASTag</h3><h4>1. The FASTag API (The New Location Intelligence)</h4><p>While everyone knows FASTag as the electronic toll collection system that eliminated cash lines at plazas, its true superpower is the digital trail it leaves behind. Every single time a vehicle passes through a toll gate, a tamper-proof timestamped transaction is recorded. The FASTag API allows operators to tap into this data instantly.</p><h4>2. The Vahan API (Instant Vehicle Health &amp; Compliance)</h4><p>Operating passenger transport requires stringent adherence to safety laws. The Vahan database is India’s central registry for all motorized vehicles. Through the Vahan API, a travel company can instantly query a vehicle’s registration details, fitness certificate expiry, commercial national permits, and active insurance coverage.</p><h4>3. The Sarathi API (Verified Driver Guardrails)</h4><p>Passenger safety is the absolute foundation of brand trust. The Sarathi API links directly to the national driving license registry. It enables automated driver onboarding by verifying license validity, checking for authorized vehicle classes (e.g., commercial transport vs. private), and confirming that the driver has no active suspensions or blacklists.</p><h3>Revolutionizing Vehicle Tracking: Moving Beyond Traditional GPS</h3><p>While GPS provides continuous breadcrumb tracking, integrating it with the ULIP stack – specifically FASTag data – creates a multi-layered tracking mechanism that solves critical vulnerabilities.</p><blockquote>“Hardware-backed tracking can be bypassed, but infrastructure-backed tracking cannot.”</blockquote><p>Here is how travel companies are deploying ULIP for bulletproof tracking:</p><ol><li>Checkpoint-Based Geo-Fencing: Every toll plaza across India effectively becomes a verified physical checkpoint. When a vehicle crosses a toll gate, the FASTag API triggers a real-time event log in your dashboard.</li><li>Anti-Tampering and Fraud Prevention: Drivers can occasionally unplug standard OBD tracking devices or experience cellular dead zones. A physical FASTag scan at a government-monitored toll booth cannot be spoofed, offering undeniable proof of a vehicle’s route progression.</li><li>Dynamic ETA Refinement: By mapping the exact timestamps of a vehicle across successive toll plazas, travel operators can cross-reference historic transit averages to provide customers with highly accurate, dynamic Estimated Times of Arrival (ETAs).</li></ol><h3>Broader Industry Applications Across the Travel Sector</h3><p>The operational efficiency gained from the ULIP stack expands across various segments of passenger transit:</p><h4>Intercity Coach &amp; Bus Operators</h4><p>Long-distance passenger coaches frequently cross state borders where permit checks are mandatory. By utilizing the Vahan API, operators can run automated pre-trip audits to confirm that national permits and fitness certificates are active, eliminating the risk of steep border penalties and unexpected trip delays.</p><h4>Corporate Car Rentals &amp; Employee Transport</h4><p>For enterprises managing thousands of daily corporate employee commutes, driver verification is non-negotiable. HR and transport teams can use the Sarathi API to completely automate driver screening during onboarding, ensuring that only certified, vetted professionals handle employee transport.</p><h4>Self-Drive and Rental Car Platforms</h4><p>For self-drive car companies, tracking where vehicles go and managing expenses is complex. The combination of FASTag tracking and Vahan data allows platforms to see exactly when a vehicle enters a new state, automatically reconcile toll charges back to the user’s credit card, and ensure the vehicle’s fitness parameters remain fully compliant.</p><h4>Drawing Technical Inspiration</h4><p>Building a high-scale fleet monitoring and compliance dashboard requires looking at architectures that successfully harness these real-time API integrations.</p><p>In looking at how industries navigate vehicle validation and seamless toll mapping, platforms like Fastag Tracking (fastagtracking.com) and LorryCare (lorrycare.com) offer good blueprints, still leaving much to be desired. They demonstrate how automated APIs can be elegantly stitched together to provide centralized tracking, instant vehicle health checks, and secure operational insight.</p><p>By applying similar robust architectural patterns, travel companies can engineer tailored customer dashboards that offer travelers total peace of mind and provide operations teams with complete situational awareness.</p><h4>Conclusion: The API-First Travel Enterprise</h4><p>The future of passenger transit in India belongs to operators who build on data, trust, and automation. Relying on manual spreadsheets and isolated hardware tracking is no longer sustainable in a hyper-competitive market.</p><p>By integrating the India ULIP API stack, your travel brand can assure corporate clients, tourists, and daily commuters that every vehicle is legally compliant, every driver is certified, and every single mile of the journey is backed by secure, nationwide digital infrastructure.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa77b8387f0b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Payment Foundation Models via Transformer-Based Transaction Embeddings]]></title>
            <link>https://ravishrawal.medium.com/payment-foundation-models-via-transformer-based-transaction-embeddings-fdf2961cac95?source=rss-d78a4cdb27d6------2</link>
            <guid isPermaLink="false">https://medium.com/p/fdf2961cac95</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[payments]]></category>
            <category><![CDATA[transformers]]></category>
            <dc:creator><![CDATA[Ravish Rawal]]></dc:creator>
            <pubDate>Wed, 20 May 2026 15:12:49 GMT</pubDate>
            <atom:updated>2026-05-20T15:12:49.848Z</atom:updated>
            <content:encoded><![CDATA[<p>In global financial technology, traditional machine learning architecture has reached a point of diminishing returns. For years, the industry baseline for fraud detection, authorization optimization, and chargeback prediction relied on a fragmented ecosystem: a siloed ensemble of Gradient Boosted Decision Trees (XGBoost) and logistic regression models, each custom-fed with hand-crafted, domain-specific features.</p><p>While effective for isolated tasks, this approach is fundamentally brittle. It fails to capture the holistic behavioral lifecycle of a shopper or the systemic structural patterns of global commerce. It ignores the sequential nature of transactions, treats highly related entities as isolated categorical indices, and demands immense data-engineering overhead to maintain thousands of engineered features.</p><p>A paradigm shift is underway. By treating financial transactions not as static database rows, but as a structured language, we can build a <strong>Payments Foundation Model (PFM)</strong>. Leveraging Transformer architectures and self-supervised learning, a PFM learns the deep contextual “grammar” of global money movement. The primary engine of this system is the generation of dense, high-dimensional <strong>Behavioral Transaction Embeddings</strong> that capture latent risks and identities across the entire payment lifecycle.</p><p>Here is an architectural deep dive into how payments foundation models operate, how to handle tabular financial multi-modalities, and how to implement them in production.</p><h3>1. The Core Paradigm: Payments as a Language</h3><p>In Natural Language Processing (NLP), a sentence is a sequence of discrete tokens (words) governed by syntactic rules. In global payments, an entity’s financial history (whether a cardholder, a tokenized device, or a merchant endpoint) is a chronological sequence of transactions.</p><p>Each individual transaction is itself a multi-modal composition of high-cardinality categorical attributes and raw numerical data:</p><p><strong>Feature ClassExamplesDomain ComplexityHigh-Cardinality Categorical</strong>Bank Identification Number (BIN), Merchant Category Code (MCC), Merchant ID, Acquirer IDHundreds of thousands of unique classes; semantic similarities are hidden by arbitrary ID assignments.<strong>Low-Cardinality Categorical</strong>Currency Code, Country Code, Card Brand, Entry ModeDense localized regularities (e.g., cross-border behavior patterns).<strong>Numerical/Continuous</strong>Transaction Amount, Time Delta (since last attempt), Velocity CountsHeavily skewed distributions; highly sensitive to local temporal contexts.</p><p>Instead of feeding these raw elements into isolated classifiers, a PFM projects them into a unified continuous vector space — a <strong>Transaction Token</strong>. A time-series sequence of these transaction tokens is then passed through a Transformer stack, enabling the network’s self-attention mechanism to uncover cross-transactional dependencies over time (e.g., identifying card-testing scripts, velocity anomalies, or systemic merchant churn).</p><h3>2. Technical Architecture: Inside the Transaction Encoder</h3><p>Transforming structured payment logs into a sequence capable of feeding a Transformer encoder requires an intricate input-processing pipeline.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xmCq91GzhUdJL7aKpd8VPg.png" /></figure><h3>Mapping Categoricals to Continuous Spaces</h3><p>Arbitrary identifiers like MCC 5812 (Eating Places) and 5814 (Fast Food Restaurants) share deep semantic connections. Hand-coded models require manual feature grouping to capture this. In a foundation model, we map every high-cardinality feature to a learned embedding layer. Through optimization, the model naturally clusters similar codes together based on their structural context.</p><h3>Discretizing and Encoding Continuous Data</h3><p>Transformers are notoriously sensitive to raw unscaled continuous inputs. Feeding a raw dollar amount (e.g., $10,450.00) directly next to a flag of 0 or 1 destabilizes gradient propagation. To fix this, continuous features undergo mathematical transformations:</p><ul><li><strong>Non-linear scaling:</strong> Applying power transformations (like Box-Cox) or log-scaling to compress heavy-tailed monetary distributions.</li><li><strong>Quantization/Binned Embeddings:</strong> Dividing values into data-driven quantiles (e.g., 100 buckets for transaction sizes) and treating each bucket as a token, or applying sinusoidal encodings directly to time deltas to capture multi-scale periodicities (hourly, weekly, seasonal spending habits).</li></ul><h3>3. PyTorch Implementation: The Transaction Foundation Layer</h3><p>The following implementation showcases a structural module that ingests structured transaction components, builds unified transaction tokens, and routes them through a Transformer core to produce dense behavioral embeddings.</p><h3>4. Self-Supervised Pre-Training: Overcoming Labeled Data Constraints</h3><p>The primary bottleneck in traditional financial machine learning is the reliance on explicit target labels. Fraud labels are highly imbalanced, subject to immense human review noise, and inherently lagged — often taking 30 to 60 days to stabilize via formal banking chargeback cycles.</p><p>To build a true foundation layer, the model must be trained via <strong>Self-Supervised Learning (SSL)</strong> on the trillions of raw, unlabeled transactions passing through payment rails daily. By designing pretext tasks rooted in the structure of the data itself, the model learns comprehensive payment patterns before a single downstream task is introduced.</p><h3>Pretext Task A: Masked Feature Modeling (MFM)</h3><p>Taking inspiration from masked language models like BERT, we randomly corrupt or completely mask categorical fields (e.g., hiding the Merchant ID or MCC) or continuous fields within a specific historical transaction sequence. The network is optimized to predict these masked fields based entirely on the preceding and succeeding transaction contexts. To solve this task, the model must internally map out complex relationships, such as which card types are typically used at specific retail sectors within distinct geographic boundaries.</p><h3>Pretext Task B: Contrastive Sequence Cohherence</h3><p>Payment scripts and automated bots generate disjointed, chaotic transaction paths. We train the model to distinguish a true chronological sequence of transactions executed by a single valid shopper from a corrupted sequence where transactions from another user are mixed in. The model minimizes a contrastive loss function (such as InfoNCE), mapping coherent organic spending histories close together in vector space while forcing anomalous, disjointed tracks far apart.</p><h3>5. Downstream Integration: One Embedding to Power the Risk Stack</h3><p>Once pre-trained across billions of historic payments, the model’s parameters can be frozen, or fine-tuned. Instead of running dozens of isolated models, engineering teams can pass raw data through the frozen foundation network to generate a single vector: the <strong>Universal Behavioral Transaction Embedding</strong>.</p><p>This single embedding acts as a shared contextual signal that powers multiple downstream micro-networks simultaneously:</p><ul><li><strong>Fraud Scoring Head:</strong> A lightweight multi-layer perceptron (MLP) reads the embedding at inference time to output a probability of fraud within sub-10ms. Because the embedding already captures multi-layered sequence behaviors, the fraud model achieves near-optimal Area Under the ROC Curve (AUC) numbers out of the box, even on unseen card categories.</li><li><strong>Dynamic Routing &amp; Auth Optimization:</strong> Payments can fail due to legacy bank infrastructure or overly aggressive downstream filters. The embedding captures the exact semantic state of the issuing bank, the merchant category, and the regional path, allowing smart routers to dynamically adjust technical payment fields (e.g., routing through alternative acquiring networks or modifying messaging flags) to maximize authorization success rates.</li><li><strong>Smart Disputes (Chargeback Mitigation):</strong> Predicting whether a completed transaction will result in a subsequent commercial dispute. By mapping the user’s current interaction vector against historical profiles of chargeback-heavy behaviors, platforms can trigger proactive step-up authentication mechanisms or flag transactions for merchant holding queues.</li></ul><h3>6. Enterprise Scale and Production Deployment</h3><p>Running deep multi-layered Transformer architectures inside the synchronous path of a live payment authorization loop introduces strict operational constraints. When a customer clicks “Pay,” the payment gateway generally has less than <strong>100 milliseconds</strong> to assess risk, run optimizations, and format the request for the global card schemes. The PFM layer itself must execute its entire inference forward pass in under <strong>10 milliseconds</strong>.</p><p>To maintain this scale, production architectures use a series of optimization strategies:</p><ul><li><strong>Decoupled Sequencers &amp; KV Caching:</strong> Historical shopper transaction histories are cached out-of-band in low-latency in-memory databases (e.g., Redis Enterprise or specialized key-value stores). During a live transaction, the model doesn’t re-encode the entire historical sequence. Instead, it maintains a Key-Value (KV) cache of past transaction tokens, needing only to compute the attention weights between the incoming transaction and the pre-computed historical states.</li><li><strong>Model Quantization and Compilation:</strong> Models are compressed using FP16 or INT8 precision pipelines and compiled via specialized tensor runtimes (such as NVIDIA TensorRT or Apache TVM). This allows large foundation architectures to run across highly parallel GPU inference clusters with predictable sub-millisecond latencies.</li></ul><p>By moving past hand-coded tabular rules and adopting transformer-based representation networks, financial systems gain a foundational understanding of the global economy — delivering better conversion rates, reduced fraud, and a robust architecture ready for future transaction patterns.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fdf2961cac95" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Transforming Natural Language Understanding]]></title>
            <link>https://ravishrawal.medium.com/transforming-natural-language-understanding-c1ac7f57613f?source=rss-d78a4cdb27d6------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1ac7f57613f</guid>
            <category><![CDATA[attention]]></category>
            <category><![CDATA[transformers]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Ravish Rawal]]></dc:creator>
            <pubDate>Sat, 13 Nov 2021 00:12:41 GMT</pubDate>
            <atom:updated>2021-11-13T16:03:09.434Z</atom:updated>
            <content:encoded><![CDATA[<h3>Transforming Natural Language Understanding: Attention, GPT, BERT, and Switch</h3><p><em>Authors: </em><a href="https://medium.com/u/d78a4cdb27d6"><em>Ravish Rawal</em></a><em>, </em><a href="https://medium.com/u/4808661549d2"><em>Viren Bajaj</em></a></p><h3>History</h3><p>Modeling natural language has become one of the flagship successes of deep learning techniques. We see these techniques put to use at scale in many software systems, including the one on which this article is being written, Google Docs. You could say we complete each other’s <em>sentences</em>.</p><p>The program that is giving this recommendation is calculating the probability of the next words in the sentence given the ones already typed. This is one of the tasks that helps evaluate the effectiveness of a natural language model, simply known as sentence completion. This is just one of a variety of natural language tasks that modern deep learning systems are designed for and tested on. What each of these tasks have in common, though, is that the input data is sequential in nature. A word in a sentence derives its meaning from the context around it, and each sentence must consider those preceding it in order to pass as natural language.</p><p>The state of the art in NLP was constrained for three decades due to this sequential nature of the inputs. Recurrent Neural Networks (<strong>RNNs</strong>) are a form of feedforward neural networks, and work by generating a sequence of hidden states using, to compute each, both the prior hidden state and the current input. Thus, they need to be <strong>sequential</strong>, which makes parallelization during training impossible. That means they are <strong>slow</strong>, even using a truncated form of back-propagation. Further, for long sequences they suffer from vanishing &amp; exploding gradients, which prevents learning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hcBAl_1PVDtkA09V" /><figcaption>An unfolded RNN</figcaption></figure><p>LSTMs were introduced to address the gradient problem, and did advance the state of the art, but are more complex than RNNs, and still sequential. Read: they are <strong>even slower</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*v2OY9irtXZZjWl45" /><figcaption>LSTM cells</figcaption></figure><h3>Transformers (2017)</h3><p>Michael Bay wasn’t the only one to release Transformers in 2017 — Google Brain published a groundbreaking paper called “Attention Is All You Need,” which would set the stage for rapid advancements in the NLU state of the art. Their innovation, the Transformer, would eliminate the need for recurrence or convolution in deep learning on sequential data in their entirety. That meant inherently quicker models which could also take advantage of advancements in data parallelism and model parallelism.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*GBcPYgJFDTad07hQG4L0hw.png" /></figure><p>At their core, transformers were made up of 4 basic elements:</p><ul><li>Embeddings</li><li>Positional Encoding</li><li>Encoder Block</li><li>Decoder Block</li></ul><p><strong>Embeddings</strong></p><p>This is basically a lookup table to map words to learned vector representations with continuous values.</p><p><strong>Positional Encoding</strong></p><p>In order to preserve sequence position information we must inject some information about the relative position of each word in order to capture contextual information. There are many options for how to achieve this, but the authors chooses sine (for even timesteps) &amp; cosine (for odd timesteps) functions to embed positional information since this allows for linear representations of any given positional encoding in terms of a preceding positional encoding.</p><p><strong>Encoder Block</strong></p><p>The encoder’s job is to transform the input sequence into context vector representations for each unit in the sequence. Each encoder layer has a multi-head self-attention (more on this below) layer, and a simple, position-wise fully connected feed-forward network. Each sublayer uses layer normalization &amp; residual (or skip) connections. We can stack encoder layers in order to learn more complex representations.</p><p><strong>Decoder Block</strong></p><p>The decoder takes in the input sequence as well as an input from the encoder, and uses multi-headed attention to determine the appropriate decoder output for a given encoder input. After the multi-headed attention layers, the data goes through a feed-forward network, as well as a linear and softmax layer to map the probability distribution to the size of the vocabulary and select the most probable word.</p><p><strong>Attention</strong></p><p>At the core of transformer architecture is attention. Instead of encoding a whole sequence to a fixed context vector like in traditional RNN encoders, it develops a context vector filtered for each timestep. Most notably, transformers take advantage of a <strong>self-attention </strong>mechanism. This allows the model to determine the relevance of a word given the other words in the sequence.</p><p>The input is mapped to a <strong>query</strong>, <strong>key</strong> and <strong>value</strong>, which are all vectors. Analogies have been drawn to search engines which compare your <strong>query</strong> against a set of <strong>keys</strong> (metadata) associated with rows in the database, and return the best match <strong>values</strong> (results).</p><p>Transformers take advantage of scaled dot product attention, which reduces runtime and space, by using matrix multiplication &amp; taking advantage of optimizations for such operations on the GPU side.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/0*Drs_NM5MNgbn7Zya" /><figcaption>Attention Formula</figcaption></figure><p>Let’s break it down:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nn0PVoBJztgIMJNtfaWGUw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5bNJVXVe8pf3mzwxi1-6ew.png" /></figure><p>The query &amp; key are multiplied to generate attention scores.</p><p>These are then scaled down by the square root of dimensionality to prevent holding softmax in its saturated regions and avoid vanishing gradients.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*bP4WMwRk_JJr48PtBLYQLg.png" /></figure><p>Finally, we multiply these weights with the values to produce an output layer, which is processed through a linear layer to generate a result.</p><p>In terms of <strong>computational complexity</strong>, self-attention layers are faster than recurrent layers when the sequence length n is smaller than the representation dimensionality d, which is most often the case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OLCnCtn-FQ-VBRIs" /><figcaption>Time complexity of self-attention vs prior approaches</figcaption></figure><p>As a direct result of this, combined with the increased amount of computation that can be parallelized by minimising sequential operations, transformers improve on the state of the art both in terms of performance and training cost.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*n9yDFH1uQVXSxYrM" /><figcaption>Transformer performance benchmarked on machine translation tasks</figcaption></figure><p>Transformers have set the stage for massive jumps in performance for natural language and temporal models, and form the basis for advancements such as Open AI’s GPT models, Google’s BERT, and Google’s Switch Transformer.</p><h3>Improving Language Understanding by Generative Pre-Training (GPT)</h3><p>GPT is a language model based on transformers that achieved great success in its time by pre-training the model in an unsupervised way on a large corpus, and then fine tuning the model for different downstream tasks. This technique of performing task-agnostic training followed by fine tuning was distinguished from the training task-specific models, which had previously achieved state of the art performance.</p><h4>Unsupervised Pre-Training</h4><p>During pre-training, a neural network is used to maximize the likelihood of the next token given the previous k tokens. Concretely, given an unlabeled corpus <em>U= {u</em>₁<em>, u</em>₂<em>, …, u</em>ₙ<em>},</em> the likelihood <em>L₁(U)</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*HRIlwoKQt2nzezmZWhQWTQ.png" /><figcaption>Standard language modeling objective used in unsupervised pertaining</figcaption></figure><p>is maximized using stochastic gradient descent over the parameters 𝚯 of a transformer decoder (shown below), which models the conditional probability <em>P</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/0*afHPNTaRJcltOxMi" /><figcaption>Transformer architecture used in GPT during pre-training</figcaption></figure><h4>Supervised Fine Tuning</h4><p><strong>Objective Functions</strong></p><p>Once the transformer model has been pre-trained, a new linear (fully connected) layer is attached to the output of the transformer which is then passed through a softmax function to produce the output required for the specific task, such as Natural Language Inference, Question Answering, Document Similarity, and Classification. The model is fine tuned on each of these supervised tasks using labelled datasets. The the supervised objective function over a labelled dataset <em>C</em> with a data point: <em>(x = (x</em>₁<em>,…,x</em>ₘ<em>),y)</em> then becomes <em>L₂(C):</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*Mjt6MJ68FjVkfSTNzsbx4Q.png" /><figcaption>Supervised fine tuning objective function used in GPT</figcaption></figure><p>Sometimes to improve performance, language modeling objective (<em>L₁(C)</em>) is added to the fine-tuning objective with a regularization term to achieve the final loss <em>L</em>₃<em>(C):</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/1*GgY4WYGG6ATxMM5a_-4RGw.png" /><figcaption>Final objective during supervised fine-tuning for certain tasks</figcaption></figure><p><strong>Input transformations</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/1*dVvMCVYqWoySLFvlzjD0qQ.png" /><figcaption>Input transformations for different supervised fine-tuning tasks</figcaption></figure><p>Common to all taks is the fact that the input is sandwiching the input text in between randomly initialized <em>start</em> and <em>end</em> tokens.</p><p>In Classification, the standard input transformation of using a start and end token around the input text is used.</p><p>In Natural language inference (Entailment), the premise and hypothesis are separated by the delimiter token ($).</p><p>In (Text) Similarity, two texts are separated by the delimiter token ($) and passed through the transformer once, and then a second time with the order of the texts swapped. Each output is then concatenated and passed through the linear+softmax layer. This is because there is no inherent order present in a similarity task.</p><p>In the Multiple Choice Question Answering task, the context, question, and each answer is separated with a delimiter ($) and passed through the transformer and linear layer independently. Finally, the linear output of each possible answer is passed through a softmax to get a normalized probability distribution over possible choices.</p><h4>Performance of GPT</h4><p><strong>Natural Language Inference (NLI)</strong></p><p>GPT outperformed state of the art models on all NLI datasets except <a href="https://paperswithcode.com/dataset/rte">Recognizing Textual Entailment (RTE)</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Di1-w2xwu3aoXdQCsMLKMQ.png" /><figcaption>GPT Results on NLI tasks. 5x indicates ensemble of 5 models. Evaluation metric is Accuracy.</figcaption></figure><p><strong>Question Answering (QA)</strong></p><p>GPT outperformed other state of the art models on all QA datasets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*40ciOSf0QvQ-4jnOW0yK_w.png" /><figcaption>GPT Results on QA Tasks. 9x is an ensemble of 9 models. Evaluation metric is Accuracy.</figcaption></figure><p><strong>Similarity and Classification</strong></p><p>GPT outperformed on most semantic similarity and classification datasets except the <a href="https://paperswithcode.com/dataset/sst">Stanford Sentiment Treebank (SST2)</a> and <a href="https://www.microsoft.com/en-us/download/details.aspx?id=52398">Microsoft Research Paraphrase Corpus (MRPC)</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*79X6t2FdQGrpq4QmiwEYXQ.png" /><figcaption>GPT Results on Similarity and Classification. mc: Mathews Correlation; acc: Accuracy; pc: Pearson Correlation</figcaption></figure><h3><strong>BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding</strong></h3><p>BERT is a product of Google AI, and a truly creative spin on transformers and the attention mechanism. Transformer models are directional, that is, they read the text input sequentially. BERT uses just the transformer encoder, along with <strong>bidirectional self-attention</strong>, which reads the entire sequence of words at once, in order to learn the context of a word based on the sequence succeeding &amp; preceding it.</p><p>There are two BERT architectures: BERTBASE, with 110M parameters and 12 tranformer blocks, and BERTLARGE with 340M parameters and 24 transformer blocks. The implementation can be broken down into two steps: <strong>pre-training</strong> and <strong>fine tuning. </strong>These two steps allow for good performance using a smaller training corpus, since the pre-training step can use unlabelled data while relying on fine-tuning using labelled data to compensate for lost information.</p><h4>Unsupervised Pre-training</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/0*hufRX_pqBtBn1NX3" /><figcaption>BERT pre-training using MLM &amp; NSP</figcaption></figure><p>Pre-training on BERT can be broken down into two tasks, and trains using a combined loss of both:</p><ol><li><strong>Masked Language Model (MLM):</strong> 15% of the words in each input sequence are masked (replaced with a [MASK] token), and the model attempts to predict original value of each masked word.</li><li><strong>Next Sentence Prediction (NSP):</strong> Data are input as sentence pairs, separated by a [SEP] token. 50% of pairs are randomized, 50% are in their original sequence. The model attempts to predict whether the second sentence IsNext or NotNext. The NSP component of the loss allows BERT to be more generalizable to tasks like Question Answering and Natural Language Inference.</li></ol><h4>Supervised Fine Tuning</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/0*9yUWvoORjrSw-PxB" /><figcaption>BERT fine-tuning on a variety of natural language tasks</figcaption></figure><p>Fine-tuning with BERT is straightforward. It uses labelled data, and for each language model task, we simply plug in the task specific inputs and labels into BERT and fine tune all the parameters.</p><h4>Performance</h4><p>BERT shows performance improvements over the state of the art for 11 natural language tasks, and drastically reduces training time for transfer-learning models by requiring only hyper-parameter tuning for many NLP tasks. It is the first fine-tuning based representation model that achieves state-of-the-art performance on a large suite of sentence-level and token-level tasks, outperforming many task-specific architectures.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DYF8sPVcZbFbTSLb" /><figcaption>BERT Performance vs the SoTA on various GLUE benchmark tasks (<a href="https://gluebenchmark.com/">https://gluebenchmark.com/</a>)</figcaption></figure><p>The importance of its key innovation, bidirectional self-attention, is demonstrated in the ablation study below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*5lPhExQhGsH4GSubx9w_VA.png" /><figcaption>BERTBASE compared to an MLM-only model and an MLM-only, left-to-right (LTR)-only model</figcaption></figure><h3>Switch Transformer: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity</h3><p>Switch Transformers introduced by researchers from Google appears to be the largest language model to be trained till date. Compared to the other large models like Open AI’s GPT-3, which has 175 Billion parameters, and Google’s T5-XXL, which has 13 Billion parameters, the largest Switch Model, Switch-C, has a whopping 1.571 Trillion parameters! This model was trained on the 807GB “Colossal Clean Crawled Corpus”(C4). Their efforts to increase model size are based on research that suggests models with simpler architectures but more parameters, data and computational budget perform better than more complicated models.</p><h4>From Mixture of Experts (MoE) to the Switching Layer</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F8gtwPR0GKYow0SkZz36Jw.png" /><figcaption>Switching Feed Forward Layer processing two tokens “More” and “Parameters” in parallel.</figcaption></figure><p>The switch transformer was able to achieve this parameter scale by using Mixture of Expert (MoE) models. Unlike traditional deep learning models, which use the same parameters for all inputs, MoE models use different parameters for each input. This results in a sparsely activated model, which can have many more parameters while maintaining the same computational budget as a model with parameters equal to those that are activated at any given time. For instance, a dense feed forward layer with <em>N</em> nodes can be transformed into a sparse MoE layer by having <em>K</em> dense feed forward layers with <em>N</em> nodes each and a trainable routing function to direct the input to one or more of them. The routing function is a vector of size <em>N</em>, <em>Wᵣ</em>, with trainable parameters which when multiplied with the input <em>x</em>, and normalized via softmax, produces a probability distribution over the <em>N </em>expert layers. For each expert <em>i</em>, we get <em>p</em>ᵢ<em>(x) = softmax(Wᵣ x)ᵢ.</em>The output, <em>y</em>, of the MoE layer is the weighted sum of the outputs of the top-k experts. Concretely, if <em>T</em> is the set of top-k indices, and output from expert <em>i</em> <em>∈ T </em>is<em> Eᵢ(x)</em>, then <em>y = ∑ᵢpᵢ(x)Eᵢ(x).</em></p><p>Creators of the switch transformer, Fedus, Zoph, et al., went against prevailing views by using only one expert (k=1) at each MoE routing layer to create the eponymous layer of the Switch Transformer. Earlier, researchers had intuited that at least two or more experts would be needed to learn how to route, and others reported that in models with many routing layers higher values of k in top-k routing were needed in layers closer to the input. However, the creators of the switch transformer go on to show that the switch-transformer can perform well on many NLU tasks, while saving computation and communication cost.</p><h4>Using Model, Data, and Expert Parallelism</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BRO65J6CjNoCmsHlSBn53g.png" /><figcaption>Diagram depicting different kinds of parallelism used during distributed training.</figcaption></figure><p>The switch transformer is able to scale up well because they are able to minimize communication requirements by using model, data, and expert parallelism. Their Switch-C model (1.5T parameters), uses data and expert parallelism, whereas the Switch-XXL (397B parameters), uses data, model, and expert parallelism.</p><p>Expert parallelism implies that weights of each expert lie in a different core. Thus when a batch <em>B</em> of inputs of size <em>T </em>reaches the router function, it must route each input to the right expert. To fix the maximum computation on any one expert, the maximum number of input tokens routed to each are also fixed. This number is called ‘<em>expert capacity</em>’. Expert capacity is the batch size of batch size of each expert calculated as <em>(T/N) * capacity factor</em>. If more tokens are routed to an expert than it’s capacity, i.e. when tokens overflow, they are passed onto the next layer through a residual connection. Scaling expert capacity using the capacity factor (a hyper parameter) helps mitigate token overflow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wrXxC5sPb3LP8pR8_qw0qA.png" /><figcaption>An explanation of token routing dynamics in the switching Layer with different capacity factors.</figcaption></figure><h4>Reducing Communication cost with Selective Precision</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*orIA9CdDwJEJ6n8hfzivCA.png" /><figcaption>Using Selective Precision to stabilize model training and achieving speed of full bfloat16 model. In selective precision, float32 precision was used only in the router computation which is local to a core.</figcaption></figure><p>Another interesting problem solved by the authors of this work is using low precision numbers, such as ‘bfloat16’. ‘bfloat16’ is Google Brain’s 16 bit float precision format (b for brain) created by truncating float32 to the first 16 bits. In prior MoE works, using bfloat16 precision caused instability during training and forced the use of float32 precision. The creators of the switch transformer circumvented this issue by using high precision numbers only in the router computation, which is local to a given core, and showed that training still converges. This reduced the communication cost between cores by two, and increased throughput (speed).</p><h4>Performance of the Switch Transformer</h4><p><strong>Fine Tuning Results</strong></p><p>Switch models show performance improvement in all but one downstream fine tuning task: the AI2 Reasoning Challenge (ARC). Overall they saw gains with increasing model size, and also gains in both knowledge heavy and reasoning tasks, when compared to their FLOP matched baselines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*4tPJN6Pkm98TOtmlOEtk6g.png" /><figcaption>Switch Model and their FLOP matched Baselines for Comparison</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WPfhdpHTgneg_lX4_3XDPA.png" /><figcaption>Fine Tuning Results. Comparing Switch models to FLOP matched Baselines on various NLU tasks.</figcaption></figure><h4>Scaling Properties</h4><p><strong>Scaling on the basis of training steps</strong></p><p>The authors found that more experts achieve lower loss and higher performance for a fixed number of steps, when the amount of computation (FLOPs) per token is held constant (left figure below). This means that sparser models learn faster in terms of number of training steps. Their switch-base 64 model achieved a 7.5x speed up in terms of step time compared to the T5-base model (not shown in the figure below). The plot on the right implies that larger models are more sample efficient, i.e, learn faster for a fixed number of observed samples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qoeYtd-FmRcUQ6dGChueWg.png" /><figcaption>Left: Final test loss vs # parameters. Right: Convergence of models with different number of experts compared to T5-Base</figcaption></figure><p><strong>Scaling on the basis of training time</strong></p><p>The authors wished to understand that for a fixed training duration and computational budget, should one train a dense or a sparse model?</p><p>First, they noted that their sparse models outperformed the dense baselines: the model with 64 experts achieves a given loss 7x faster than T5-Base.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*RK2rahoU8EyRGQT-nMQ5xw.png" /><figcaption>Training time of models with different number of experts compared to T5-Base.</figcaption></figure><p>However, instead of comparing the sparse model with the same number of parameters, what if we compare a sparse model to a larger dense model? The following plot shows that the Switch-Base with 64 experts is more sample efficient (left) and 2.5x faster (right) than even T5-Large.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iVZEWAD61x18-ItbOJg0NQ.png" /></figure><p>Diving deeper into time to train of the largest models, we see that the Switch-C model gets to a fixed perplexity (-1.096) four times faster than T5-XXL, while maintaing the same computational budget. Note the multiplier is four and not two because the reported value is in the logarithmic domain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rPV8HBhWJ72LyMKXzFK2AQ.png" /><figcaption>A comparison of the hyper parameters and pre-training performance on the C4 dataset after 250k and 500K steps</figcaption></figure><p>Note: Please refer to the paper for more interesting experiments and techniques that we haven’t discussed in this summary.</p><h3>References</h3><ul><li>Vaswani, et al. (2017). Attention Is All You Need. arXiv:1706.03762v5.</li><li>Rashford, et. al. (2018) “Improving Language Understanding using Generative Pre-Training” <a href="https://cdn.openai.com/research-covers/language-unsupervised/language_understanding_paper.pdf">https://cdn.openai.com/research-covers/language-unsupervised/language_understanding_paper.pdf</a></li><li>Devlin, et al. (2019). BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding. arXiv:1810.04805v2.</li><li>Fedus, et al. (2021) “Switch Transformers: Scaling to Trillion Parameter Models using Simple and Efficient Sparsity” <a href="https://arxiv.org/pdf/2101.03961.pdf">https://arxiv.org/pdf/2101.03961.pdf</a></li><li>Graphics used from: <a href="https://www.youtube.com/watch?v=4Bdc55j80l8&amp;t=300s&amp;ab_channel=TheA.I.Hacker-MichaelPhi">https://www.youtube.com/watch?v=4Bdc55j80l8&amp;t=300s&amp;ab_channel=TheA.I.Hacker-MichaelPhi</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1ac7f57613f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making: The Environmental Impact of Bitcoin]]></title>
            <link>https://ravishrawal.medium.com/making-the-environmental-impact-of-bitcoin-dc884c63ad00?source=rss-d78a4cdb27d6------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc884c63ad00</guid>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[climate-change]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[environment]]></category>
            <dc:creator><![CDATA[Ravish Rawal]]></dc:creator>
            <pubDate>Tue, 20 Apr 2021 07:04:07 GMT</pubDate>
            <atom:updated>2021-04-20T19:21:47.219Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Authors: </em><a href="https://medium.com/u/d78a4cdb27d6"><em>Ravish Rawal</em></a><em> , </em><a href="https://medium.com/u/4808661549d2"><em>Viren Bajaj</em></a><em>, </em><a href="https://medium.com/u/9b3ba5ff713"><em>Kamrul Hossain</em></a><em>, Hector Liang (</em><a href="https://medium.com/u/17aa4db7fc13"><em>Chinisko</em></a><em>)</em></p><p><em>An article about the making of </em><a href="https://carbon-implication.uc.r.appspot.com/"><em>our visualization</em></a><em>.</em></p><p><strong>Introduction</strong></p><p>Cryptocurrency is an emerging technology that is being applied across the financial sector and beyond. While the promises of a decentralised, secure system are exciting, we must recognise that computationally intensive solutions carry with them environmental implications. Given that we are in a climate crisis, we hope to use this viz to highlight the magnitude of energy consumed by Bitcoin, the most prominent cryptocurrency, and encourage discussions to scale this technology more thoughtfully.</p><p><strong>Related Work</strong></p><p>For our data story, we drew inspiration from a few cryptocurrency articles when coming up with our project. [7] presents a framework to overcome uncertainties in previous climate estimates and project Bitcoin’s carbon footprint in the long term and [8] focusses on market and environmental implications of Bitcoin miners’ power draw.</p><p>Our design was inspired by a <em>scrolly-tale</em> made by Stamen for Dropbox [15]. This format perfectly suited our need to gradually break down complex topics while building up a narrative to finally reach a convincing, and well-informed conclusion.</p><p><strong>Methodology</strong></p><p>We used diverse sources to gather data that fit our story and performed many transformations to prepare it. Let’s look at the methodology for creating some of our more interesting graphs:</p><ol><li><em>Bitcoin’s Energy Consumption Comparisons:</em> To compare Bitcoin’s consumption with relatable units we had to aggregate these figures from various sources and normalise them to display them in one graph [1,2,3,4]. There are limited estimates for Bitcoin’s per microtransaction energy consumption. To compare with VISA we used per block data from [11] and extracted per transaction values using the average transactions per block from [12].</li><li><em>Energy Consumption vs Hash-Rate: </em>To show how hash-rate affects energy consumption, we combined [1] and [9], and smoothened the curve by aggregating and reducing the dataset down to one-tenth of its size.</li><li><em>Future Carbon Footprint Predictions:</em><strong><em> </em></strong>We started with a data point from [17]: a figure for PoW miners’ renewable adoption as of today. We assumed this to be representative of Bitcoin, the most prominent PoW coin. We then applied the average year-over-year growth rate of Bitcoin and the renewable energy sector [6] to extrapolate and make future predictions.</li><li><em>Efficiency of Suitable Mining Devices for Different Consensus Algos: </em>The data for this was selected from columns in Table 1 of [14], which provides the energy efficiency of the top 20 cryptocurrencies by market capitalization.</li></ol><p><strong>Design</strong></p><p>The fundamental design decision was to choose to present our story in a scrolly-telling format. This allowed us to take a step-by-step approach to having a technically and socially nuanced but critical discussion. The tradeoff was sacrificing interactivity in the interest of the narrative’s flow. A compromise was to trigger animated graphs as the user scrolled, creating the illusion of interactivity. We also used animations to demonstrate magnitudes. Our Bitcoin vs. VISA transaction shows an expanding y-axis as the Bitcoin bar grows to tower over the other.</p><p>We experimented with more complex visualizations but chose to go with more familiar visual encodings like line and bar charts. The complexity of the content alongside unfamiliar visualizations made the topic more daunting, as was revealed in user testing, so we focussed on approachability. We also used colour as a channel to create a visual language that spanned the story, and a tool to focus the reader’s attention to the important information — Bitcoin.</p><p>For our comparison graphs, an early thought was to include country-specific units of comparison to select from, to allow universal comprehension.</p><p><strong>Implementation</strong></p><p>We created these visualizations using a react library, VictoryJS, which provided abstractions to make designing animated graphs and allowed us to create custom themes. These were all structured and wrapped within a scrolling interface provided by react-scrollama.</p><p>Before this, we had to gather the data which was mostly in large CSV files. We cleaned and extracted only the necessary fields for our visualizations to reduce computation and storage. We converted these to JSON and served them through an API to improve performance. Finally, we used Google App Engine to serve up our files.</p><p><strong>Discussion</strong></p><p>Through user testing, the resounding consensus was that our narrative is the most compelling element of our visualization. The selection of data to render visualizations worked well to support our argument.</p><p>We also heard that putting energy consumption in terms of relatable units of measure would have a greater impact, and this drove our comparison graphs.</p><p>We also received feedback on the jargon we were using, which helped us identify what to explain beforehand.</p><p><strong>Future Work</strong></p><p>In the future, we will expand our investigation beyond Bitcoin to all cryptocurrencies to present a holistic view of the industry.</p><p>We will also analyze security and functional features of proof-of-x models to paint a more complete picture of why proof-of-work is unnecessarily energy intensive.</p><p>Finally, we would love to converse with experts to better understand the nature of realistic regulation that could cap carbon emissions.</p><p><strong>References:</strong></p><ol><li><a href="https://cbeci.org/">Bitcoin energy consumption</a></li><li><a href="https://www.nycsubway.org/wiki/Subway_FAQ:_Facts_and_Figures">NYC Subway energy consumption</a></li><li><a href="https://www.withouthotair.com/c5/page_36.shtml">Flight energy consumption metrics</a></li><li><a href="https://www.eia.gov/tools/faqs/faq.php?id=97&amp;t=3">U.S household electricity consumption</a></li><li><a href="https://www.eia.gov/consumption/manufacturing/data/2018/#r13">U.S electricity consumption by industry</a></li><li><a href="https://ourworldindata.org/grapher/modern-renewable-energy-consumption?country=~OWID_WRL">Renewable energy consumption</a></li><li><a href="https://arxiv.org/pdf/2011.02612.pdf">Qin, Shize, et al. “Bitcoin’s future carbon footprint.” arXiv preprint arXiv:2011.02612 (2020).</a></li><li><a href="https://knoema.com/suxqfz/bitcoin-energy-requirements-climbing-even-as-revenues-fall">“Bitcoin Energy Requirements Climbing Even as Revenues Fall” (2019)</a></li><li><a href="https://knoema.com/CMCCD2019/coin-metrics-crypto-currency-data">Coin Metrics: Crypto Currency Data</a></li><li><a href="https://knoema.com/BITCONCS/bitcoin-currency-statistics-daily-update">Bitcoin Currency Statistics, Daily Update</a></li><li><a href="https://www.statista.com/statistics/881541/bitcoin-energy-consumption-transaction-comparison-visa/">Bitcoin average energy consumption per transaction vs VISA (April 14, 2021).</a> <a href="https://www.statista.com/statistics/881541/bitcoin-energy-consumption-transaction-comparison-visa/">https://www.statista.com/statistics/881541/bitcoin-energy-consumption-transaction-comparison-visa/</a></li><li><a href="https://towardsdatascience.com/the-blockchain-scalability-problem-the-race-for-visa-like-transaction-speed-5cce48f9d44">The Blockchain Scalability Problem &amp; the Race for Visa-Like Transaction Speed</a>. <a href="https://towardsdatascience.com/the-blockchain-scalability-problem-the-race-for-visa-like-transaction-speed-5cce48f9d44">https://towardsdatascience.com/the-blockchain-scalability-problem-the-race-for-visa-like-transaction-speed-5cce48f9d44</a></li><li><a href="https://doi.org/10.1007/s12599-020-00656-x">Sedlmeir, J., Buhl, H.U., Fridgen, G. et al. The Energy Consumption of Blockchain Technology: Beyond Myth. Bus Inf Syst Eng 62, 599–608 (2020).</a></li><li><a href="https://pubmed.ncbi.nlm.nih.gov/32838201/">Gallersdörfer U, Klaaßen L, Stoll C. Energy Consumption of Cryptocurrencies Beyond Bitcoin. <em>Joule</em>. 2020;4(9):1843–1846. doi:10.1016/j.joule.2020.07.013</a></li><li><a href="https://spectrum.ieee.org/computing/networks/ethereum-plans-to-cut-its-absurd-energy-consumption-by-99-percent">Ethereum Proof-of-Stake Estimates</a></li><li><a href="https://stateofwork.dropbox.com/">The State of Work</a></li><li><a href="https://www.jbs.cam.ac.uk/faculty-research/centres/alternative-finance/publications/3rd-global-cryptoasset-benchmarking-study/">Percentage of renewable energy used in bitcoin energy consumption</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc884c63ad00" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Polyline Sorcery With React Native]]></title>
            <link>https://ravishrawal.medium.com/polyline-sorcery-with-react-native-8e194bd993f1?source=rss-d78a4cdb27d6------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e194bd993f1</guid>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[mapbox]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[google-maps]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ravish Rawal]]></dc:creator>
            <pubDate>Wed, 22 Nov 2017 02:18:35 GMT</pubDate>
            <atom:updated>2017-11-22T02:18:35.192Z</atom:updated>
            <content:encoded><![CDATA[<p>I owe my first 6 months of college attendance to Google Maps. You could say, I would not be where I am today if that location marker and the blue path to my destination had not got along so well. I also would not be where I am right now. It’s just a dot and a line though, what’s the big deal? And that’s exactly right; it isn’t a big deal, but that’s all thanks to the nice guys at Google. Their algorithms are out there figuring out the fastest routes to drive, walk, and Heely (RIP) to your destination. It’s up to us to figure how best to leverage this in our apps.</p><p>There are many ways to render a route on Google Maps. All you really need is a little bit of HTML knowledge (you will be using script tags though), and you’re on your way using the <a href="https://developers.google.com/maps/documentation/javascript/directions">Google Maps Direction Service</a>. But I wanted to recreate the same mobile experience that guides me to 3 AM burritos every Saturday. My weapon of choice: React Native <a href="https://facebook.github.io/react-native/">(If You Don’t Know, Now You Know)</a>. I’ll trust you to learn the basics, and if you want to try it out Expo is a great tool to see your app come to life.</p><h3>The Map Component:</h3><p>I totally would love to figure out how to implement Google Maps as a React Native component but baby steps here. The first baby step: <a href="https://github.com/airbnb/react-native-maps">AirBnB’s MapView Component</a>. [Tl;dr : It’s a wrapper that took React Native’s MapView component and augmented it with so many options and optimisations that the original component is now deprecated.]</p><pre>//In Your Terminal (Yes, I Know You Already Know This)<br>npm install --save react-native-maps</pre><pre>//React Component (Apple Map on iOS, Google Map on Android)<br>import MapView from &#39;react-native-maps&#39;</pre><p>At this point you should be able to literally drop the&lt;Mapview /&gt; component into your class’ render function and have a functional map (although you might want to look into the options to tweak the appearance or focus).</p><h3>Polylines, Finally</h3><p>We are finally ready to talk about polylines. Simply put, a polyline is just a mash of many smaller line segments. These line segments use latitude &amp; longitude values to plot parts of your path. Put em all together, and you have your route! The Google Maps API helps us out with the lat/lng values, so go ahead and grab an API key from their developers site. A simple call now lets us get all the information we need to plot our polyline, and it looks something like this:</p><pre><a href="https://maps.googleapis.com/maps/api/directions/json?origin=40.71855466,-73.98899738&amp;destination=40.72867347,-74.00473773&amp;mode=walking&amp;key=[YOUR_API_KEY_HERE">https://maps.googleapis.com/maps/api/directions/json?origin=40.71855466,-73.98899738&amp;destination=40.72867347,-74.00473773&amp;mode=walking&amp;key=[YOUR_API_KEY_HERE</a>]</pre><p>Go ahead and input that in your browser to see what the result looks like. It’s an object that gives us information for a walking route (note the walking option in the URL; go on, mess around). Use what you’d like (the place_id lets you access a lot more information about a place using the <a href="https://developers.google.com/places/web-service/photos">Google Places</a> service). What we (I) care about here is the “overview_polyline” property, which gives us a (slightly modified) base64 encoded string. <a href="https://developers.google.com/maps/documentation/utilities/polylinealgorithm">Crack that code</a> and you’re magically left with an array of lat/lng objects that make up your line segments and subsequently your polyline. I do encourage checking out base64 encoding/decoding, as it is a more stable way to get data across a network using a string of common characters.</p><p>Here’s a visual of your points, segments, and polyline:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/1*z87hF9enT-yIoOFVK1DPlw.png" /><figcaption>“Ooooh Aaaaah” — Larry Page</figcaption></figure><h3>Enough Talk</h3><p>Here’s straight up code to get your polylines going. Note: you can definitely do this all on the front end, but don’t. Smartphone processors around the world will thank you.</p><p>React:</p><pre>import React, { Component } from &#39;react&#39;;<br>import { MapView } from &#39;expo&#39;;<br>import { getDirections } from &#39;../redux&#39;; //next section, patience</pre><pre>class Map extends Component {<br>    constructor(props) {<br>        super(props)<br>        this.state = {<br>//you want to locally store your start location and destination, and your polyline coordinates<br>        }<br>    }</pre><pre> componentDidMount() {<br>//use your current location as your starting point, if you&#39;d like. I am.<br>       navigator.geolocation.getCurrentPosition((res, rej) =&gt; {<br>//you will get a res.coords property        <br>res ? this.setState({ ...etc }): console.log(rej);<br>       });<br> }</pre><pre>onButtonPress(){<br>        let { startLocation, destination } = this.state;<br>        getDirectionsToBar(startLocation, destination) //lat-lng objects<br>        .then(res=&gt; this.setState({...set your coordinates})<br>        .catch(er =&gt; console.log(er))<br> }</pre><pre>render(){<br>  //Make sure you set your destination (using markers or a dropdown or however you want the user to set it) and create a button</pre><pre>//Within your MapView<br>{ this.state.coordinates &amp;&amp;<br>   &lt;MapView.Polyline<br>   coordinates={this.state.coordinates}<br>   strokeWidth={4}<br>   strokeColor=&quot;rgba(255,140,0,0.8)&quot;/&gt;<br>  }<br>}</pre><p>Redux:</p><pre>import axios from &#39;axios&#39;;</pre><pre>export function getDirectionsToBar(startLoc, destLoc){<br>    return axios.post(&#39;YOUR_ROUTE&#39;, { startLocation, destination })<br>      .then(res =&gt; { return res.data })<br>      .catch(er=&gt;console.log(er))<br>}</pre><p>Express (Your API):</p><pre>//I&#39;ll use a router so you cant mount this code on your api path or wherever else you&#39;d like</pre><pre>const router = require(&#39;express&#39;).Router();</pre><pre>//axios helps us make calls to the Google Maps Api<br>const axios = require(&#39;axios&#39;);</pre><pre>//mapbox gives us a great polyline tool that does the decoding for us. sorry I sent you down the base64 rabbithole. But also, you&#39;re welcome.</pre><pre>const Polyline = require(&#39;<a href="http://twitter.com/mapbox/polyline">@mapbox/polyline</a>&#39;);</pre><pre>module.exports = router;</pre><pre>router.post(&#39;/&#39;, (req, res, next) =&gt; {<br>  let { startLocation, destination } = req.body</pre><pre>  //remember this url? you can do an async await/fetch too</pre><pre>  axios.get(`<a href="https://maps.googleapis.com/maps/api/directions/json?origin=${startLoc.latitude},${startLoc.longitude}&amp;destination=${destLoc.latitude},${destLoc.longitude}&amp;mode=walking&amp;key=${process.env.GOOGLE_MAPS_KEY}`">https://maps.googleapis.com/maps/api/directions/json?origin=${startLocation.latitude},${startLocation.longitude}&amp;destination=${destination.latitude},${destination.longitude}&amp;mode=walking&amp;key=YOUR_API_KEY`</a>)<br>  .then(result=&gt; result.data)<br>  .then(result=&gt; {<br>    let array = Polyline.decode(result.routes[0].overview_polyline.points);</pre><pre>//your base64 string is now an array of lat/lng objects</pre><pre>    let coordinates = array.map((point) =&gt; {<br>              return  {<br>                  latitude :point[0],<br>                  longitude :point[1]<br>              }<br>          })<br>    res.send(coordinates)<br>  }).catch(er=&gt;console.log(er.message))<br>})</pre><h3>Houston, We Have A Polyline</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*JQi8BYoiiw7JHiCmavt6WA.jpeg" /><figcaption>Coolest Polyline On The Block</figcaption></figure><p>And that’s about it. You want to think about things like using the distance and duration Google gives you, and giving the user the option of cancelling navigation by clearing your state and adding conditionals. But that wasn’t so bad, and now you can find your own way to class!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e194bd993f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>