<?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 Preston Lim on Medium]]></title>
        <description><![CDATA[Stories by Preston Lim on Medium]]></description>
        <link>https://medium.com/@prestonlim?source=rss-8598d290eacf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*rj5_z3sD8g98_miMHY1ahw.jpeg</url>
            <title>Stories by Preston Lim on Medium</title>
            <link>https://medium.com/@prestonlim?source=rss-8598d290eacf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 04:23:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@prestonlim/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[Are Singaporeans negative Nancies? A sentiment analysis of social media comments using BERT]]></title>
            <link>https://medium.com/@prestonlim/are-singaporeans-negative-nancies-a-sentiment-analysis-of-social-media-comments-using-bert-5a6e51b1c1e2?source=rss-8598d290eacf------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a6e51b1c1e2</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[bert]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[social-media]]></category>
            <dc:creator><![CDATA[Preston Lim]]></dc:creator>
            <pubDate>Mon, 13 Jan 2020 09:10:31 GMT</pubDate>
            <atom:updated>2020-01-13T09:47:32.927Z</atom:updated>
            <content:encoded><![CDATA[<p>Complaining is an undisputed national past time for many Singaporeans. But exactly how negative are we? And do we loathe all topic matters equally?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PPcGGe3_hFno1hhkvRTCaQ.png" /><figcaption>An excerpt written by the founder of the World Toilet Organization. Published in my favorite national newspaper, The Straits Times.</figcaption></figure><p>Wow, I get that this was maybe written from the perspective of the World Toilet Organization but what a load of — oh crap, am I perhaps also complicit in this complaining culture?</p><p>In order to prevent my innately-Singaporean negativity from clouding my judgement, I guess I’ll have to use some good old data science to conduct this study.</p><p>In the next section, I’ll be explaining the deep learning technique used to perform sentiment analysis — skip ahead to the end if you want to find out what the results are.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MlTJWD4yTOAFH__EkAAUKw.png" /><figcaption>An assortment of negative comments from posts on the Straits Times Facebook group</figcaption></figure><h3>What is sentiment analysis?</h3><p>Sentiment analysis is a technique to study the opinions or emotions expressed in a given text.</p><p>Many companies use sentiment analysis to track how their brands are being perceived by people through online platforms like the app store or Amazon reviews.</p><p>For our use case, we want to use sentiment analysis to measure how Singaporeans perceive specific news articles.</p><h4>Computers struggle at sentiment analysis</h4><p>Sentiment analysis is difficult for machines because human languages are highly complex. And so machines find it really hard to understand if the emotion behind a sentence is positive, negative, or neutral.</p><p>For example, the English language has many words that while seemingly identical, can have drastically different meanings when used in different contexts.</p><p>Take the use of the word <strong>wound</strong> in the following sentences:</p><blockquote>John wound the clock.<br>The arrow inflicted a wound onto her arm.</blockquote><p>Traditional NLP techniques like static word embeddings are only able to ascribe one single meaning to each word. So in traditional techniques, the word <strong>wound</strong> would have the same meaning to a computer regardless of the way it was being used in a sentence.</p><p>But thankfully, the field of NLP has started seeing more advanced language modeling techniques such as BERT, which we will use in this study.</p><h4>BERT from Sesame Street saves the day</h4><p>BERT, or Bidirectional Encoder Representations with Transformers, is a state-of-the-art natural language understanding model. When Google released BERT in 2018, it broke all existing records for gold-standard natural language understanding tasks.</p><p>The reason BERT outperforms previous NLP techniques at understanding language is because it tries to learn the context in which a word is used.</p><p>BERT was trained by studying billions of sentences from Wikipedia and other text sources, and then made to predict a bunch of words that was hidden from these sentences. In doing so, BERT gets a better understanding of the context in which words appear compared to traditional static word embedding techniques!</p><p>Sorry did I sound too excited? What I really meant was, oh BERT’s just alright. Like, what a dumb name. I mean they only named it BERT because its predecessor was named ELMO.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*9HTNvSTtul5B5ABz73wYkw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*tQ6DoTTNsHafUPAEko4LQg.png" /><figcaption>What BERT looks like to Sesame street fans (left). What BERT looks like to Computer Scientists (right).</figcaption></figure><p>For our specific sentiment analysis use case, we fine-tune a BERT model to perform a classification step of 3 possible classes: <strong>positive</strong>, <strong>negative</strong>, and <strong>neutral</strong>. What this means is that we need to take the pre-trained BERT model from Google and teach it how to analyze sentiments from sentences.</p><p>In short, the model needs to do the following steps:</p><ul><li>take in a sentence — in our case an English sentence — and produce a contextual word embeddings representation for the sentence (specifically for the [CLS] token)</li><li>pass the [CLS] contextual word embedding vector into a 3-dimension output vector (each dimension corresponds to the 3 classes)</li><li>perform a softmax on the 3-dimension output vector to determine whether the sentiment is <strong>positive</strong>, <strong>negative</strong>, or <strong>neutral</strong>.</li></ul><p>What this means is that BERT takes a sentence and converts it to a mathematical representation that machines can understand and work with.</p><h4>Here’s one way to think about it</h4><p>BERT is an English-as-a-second-language student trying to understand English. He could read a sentence in English but it would be way easier if he translates it into a language that BERT is fluent in — let’s say, BERT-lish.</p><p>So BERT does just that — he translates the input sentence to BERT-lish. And finally, BERT determines if the BERT-lish sentence is <strong>positive</strong>, <strong>negative</strong>, or <strong>neutral</strong>.</p><p>This is of course a gross simplification of the BERT model, but hey, I don’t want to get more complaints about how long the article would have been if I tried to fully explain it. Here are some good resources if you want to learn more about BERT.</p><p><a href="https://towardsdatascience.com/bert-explained-state-of-the-art-language-model-for-nlp-f8b21a9b6270">BERT Explained: State of the art language model for NLP</a></p><h4>Fine-tuning BERT for sentiment analysis</h4><p>I fine-tuned BERT, specifically, <em>BertForSequenceClassification</em> using thebert-base-uncased model from the <a href="https://huggingface.co/transformers/">huggingface transformers library</a>.</p><p>The fine-tuning process was conducted on the <a href="https://www.kaggle.com/crowdflower/twitter-airline-sentiment">Twitter airline sentiment dataset</a> — my training code can be found in this repo:<strong> </strong><a href="https://github.com/prestonlimlianjie/bert-sentiment-analysis-straits-times"><strong>bert-sentiment-analysis-straits-times</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qsaUKnnr8Lb8GJBf0kKDKA.png" /><figcaption>Sample records from the Twitter airline sentiment dataset</figcaption></figure><p>The dataset contains <strong>14,640</strong> tweets that were manually classified as negative, positive, or neutral. I created a training set with 80% of the dataset and kept the other 20% for validation.</p><p>I ran the training on a Google Colab notebook with a GPU and obtained the following validation results. The entire training process took approximately 20 minutes to complete.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1sd4Ayp_joMWrKLEfx94Kg.png" /><figcaption>Screenshot of validation results</figcaption></figure><p>The results show that the model has an <strong>83% </strong>accuracy — that is, it is able to accurately predict the correct sentiment given an input sentence 83% of the time.</p><p>It also appears that the model is better at predicting comments that are <strong>positive</strong> than <strong>negative </strong>or<strong> neutral.</strong></p><p>Great, now that we have a decent model that can predict sentiments, let’s test it out on a bunch of comments made by Singaporeans!</p><p>A random Sesame Street aside. I’ve been obsessively binging the incredible podcast <em>The Weirdest Thing I Learned This Week</em> and discovered that according to folklore, vampires are obsessive counters.</p><p>That is, they feel compelled to count every single object around them — which is why people threw poppy seeds on the burial grounds of suspected vampires so that they would be so preoccupied with counting them that they wouldn’t attack humans. So perhaps Sesame Street was actually on point with the characterization of Count Dracula. Anyway, on to the results.</p><h3>Results: Sentiment analysis of comments on The Straits Times articles</h3><p>The Straits Times is my favorite national newspaper. And judging from how fervently Singaporeans from all walks of life comment on the news articles, I’m sure it is also the beloved source of <em>#realnews </em>for many Singaporeans.</p><p>And so, to answer the two questions I posed earlier about (i) exactly how negative are Singaporeans, and (ii) do we dislike all topics equally, I collected a bunch of Facebook comments from <strong>5 randomly selected articles </strong>on The Straits Times to run the analysis on.</p><p>The 5 articles I chose to study were:</p><ul><li><em>Husband runs off when wife is pregnant and defaults on paying maintenance</em></li><li><em>China launches gigantic telescope in hunt for life beyond earth</em></li><li><em>Tsai Ing-wen re-elected Taiwan President; KMT’s Han Kuo-yu concedes defeat</em></li><li><em>Forum: Promote plant-based diet to cut Singaporean’s carbon footprint</em></li><li><em>Menacing mynas, pigeons and crows: Complaints about nuisance birds rising</em></li></ul><p>There were <strong>257 comments </strong>in total across the 5 articles.</p><h4>How good is BERT at analyzing the sentiments of Straits Times comments?</h4><p>In the previous step, we fine-tuned the BERT model on the Twitter airline sentiments dataset, and verified that it works well. Typically, a good computer scientist would verify that this model also works well on a test dataset of interest — in our case the Straits Times comments.</p><p>What this means is that we should collect a bunch of comments from The Straits Times’ posts and manually label them as <strong>positive</strong>, <strong>negative</strong>, or <strong>neutral</strong>. However, I’m doing this in my spare time on a Sunday, so ain’t nobody got time for that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/0*YxkoF2R0W92uLdgh.jpeg" /></figure><p>Instead, I’m going to take the short-cut of using the model to predict the sentiments in The Straits Times’ comments and then looking through the predictions to see if they make sense.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Oox8o5-2iyavpniuIliu0g.png" /></figure><p>Let’s take a look at the comments on any article — for example this one: <strong>Forum: Promote plant-based diet to cut Singaporeans’ carbon footprint</strong>. The article is an opinion letter that asks the government to intervene or “nudge” Singaporeans towards plant-based diets.</p><h4>Correctly classified comments</h4><p>The model does a pretty good job identifying the correct classes of many comments, despite some comments having spelling and grammar issues.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p89A5lkHHrfx3tuqqCpGmg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5WJKG9zC9XI655CAdbRreQ.png" /><figcaption>Comments from articles on The Straits Times — the sentiment for each comment as predicted by the model is displayed on the right.</figcaption></figure><h4>Misclassified comments</h4><p>However, there were a few comments that were misclassified.</p><p>For example the first comment below was classified as <strong>neutral</strong>, when the user actually had a negative sentiment in the response. The way I interpreted the comment was this: the user demands for political leaders and news organizations to first adopt a vegan diet before shoving veganism down his/her throat. However, this required some <strong>inference</strong>, which existing NLP models like BERT aren’t very well-versed at doing.</p><p>Additionally, in the second comment below, the user was being <strong>sarcastic</strong> — and BERT, like most state-of-the-art NLP models, struggle to understand sarcasm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fTwQ1oONsxR4QpN-BRocQg.png" /></figure><h4>Special shoutout to these comments that are uninterpretable even to humans</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0z80q1T9oQe4Iq3stVy0dg.png" /><figcaption>WHAT IS HAPPENING?? I am surprised that BERT was even able to give these comments a label.</figcaption></figure><p>Cool, so BERT works pretty well at classifying The Straits Times’ comments! Let’s use it to study all the comments on the 5 articles that we’ve selected above.</p><h4>Good news! Not all of our comments are negative!</h4><p>Maybe Singaporeans aren’t negative Nancies after all. As it turns out, only <strong>52.9%</strong> of our comments were negative.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*Hdf_XeFzmDhl-Fde698_EA.png" /><figcaption>Prediction results on the Straits Times comments</figcaption></figure><p>And if I were to be optimistic about the situation, what this means is at <strong>48.1% </strong>of the comments were positive or neutral!</p><h4>Which articles get Singaporeans the most riled up?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*Akch1XCk4PoimLCiSdO0kQ.png" /></figure><p>“<em>Husband runs off when wife is pregnant and defaults on paying maintenance” </em>made Singaporeans most upset — with <strong>77.8%</strong> negative and <strong>2.8% </strong>positive comments.</p><p>On the other hand, “<em>Tsai Ing-wen re-elected Taiwan President; KMT’s Han Kuo-yu concedes defeat</em>” made Singaporeans the most happy — with only <strong>45.3% </strong>negative and <strong>34.8%</strong> positive comments!</p><h4>My feelings/sentiments on this entire process</h4><p>BERT is a pretty powerful language model — but while the field of NLP has made significant advancements in recent years, it still has a long way to go before machines can fully comprehend humans.</p><p>But then again, I too find it hard to understand humans sometimes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SDBNIpiyy59OjSUW" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kcSpNPWXYYv2xu9n" /><figcaption>Taken from the meta-group The Straits Times Comment Section — a Facebook group dedicated to studying why people comment the way they do on The Straits Times and other news platforms</figcaption></figure><p><em>The views in this article are my own and do not reflect the views of the organizations that I am a part of.</em></p><p>I hope you enjoyed reading this article. If you would like to read some of my other fun and frivolous™ projects, check these out:</p><ul><li><a href="https://towardsdatascience.com/i-wrote-a-program-that-speaks-like-the-collective-hive-mind-of-the-straits-times-forum-41c96e7d8d71">I wrote a program that speaks like the collective hive-mind of The Straits Times Forum</a></li><li><a href="https://blog.usejournal.com/i-made-a-machine-learning-chicken-rice-classifier-in-4-hours-to-tell-me-what-type-of-chicken-rice-e9b1af4aa069">I made a machine learning chicken rice classifier in ~4 hours to tell me what type of chicken rice…</a></li></ul><h4>Acknowledgements</h4><p>Special thanks to <em>sebsk</em> for open-sourcing their <a href="https://github.com/sebsk/CS224N-Project">CS224N project</a> from which I referenced much of the BERT fine-tuning process.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a6e51b1c1e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bringing black and white photos to life using Colourise.sg]]></title>
            <link>https://medium.com/@prestonlim/bringing-black-and-white-photos-to-life-using-colourise-sg-435ae5cc5036?source=rss-8598d290eacf------2</link>
            <guid isPermaLink="false">https://medium.com/p/435ae5cc5036</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[colorization]]></category>
            <category><![CDATA[photography]]></category>
            <category><![CDATA[singapore]]></category>
            <dc:creator><![CDATA[Preston Lim]]></dc:creator>
            <pubDate>Sun, 03 Feb 2019 11:47:48 GMT</pubDate>
            <atom:updated>2019-02-10T05:37:57.595Z</atom:updated>
            <content:encoded><![CDATA[<h3>Bringing black and white photos to life using Colourise.sg — a deep learning colouriser trained with old Singaporean photos</h3><p><em>This project is brought to you by the Data Science and Artificial Intelligence Division, GovTech Singapore.</em></p><p><em>Andrew Tan, Quantitative Analyst<br>Preston Lim, Software Engineer<br>Tan Kai Wei, Data Scientist</em></p><p>Have you ever looked at an old black and white photo and wondered: what did the person taking this photo actually see?</p><p>Was there something about the arrangement of colours that compelled the photographer to capture this very moment? And if so, did the photographer see something that we — modern day viewers of this black and white photo — are not privy to?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uranzuX4nl6vmLCVaVSJRg.png" /><figcaption>Original black and white photo (left), and the colourised result generated by Colourise.sg (right). “Chinese Girls School, Singapore”. Between 1890 and 1920. <a href="https://commons.wikimedia.org/wiki/File:Chinese_girls_school,_Singapore_LCCN2001705620.jpg">Frank and Frances Carpenter Collection, US Library of Congress</a></figcaption></figure><p>While it is impossible to replicate the exact conditions in which the original photo was taken, it is possible to add colour to the photo to help us imagine what the photographer could have seen in that instant. It is incredible — almost magical — how a little bit of colour can bring us that much closer to that specific moment in time.</p><p>And as such, for our hackathon in January, our team decided to build a deep learning colouriser tool trained specifically for old Singaporean photos.</p><blockquote>An important note here: the point of colourisation is to generate an image with colours that are plausible. It by no means guarantees that the colourised image is an accurate representation of the actual snapshot in time.</blockquote><blockquote>Another note: colourisation is a field of active research and our model is by no means perfect — it works well on some images but not others.</blockquote><p>If you have old black and white photos and would like to colourise them, you can do so here: <a href="https://colourise.sg"><strong>Colourise.sg</strong></a>. We do not store any of the photos that you upload to our colouriser application. We are planning to run this service for the month of February — but might extend it depending on usage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9i7I90Buy5Aaj_tV7w5jEQ.png" /><figcaption>The Colourise.sg web application</figcaption></figure><p>We will explain how we created <a href="https://colourise.sg"><strong>Colourise.sg</strong></a> in the following sections of this blog post. Skip ahead to the end if you would like to check out more of our results!</p><h3>Wait. Hasn’t this been done before?</h3><p>Yes — and no.</p><p>While it is true that colourisation tools exist, to our knowledge, none of these tools have been trained to colour images specific to the Singaporean historical context.</p><p>Why does this matter, you ask? Take, for example, the black and white image from the beginning of the article and its colourised output created by the deep learning tool <a href="https://demos.algorithmia.com/colorize-photos/">Algorithmia</a>. Algorithmia produces an image that lacks colour intensity and is not very believable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O2nDweuRJJR6GnU6JHvNwA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*PrftfCBAB7swFwN0Nbt2lg.png" /><figcaption>Original image (left), output image colourised by Algorithmia (right).</figcaption></figure><p>A major contributing factor to poor colourisation of old Singaporean photos could be the fact that the old Singaporean black and white images are too different from the training dataset. The model used by Algorithmia (created by <a href="http://richzhang.github.io/colorization/"><em>Zhang et al</em></a>) is trained using 1.3 million images from <a href="http://www.image-net.org/">ImageNet</a> — a commonly used image database created by researchers at Stanford University and Princeton University.</p><p>And as such, ImageNet is unlikely to have images relevant to Singapore. What this means is that the model is unlikely to have learnt what the colours of an old Singaporean schoolyard scene could plausibly be.</p><p>We hypothesise that a tool trained on Singapore-specific historical images will produce more believable colourised old Singaporean photos than existing tools.</p><h3>How does one colourise a black and white image?</h3><p>Before we jump into how colourisation can be done by a computer programme, let’s first consider how colourisation is done by a human colourist.</p><p>Colourisation is an extremely time and skill-intensive endeavour. In order to create an appropriately colourised photo, an experienced human colourist has to do two tasks:</p><ul><li>(1) do significant research on the historical, geographic, and cultural context of the photo in order to derive appropriate colours, and</li><li>(2) colour the black and white image using software tools like Photoshop.</li></ul><p>(This is of course an oversimplification of the work colourisation artists do — for a more detailed and accurate explanation, <a href="https://www.vox.com/videos/2017/5/30/15712820/how-artists-colorize-old-photos">check out this great video by Vox.</a>)</p><p>Similarly, a computer programme needs to perform the two tasks, albeit in a slightly different manner. A programme needs to:</p><ul><li>(1) identify objects in a black and white photo, and figure out a plausible colour for the objects given images that it has seen in the past, and</li><li>(2) colour the black and white image.</li></ul><h3>Colourisation using Generative Adversarial Networks (GANs) — a deep learning technique</h3><p>To colourise black and white images, we employed a technique in deep learning known as Generative Adversarial Networks (GANs). This comprises:</p><ul><li>A first neural network — a ‘generator’ — with many mathematical parameters (&gt; 20 million) that tries to predict the colour values at different pixels in a black and white image, based on features in the image, and</li><li>A second neural network — the ‘discriminator’ — that tries to identify if the generated colours are photo-realistic compared to the original coloured image.</li></ul><p>The model is trained until the generator can predict colours that the discriminator cannot effectively distinguish as fake. A simplified view of the architecture used for training is shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*1sQUnIuQIItKGZRNEiVdzA.png" /><figcaption>Simplified architecture of GANs for colourisation</figcaption></figure><p>We used the popular fast.ai and PyTorch libraries to develop our model, with an architecture and training steps inspired by Jason Antic (<a href="https://github.com/jantic/DeOldify">https://github.com/jantic/DeOldify</a>). We trained our model based on a new set of more than 500,000 old, publicly available Singapore based images that we compiled, using a local GPU cluster with NVIDIA V100 GPUs.</p><p>Other steps we took to improve our model included adding images from Google’s Open Images V4, especially for body parts that our model did not seem to do too well on (e.g. hands, legs, and arms which were hard for the model to identify), and modifying learning rates and batch sizes for better results.</p><h3>Deploying our deep learning model as a web application</h3><p>At this point, our deep learning model lived in our office’s local GPU cluster — which meant that only our team had access to the colouriser model. In order for the colouriser to be useful to anyone outside our team, we had to deploy it on the internet.</p><p>We went with Google Cloud Platform as our cloud provider for the colouriser service. The architecture is fairly simple, with:</p><ul><li>(1) a CDN offering DDoS protection and caching of static content,</li><li>(2) an NGINX frontend proxy and static content server,</li><li>(3) a load balancer that distributes traffic, and</li><li>(4) backend colouriser services with NVIDIA Tesla K80 GPUs that perform the actual colourisation.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lIRPOIiAIzFVqMoEsPW6_g.png" /><figcaption><em>The architecture diagram for Colourise.sg</em></figcaption></figure><p>The colourisation step is compute intensive and takes approximately 3 seconds to complete per image. As such, we decided to shield the backend colouriser services by using an NGINX server to queue requests to the backend. If the rate of incoming requests far exceeds the rate that our backend services can handle, the NGINX server immediately returns a status response to the client asking the user to try again later.</p><p>The key highlight of this architecture is that the colouriser service virtual machines (VMs) are autoscaled in response to how much traffic each VM has to service. This saves on cost because additional VMs are only switched on when there is demand for it.</p><h3>Results</h3><p>Here are some of our favourite results using photos obtained with permission from the New York Public Library and the National Archives of Singapore. We would like to note that our sources only provided us with the black and white photos and are not in any way responsible for the colourised output created by us.</p><h4>Good results</h4><p>Our model performs well on high resolution images that prominently feature human subjects (images where people occupy a large portion of the image) and natural scenery.</p><p>The following images look believable (at least to us) because they contain objects that exist in sufficient examples of the training image dataset. And so the model is able to identify the correct objects in the image and colour them believably.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*U532K0BTSugDeJZlPWstLw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*ZIJMlgZl9U9KVHRwmO1djw.jpeg" /><figcaption><a href="http://www.nas.gov.sg/archivesonline/watermark/picas_data/tn_pcd/19980000537-6320-3081-0479/img0021.jpg">“Malaysia Day Celebrations at Padang” — Yang Di-Pertuan Negara Yusof Ishak and Federation’s Internal Minister for Security Dato Dr Ismail bin Dato Abdul Rahman. 16 September 1963. The National Archives of Singapore (left), colourised photo by Colourise.sg (right).</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*oER3Lz4LnvWWf9G8HmcGCg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*V2fvD0jvaI-xp1aQ8R5rgA.jpeg" /><figcaption><a href="http://www.nas.gov.sg/archivesonline/watermark/picas_data/tn_pcd/19980007185-8261-3201-4550/img0108.jpg">“Minister for the Interior and Defence Lim Kim San speaking at Passing Out Parade of officer cadets at Pasir Laba Camp in Jurong”. 10 July 1969. The National Archives of Singapore (left), colourised photo by Colourise.sg (right).</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*R_hqi8WVJb5zvfGfsRM4JQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*H9p5duENyCY80QpHK2hZ5w.jpeg" /><figcaption><a href="https://digitalcollections.nypl.org/items/c2634d03-247e-f238-e040-e00a18061845">“Connaught Drive, Singapore.” <em>The New York Public Library Digital Collections</em>. The Miriam and Ira D. Wallach Division of Art, Prints and Photographs: Picture Collection, The New York Public Library </a><a href="https://digitalcollections.nypl.org/items/c2634d03-24b6-f238-e040-e00a18061845">(left), colourised photo by Colourise.sg (right).</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*KtvRlHs4jx9Sx7iWTj-0Ew.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*IZDsDOCr7QO5kLzaC7ldnA.jpeg" /><figcaption><a href="https://digitalcollections.nypl.org/items/c2634d03-24b5-f238-e040-e00a18061845">“Singapore.” <em>The New York Public Library Digital Collections</em>. The Miriam and Ira D. Wallach Division of Art, Prints and Photographs: Picture Collection, The New York Public Librar</a>y <a href="https://digitalcollections.nypl.org/items/c2634d03-24b6-f238-e040-e00a18061845">(left), colourised photo by Colourise.sg (right)</a><a href="https://digitalcollections.nypl.org/items/c2634d03-24b5-f238-e040-e00a18061845">.</a></figcaption></figure><h4>Something funky</h4><p>Funky things happen when the model does not recognise objects in the photo.</p><p>Take for example the following image, “Japanese Surrender at Singapore”. The colouriser colours one — and only one — of the soldiers’ fist red. But it gets the rest of the soldiers’ fists correct. This happens because the model is unable to tell that the clenched fist is actually a fist from the angle the photo was taken. And so the colouriser makes its best guess but didn’t quite get it right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Ios_BhKIVQewokqXXtx5dg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*-Gb5WM0d96K2I5BwdNGXMA.jpeg" /><figcaption><a href="https://www.iwm.org.uk/collections/search?query=A+30491">“Japanese Surrender at Singapore”. 12 September 1945. Royal Navy official photographer — Trusler C (Lt). Imperial War Museums </a><a href="https://digitalcollections.nypl.org/items/c2634d03-24b6-f238-e040-e00a18061845">(left), colourised photo by Colourise.sg (right)</a><a href="https://digitalcollections.nypl.org/items/c2634d03-24b5-f238-e040-e00a18061845">.</a></figcaption></figure><p>This happens again in the following image, “Minister of Finance Dr. Goh Keng Swee arrives at opening of Bata shoe factor in Telok Blangah”. The face of the man on the right of the photo is coloured a ghastly grey because half of the man’s face is hidden from view, and so the model is unable to identify the object in the photo.</p><p>This phenomenon is known as <strong>occlusion — </strong>one of the major challenges in computer vision, where object recognition algorithms have trouble identifying objects that are partially covered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*ontnLe71mP3vaM6LdAEuFg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*xxsI8BiuYN7KUGrwKnZYYA.jpeg" /><figcaption><a href="http://www.nas.gov.sg/archivesonline/watermark/picas_data/tn_pcd/19980000368-6317-3042-0469/img0073.jpg">“Minister of Finance Dr. Goh Keng Swee arrives at opening of Bata shoe factory in Telok Blangah”. 09 April 1964. The National Archives of Singapore</a> <a href="https://digitalcollections.nypl.org/items/c2634d03-24b6-f238-e040-e00a18061845">(left), colourised photo by Colourise.sg (right)</a><a href="https://digitalcollections.nypl.org/items/c2634d03-24b5-f238-e040-e00a18061845">.</a></figcaption></figure><h4>More cool results</h4><p>Here are more cool results from the colouriser. Because, why not?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*hQFaXJqweKuRF3L-6jA-ow.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*Dr6ham2ZcUNoNWi3OqV-zw.jpeg" /><figcaption><a href="https://digitalcollections.nypl.org/items/c2634d03-24b5-f238-e040-e00a18061845">“Singapore.” <em>The New York Public Library Digital Collections</em>. The Miriam and Ira D. Wallach Division of Art, Prints and Photographs: Picture Collection, The New York Public Library</a> <a href="https://digitalcollections.nypl.org/items/c2634d03-24b6-f238-e040-e00a18061845">(left), colourised photo by Colourise.sg (right)</a><a href="https://digitalcollections.nypl.org/items/c2634d03-24b5-f238-e040-e00a18061845">.</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*VwQKIUxUuBzLu_f3u8eIVw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*0FKA5QN5zta_Thy2OxXqYA.jpeg" /><figcaption><a href="https://digitalcollections.nypl.org/items/c2634d03-247b-f238-e040-e00a18061845">“Malay girl, Singapore”. Date unknown. <em>The New York Public Library Digital Collections.</em>The Miriam and Ira D. Wallach Division of Art, Prints and Photographs: Picture Collection, The New York Public Library (left), colourised photo by Colourise.sg (right).</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*At5hB0zkPAeI2PpApmSM3g.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*drhGpI-e1bMTcx3-7T5hag.jpeg" /><figcaption><a href="https://digitalcollections.nypl.org/items/c2634d03-24b6-f238-e040-e00a18061845">“Singapore”. Date unknown. <em>The New York Public Library Digital Collections. </em>The Miriam and Ira D. Wallach Division of Art, Prints and Photographs: Picture Collection, The New York Public Library (left), colourised photo by Colourise.sg (right).</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*idnyuc_DNXEZe1Sh3TlvAA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*7FGdLSkVBQMu-L_hbzxPcQ.jpeg" /><figcaption><a href="http://digitalcollections.nypl.org/items/c2634d03-24a9-f238-e040-e00a18061845">“Cattle grazing amid piles of coconut shells, Singapore.” <em>The New York Public Library Digital Collections</em>. The Miriam and Ira D. Wallach Division of Art, Prints and Photographs: Picture Collection, The New York Public Library </a><a href="https://digitalcollections.nypl.org/items/c2634d03-24b6-f238-e040-e00a18061845">(left), colourised photo by Colourise.sg (right)</a><a href="http://digitalcollections.nypl.org/items/c2634d03-24a9-f238-e040-e00a18061845">.</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*yh4yZYZ4lgcs0gvCA1Cp-A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*vI0nist7BYH5MJHwoaBL6A.jpeg" /><figcaption><a href="https://digitalcollections.nypl.org/items/c2634d03-249f-f238-e040-e00a18061845">“Malay woman, Singapore.” <em>The New York Public Library Digital Collections</em>. The Miriam and Ira D. Wallach Division of Art, Prints and Photographs: Picture Collection, The New York Public Library </a><a href="https://digitalcollections.nypl.org/items/c2634d03-24b6-f238-e040-e00a18061845">(left), colourised photo by Colourise.sg (right)</a><a href="https://digitalcollections.nypl.org/items/c2634d03-249f-f238-e040-e00a18061845">.</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*MvNNAD7-GOw94qIPpbnADQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*e3MJbki2tMYkYc2W_55UKQ.jpeg" /><figcaption><a href="https://digitalcollections.nypl.org/items/c2634d03-249c-f238-e040-e00a18061845">“Adelphi Hotel Singapore.” <em>The New York Public Library Digital Collections</em>. 1926. The Miriam and Ira D. Wallach Division of Art, Prints and Photographs: Picture Collection, The New York Public Library </a><a href="https://digitalcollections.nypl.org/items/c2634d03-24b6-f238-e040-e00a18061845">(left), colourised photo by Colourise.sg (right)</a><a href="https://digitalcollections.nypl.org/items/c2634d03-249c-f238-e040-e00a18061845">.</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*VIZoril3ztt8kS3zaOnbkA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*6s46S7XyLBZZNhotO9X1XQ.jpeg" /><figcaption><a href="https://digitalcollections.nypl.org/items/c2634d03-24a5-f238-e040-e00a18061845">“Jiksha Station, Singapore.” <em>The New York Public Library Digital Collections</em>. The Miriam and Ira D. Wallach Division of Art, Prints and Photographs: Picture Collection, The New York Public Library </a><a href="https://digitalcollections.nypl.org/items/c2634d03-24b6-f238-e040-e00a18061845">(left), colourised photo by Colourise.sg (right)</a><a href="https://digitalcollections.nypl.org/items/c2634d03-24a5-f238-e040-e00a18061845">.</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*SCZQQrkmxATVRDjmF6ypzg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*lEKWrYDWRbR3qjoJeoagdA.jpeg" /><figcaption><a href="https://digitalcollections.nypl.org/items/c2634d03-2483-f238-e040-e00a18061845">“Queen’s Place, Singapore.” <em>The New York Public Library Digital Collections</em>. The Miriam and Ira D. Wallach Division of Art, Prints and Photographs: Picture Collection, The New York Public Library </a><a href="https://digitalcollections.nypl.org/items/c2634d03-24b6-f238-e040-e00a18061845">(left), colourised photo by Colourise.sg (right)</a>.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*Sy5RbILZZcNzwjYgY7wWzw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*zv0ga-vNlpTMYtz5XD3pTA.jpeg" /><figcaption><a href="https://digitalcollections.nypl.org/items/c2634d03-2479-f238-e040-e00a18061845">“Anderson Bridge, Singapore.” <em>The New York Public Library Digital Collections</em>. The Miriam and Ira D. Wallach Division of Art, Prints and Photographs: Picture Collection, The New York Public Library (left), colourised photo by Colourise.sg (right).</a></figcaption></figure><h3><strong>Updates</strong></h3><p><em>10 Feb 2019, one week after the release of Colourise.sg</em></p><h4>More results from Twitter</h4><p>Here are some more cool (mostly non-Singapore specific) photos shared by users on Twitter.</p><h3>Qué Gorrión! ⚪🔴⚪ 🏆 on Twitter</h3><p>Necesitas colorear una foto? Entra a https://t.co/9jxpJl6s9C Un ej que hice en segundos</p><h3>Phillip Parton on Twitter</h3><p>Found this AI based image colouriser and while the AI has been trained on modern images, the results on photos freely available from @Te_Papa taken in 1880 in Tonga look great! King George Taufa&#39;ahau, Nuku&#39;alofa facing the palace, ladies from Neiafu. https://t.co/nO6uGzKZvZ</p><h3>Will Exline on Twitter</h3><p>Technology! https://t.co/SRSxq6EmU6 turns B&amp;amp;W photos into color in seconds. (HT @MusaTariq @sriramk)</p><h3>Justin Taylor on Twitter</h3><p>This website uses tech to automatically colorize old photos. Here&#39;s my grandparents wedding photo! So so awesome. Thank you @MusaTariq for sharing! https://t.co/vToVJkp3qJ</p><h3>Armesto 3D on Twitter</h3><p>A pretty amazing web with a deep learning colorizer for old pics. Recommended! https://t.co/D5vTFCxqss</p><h3>Esmeralda Román on Twitter</h3><p>A mi estas cosas me dejan loca. #Colourise es una web en la que puedes subir una foto en blanco y negro y la convierte a color. No está al 100%, pero ni tan mal. He probado con un fotograma de Roma y OJO, en menos de 10 segundos.</p><p><em>We would like to thank Richard Zhang and Jason Antic for their image colourisation research work that inspired this project. We would also like to thank the National Archives of Singapore, the New York Public Library, and US Library of Congress for approving the use of archive photos in this article.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=435ae5cc5036" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I wrote a program that speaks like the collective hive-mind of The Straits Times Forum]]></title>
            <link>https://medium.com/data-science/i-wrote-a-program-that-speaks-like-the-collective-hive-mind-of-the-straits-times-forum-41c96e7d8d71?source=rss-8598d290eacf------2</link>
            <guid isPermaLink="false">https://medium.com/p/41c96e7d8d71</guid>
            <category><![CDATA[news]]></category>
            <category><![CDATA[towards-data-science]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[singapore]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Preston Lim]]></dc:creator>
            <pubDate>Sun, 20 Jan 2019 03:41:05 GMT</pubDate>
            <atom:updated>2019-01-21T14:56:08.574Z</atom:updated>
            <content:encoded><![CDATA[<p>The forum section of The Straits Times — one of the major news papers in Singapore — is a national treasure. The forum section specifically serves as a platform for wizened and impassioned Singaporeans to share their views on Singaporean culture and society.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*akflhL6zx6OHAcSg" /><figcaption>Photo by <a href="https://unsplash.com/@elijahsad?utm_source=medium&amp;utm_medium=referral">Elijah O&#39;Donnell</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Among the many seminal works is “<a href="https://www.straitstimes.com/forum/letters-on-the-web/unsafe-to-sew-on-train"><strong>Unsafe to sew on trains</strong></a>” — in which a concerned citizen calls for the strict regulation of sewing on trains because of the many ways someone sewing on public transport can inflict bodily harm to other passengers. What if someone gets impaled in the eye? How can they seek recourse?</p><p>And my personal favorite, “<a href="https://www.straitstimes.com/forum/letters-on-the-web/bukit-timah-belt-schools-breeding-elitist-students"><strong>Bukit Timah belt schools breeding elitist students</strong></a>”, a passionate plea for students to stop wasting valuable money on Starbucks, so that the forum letter writer can sacrifice her much-less-valuable money on the exact same drinks.</p><p>I find that I cannot go a day without trawling through the Straits Times Forum for conventional wisdom so thoroughly lacking in modern Singapore.</p><p>And so I decided to create the Straits Times Forum Letter Generator (STFLG) to constantly tell me what I need to do in order for Singaporean society to not crumble to pieces.</p><p>If you’d like to give it a go, you can find it here: <a href="https://prestonlimlianjie.github.io/straits-times-forum-letter-generator/"><strong>Straits Times Forum Letter Generator</strong></a>. I will explain the algorithm used by STFLG in the next section — skip to the end for some of my favorite pieces made by STFLG.</p><h3><strong>Markov chains explained with the help of Beyoncé</strong></h3><p>The goal of STFLG is to create an article — essentially a bunch of text — in the style of the Straits Times Forum section.</p><p>The underlying algorithm I chose for STFLG is the <strong>Markov chain</strong>, a commonly used technique in next-word prediction on your mobile phone and the prediction of stock prices. Or in other hilarious applications like the <a href="https://filiph.github.io/markov/">Trump tweet generator</a> —which is really not too different from STFLG.</p><p>Anyway, the Markov chain is a very simple algorithm that is often heavily obscured by <a href="https://en.wikipedia.org/wiki/Markov_chain#Discrete-time_Markov_chain">unnecessarily complicated mathematical notation</a>. Let me instead attempt to explain Markov chains using a lyric from <a href="https://open.spotify.com/track/5IVuqXILoxVWvWEPm82Jxr?si=jIJxlJ_bTf6ExKjQnfRXXA"><em>Crazy in Love</em> by <em>Beyoncé</em></a>:</p><blockquote>“&lt;START&gt; uh oh uh oh uh oh oh no no &lt;END&gt;”</blockquote><p>Let’s say that we want to create a lyric in the same style as <em>Crazy in Love</em>. Our algorithm would have to do two things: (1) learn the style of the song, and (2) generate a lyric with that style.</p><p>Remember, the goal isn’t to exactly reproduce the lyric but to create a new lyric that is similar in nature.</p><h4>Specifically, (1) can be achieved by studying a corpus (a body of text) and calculating the probability of a word occurring given that another word has been chosen.</h4><p>This sounds like abstract gobbledegook so let’s look at a concrete example.</p><p>In the lyric above, we know that “oh” comes after “uh” 100% of the time. We also know that “oh” comes after “no” 50% of the time, and “oh” comes after “oh” 25% of the time. Given these probabilities, we can say the following:</p><p>If the current word is:</p><blockquote>“uh”, <em>the next word is</em> “oh” — <strong><em>100%</em></strong><em> of the time<br></em>“oh”, <em>the next word is </em>“uh” — <strong><em>50%</em></strong>, “oh” — <strong><em>25%</em></strong>, “no” — <strong><em>25%</em></strong><em> of the time respectively<br></em>“no” , <em>the next word is</em> “no” — <strong><em>50%</em></strong>, “&lt;END&gt;” — <strong><em>50%</em></strong><em> of the time respectively<br></em>“&lt;START&gt;”, <em>the next word is</em> “uh” — <strong><em>100%</em></strong><em> of the time</em></blockquote><p>We have just created our Markov chain!</p><h4>Now let’s perform step (2): generating a new lyric using our Markov chain.</h4><p>Let’s start with “<em>&lt;START&gt;</em>” and roll a die to pick the next word. Since the next word that comes after “<em>&lt;START&gt;</em>” is “<em>uh</em>” 100% of the time, we choose “<em>uh</em>”. Now we roll a die to pick our next word. The next word that comes after “<em>uh</em>” is “<em>oh</em>” a 100% of the time too, so we pick “<em>oh</em>”.</p><p>We now have:</p><blockquote>“&lt;START&gt; uh oh”</blockquote><p>Here’s where it gets interesting.</p><p>Given that we have the word “oh”, our next word could be “uh”, “no”, or “oh”. Let’s say that we roll a die at this moment in time — the word happens to be “oh”. But if we re-did this entire process, the word that was chosen could be “no” or “uh” instead. And as such, we could have:</p><blockquote>“&lt;START&gt; uh oh uh…” — <strong><em>50%</em></strong><em> of the time<br></em>“&lt;START&gt; uh oh oh…” — <strong><em>25%</em></strong><em> of the time<br></em>“&lt;START&gt; uh oh no….” — <strong><em>25%</em></strong><em> of the time</em></blockquote><p>And given that there are now three different possible outcomes when we have three words, we can have six outcomes when we have four words:</p><blockquote>“&lt;START&gt; uh oh uh oh” — <strong><em>50%</em></strong><em> of the time<br></em>“&lt;START&gt; uh oh oh uh” — <strong><em>12.5%</em></strong><em> of the time<br></em>“&lt;START&gt; uh oh oh oh” — <strong><em>6.25%</em></strong><em> of the time<br></em>“&lt;START&gt; uh oh oh no” — <strong><em>6.25%</em></strong><em> of the time<br></em>“&lt;START&gt; uh oh no no” —<em> </em><strong><em>12.5%</em></strong><em> of the time<br></em>“&lt;START&gt; uh oh no &lt;END&gt;” — <strong><em>12.5%</em></strong><em> of the time</em></blockquote><p>After some #<a href="https://www.youtube.com/watch?v=3M_5oYU-IsU">quickmaths</a>, we get the original lyric:</p><blockquote>“&lt;START&gt; uh oh uh oh uh oh oh no no &lt;END&gt;” — <strong><em>0.78125%</em></strong><em> of the time</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*vbFHIQ_EE0l0qRnqIxntUA.jpeg" /><figcaption>Skrrat, skidi-kat-kat. Boom.</figcaption></figure><p>However, we get lyrics that are similar but not exactly the same (the differences are highlighted in bold):</p><blockquote>“&lt;START&gt; uh oh uh oh uh oh <strong>uh </strong>oh no no &lt;END&gt;” —<strong><em> 0.78125%</em></strong><em> of the time<br></em>“&lt;START&gt; uh oh uh oh <strong>oh uh</strong> oh no no &lt;END&gt;” — <strong><em>0.390625%</em></strong><em> of the time<br></em>“&lt;START&gt; uh oh uh oh uh oh<strong> uh oh</strong> no &lt;END&gt;” — <strong><em>3.25%</em></strong><em> of the time</em></blockquote><p><em>Skidiki-pap-pap, and a pu-pu-pudrrrr-boom</em>. <br><em>Skya, du-du-ku-ku-dun-dun.</em></p><p>#quickmaths.</p><p>Sorry, I got distracted.</p><p>It is interesting to note that in this toy example where there is only one lyric in the corpus, there is an exactly <strong>0.78125%</strong> chance that the original lyric is generated, but a much higher <strong>(4.3%)</strong> chance that any of the 3 above mentioned similar lyrics is generated.</p><p>And so as the Markov chain grows, the generated lyric is unlikely to be exactly the same as the original, but it is very likely to be similar.</p><p>This is the intuition behind Markov chains.</p><h4>Improving our algorithm: second-order Markov chains</h4><p>The algorithm described above is known as a <strong>first-order Markov chain</strong>; it works decently for the most part, but breaks in some cases.</p><p>Consider the following example. We have generated three words, “<em>I ate a</em>”. The first-order Markov chain attempts to find the next word. However, it has five choices it can pick from — not all of which make sense to a human reader.</p><blockquote><strong><em>First-order Markov chain</em></strong><em><br>Current word: “</em>a<em>”<br>Next word: “</em>duck, window, giraffe, breeze, carrot<em>”</em></blockquote><p>But the algorithm is just as likely to pick “<em>window</em>” as it is “<em>duck</em>”. I don’t know about you, but I don’t quite consider myself a connoisseur of windows.</p><p>This is where the first-order Markov chain trips up. We can improve the generator by instead using a <strong>second-order Markov chain</strong>. The second-order Markov chain is similar to the first-order Markov chain described above, except for one crucial detail.</p><p>Instead of choosing the next word based on what the previous word was, a second-order Markov chain chooses the next word based on what the previous <strong>two</strong> words were.</p><p>Consider the following example:</p><blockquote><strong><em>Second-order Markov chain<br></em></strong><em>Current two words: “</em>ate a<em>”</em><strong><em><br></em></strong><em>Next word: “</em>duck, carrot<em>”</em></blockquote><p>Second-order Markov chains are more likely to generate believable articles than first-order ones since they have more “historical context”.</p><p>One could conceivably implement higher-order Markov chains to improve the prediction ability of the generator. And that is indeed the case for applications in stock price or protein folding prediction, where one would like as accurate a prediction as possible. But in our case, we just want something that is believable — and not the exact replica of an existing Straits Times forum letter.</p><h3>Results</h3><p>I very diligently studied thousands of the Straits Times Forum Letters and was able to create a second-order Markov chain capturing the “style” of the forum letters. I then generated my own articles using the above-mentioned second-order Markov chain — you can play with it here:<strong> </strong><a href="https://prestonlimlianjie.github.io/straits-times-forum-letter-generator/"><strong>Straits Times Forum Letter Generator</strong></a>.</p><p>Here are some of my favorite articles generated by STFLG. I genuinely think some of these are poetry.</p><p><strong>Disclaimer: none of these articles reflect any of my viewpoints… or really anyone’s.</strong></p><blockquote><strong>Post to work together.</strong></blockquote><blockquote>In the ward, if you are an imposed stringent code of conduct and watermark for peace in the many government grants and giving due regard to our environment immediately, but was not granted, and perhaps more outdoor seating provided for people attempting suicide; Sept 9). It is arguably the most effective way of life, is unreasonable.</blockquote><blockquote>While most of us need to use Tasers to restrain the violent or weapons-wielding subjects.</blockquote><blockquote>Instead of begrudging ministers their high salaries.</blockquote><blockquote><strong>Schools, need to respect and space requirements surface.</strong></blockquote><blockquote>For instance, a sunset industry. I may like hawker food remains affordable for all.</blockquote><blockquote>There is nothing more than 400 SCCs in schools</blockquote><blockquote>While investing in the national feedback unit — guarantee access to affordable, quality goods and people fighting depression are labelled “spoilt” or “weak”.</blockquote><blockquote>Perhaps recess in Singapore.</blockquote><blockquote><strong>Having account, ATM card can protect and facilitate but do not own a car.</strong></blockquote><blockquote>They help Singaporeans understand the key driver of the taxpayer in entering into the public eye.</blockquote><blockquote>The estimated payout provided last month because the leaders were one with extremely few natural resources too, to ensure that these agencies have to continue increasing land sales programme without fixing the inherent problem, while dampening market sentiment with a bank account for FDWs to access social assistance to persons with disabilities to walk to a minority of Singaporeans who did well in the workforce remains relatively low property prices.</blockquote><blockquote>We take pride in securing this top honour.</blockquote><blockquote><strong>Week’s Letter #1: Time S’pore responded like-for-like to Malaysia at Johor’s request; Jan 6).</strong></blockquote><blockquote>I also wonder how much allows us back into the carriage and found it to mean targeting specific groups of National Development.</blockquote><blockquote><strong>Working preserve, enhance Pulau Ubin’s living community which renders the island are organising “eat all you can” durian tours to Malaysia.</strong></blockquote><blockquote>Hence we should adopt.</blockquote><blockquote>The recent cyber attack, I realised that it will be brave and strong corporate governance, often underpinned by technology.</blockquote><blockquote>The Ministry of Social and Family Development</blockquote><blockquote><strong>Lions dearth of strikers</strong></blockquote><blockquote>Singapore’s biggest resource is its strength.</blockquote><blockquote>I have seen how these have been using gross domestic product (GDP) and GDP per capita utility usage rate is more objective to better understand the effectiveness of past and the appointment reminder sent via SMS.</blockquote><blockquote>We believe that a fractured Asean will respond to something they did not cease with the latest case of SNEC, its charges periodically to determine if tax avoidance based on their food.</blockquote><blockquote>Bit by bit, we can all be able to read about the best recruit who I voted for was the photograph that accompanied it — few would disagree with Mr Seah Yam Meng’s letter (Airport-like checks at our wet markets in the comfort of their PMDs, manage indiscriminate parking of cars drastically.</blockquote><h3>Takeaways</h3><p>This was another fun-and-frivolous™ project brought to you by yours truly (mostly) because I am sick in bed. Oh the things software engineers do for fun/instead of recuperating.</p><p>Here are my takeaways:</p><ol><li>I was surprised at how easy it was to implement my own second-order Markov chain.</li><li>I might look back in a year or two and regret making a program that emulates the collective hive-mind of The Straits Times Forum.</li></ol><p>If you enjoyed this, do check out my other pieces, like the one about a <a href="https://blog.usejournal.com/i-made-a-machine-learning-chicken-rice-classifier-in-4-hours-to-tell-me-what-type-of-chicken-rice-e9b1af4aa069"><strong>Machine Learning Chicken Rice Classifier</strong></a> that I made.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41c96e7d8d71" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/i-wrote-a-program-that-speaks-like-the-collective-hive-mind-of-the-straits-times-forum-41c96e7d8d71">I wrote a program that speaks like the collective hive-mind of The Straits Times Forum</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I made a machine learning chicken rice classifier in ~4 hours to tell me what type of chicken rice…]]></title>
            <link>https://medium.com/@prestonlim/i-made-a-machine-learning-chicken-rice-classifier-in-4-hours-to-tell-me-what-type-of-chicken-rice-e9b1af4aa069?source=rss-8598d290eacf------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9b1af4aa069</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[chicken]]></category>
            <category><![CDATA[singapore]]></category>
            <dc:creator><![CDATA[Preston Lim]]></dc:creator>
            <pubDate>Tue, 25 Sep 2018 09:49:46 GMT</pubDate>
            <atom:updated>2018-10-25T18:54:38.686Z</atom:updated>
            <content:encoded><![CDATA[<h3>I made a machine learning chicken rice classifier in ~4 hours to tell me what type of chicken rice I bought for lunch</h3><p>This entire frivolous episode started when my colleague got chicken rice for lunch. The lunchtime conversation then evolved into how there was this hilarious Instagram account called<em> kuey.png</em> whose owner photographed one plate of chicken rice every single day for 279 days as of yesterday.</p><p>An aside here. For non-Singaporeans: “<em>kuey png</em>” is the Hokkien term for chicken rice, one of the national dishes of Singapore. And this Instagram account owner uploads .png format photos of the chicken rice — hence the name, <em>kuey.png</em>. This really tickled me. Anyway, back to the lunchtime convo.</p><p>As conversations in the Data Science Division of GovTech do, our convo soon spiralled into “wow this would be an amazing machine learning dataset for chicken rice” and “wait could we train a classifier to differentiate between <strong>steamed </strong>and <strong>roasted</strong> chicken rice?”. Next thing I know, it is 1am on a Monday night and I’m waiting for my chicken rice machine learning model to finish training.</p><p>Here’s the solution — a tool that allows you to take or upload a photo of chicken rice, and the machine learning classifier tells you if it is a plate of steamed or roasted chicken rice. (I’m still debating whether I should turn it into a web app that anyone can use. Let me know what you think.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0rMCL6BIBhX8_9kR1fOfng.png" /><figcaption>Because… I don’t know why.</figcaption></figure><p>At the heart of the ridiculous exercise is this point: you can now create and deploy a very simple ML project within hours, thanks to the magic that is Google AutoML Vision.</p><h3>The magic of AutoML Vision</h3><p>Traditionally, it would haven taken me days at the very least to create and deploy an ML classifier on the internet. I would have had to (1) curate and label the dataset, (2) train an ML classifier, (3) deploy the ML model, (4) create a server with a REST API to call the ML classifier.</p><p>With AutoML Vision, all I had to do was step (1). And that’s why I was able to finish the entire project in ~4 hours. Though to be perfectly honest, I could have completed it sooner, but I was multi-tasking by labelling the chicken rice images while watching the extremely confusing pilot of <em>Maniac</em> ft. Emma Stone and Jonah Hill. What is even going on in this show? What year is it supposed to be in the world of <em>Maniac</em>? Anyway, I digress. Here’s a quick rundown of what I did.</p><p><strong>Step 1: Obtain images from <em>kuey.png</em> on Instagram</strong></p><p>Because Instagram makes it really hard to obtain images from its platform, I painstakingly took screenshots of the 279 individual images on my Macbook.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jRP2UFBAlWPrD8pl6uzfKw.png" /><figcaption>I got really hungry doing this.</figcaption></figure><p><strong>Step 2: Upload images onto AutoML</strong></p><p>I dragged and dropped all 279 images into AutoML and watched Netflix while they were uploading.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WfbDlIc4llsIk-P1_d38xg.png" /></figure><p><strong>Step 3: Label images</strong></p><p>I then labelled each image as <strong>roasted</strong> or <strong>steamed</strong>. This was really tough because I was debating between classifying “soy sauce chicken” as either roasted or steamed, or making it its own class. I eventually went with <strong>steamed </strong>since it technically is a steamed chicken, but chicken rice purists will fervently disagree with me.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jSAY9IHKXeq61SkBC9laxQ.png" /><figcaption>This was when I realized that the kuey.png person prefers roasted chicken rice over steamed chicken rice. I don’t blame them.</figcaption></figure><p><strong>Step 4: Train ML model</strong></p><p>I just clicked on “Train”. More Netflix happened. Simply because AutoML does several things automatically:</p><ol><li>it extracts 10% of the dataset to keep for model testing/validation.</li><li>it scales your images for you.</li><li>it generates the precision/recall graphs and confusion matrix for you.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ren8CgwJ43XZ9emWVqlLcQ.png" /><figcaption>The best Netflix and Chill companion</figcaption></figure><p><strong>Step 5: Validate ML model</strong></p><p>30 mins later — the results were out.</p><p>The precision and recall were decent enough. And according to the confusion matrix, the ML model was able to accurately classify <strong>all</strong> the roasted chicken rice photos (yay!).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uf9pt9J4H8jBN6kJDT0kMg.png" /></figure><p>However, the model got a little confused (hence the name confusion matrix) by some steamed chicken rice dishes. More specifically, the model thought that an image of a steamed chicken was a roasted chicken 16.7% of the time when it was actually a steamed chicken.</p><p>I mean, I don’t blame it. Have you seen how some people slather their chicken rice with so much soy sauce and chili that you can’t quite make out what they’re eating? Because I’m one of those people.</p><p>Some of the photos were really quite challenging to classify (shown below).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ObZRg6HD2SYnJGWhGjFW2Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8cNRQEJrgLjoUdoBs5P7_w.png" /><figcaption>Left: Soy sauce chicken masquerading as a steamed chicken; Right: At this point, are you really eating chicken rice with chilli, or chilli with chicken rice?</figcaption></figure><p>Next, I tested the ML model with new images of chicken rice: both steamed and roasted. And it was able to accurately classify each of them — albeit with much more confidence for roasted chicken rice than steamed chicken rice. I was quite pleased with it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0rMCL6BIBhX8_9kR1fOfng.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BDmT6DwA-tAaAeUOGSak0A.png" /><figcaption>I can’t believe this actually worked!</figcaption></figure><h3>My Takeaways (dabao)</h3><p>I might have jumped into this little machine learning project in jest, but I’ve managed to gain some pretty neat insights:</p><ul><li>AutoML is next-level voodoo magic. It’s also very meta — AutoML uses an ML model to train ML models. How crazy is that?</li><li>AutoML democratizes machine learning for non-ML experts by abstracting the complexities of machine learning.</li><li>While AutoML may not be the best solution for hard ML problems, people who do not have the technical skills to dabble in ML are now placed on a more level playing field as those who do.</li></ul><p><em>Special thanks to kuey.png for dilligently ordering, taking photos of, and eating one plate of chicken rice every single day.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*NJVG2C_1QiqyD45ciYTL5w.png" /></figure><figure><a href="https://blog.usejournal.com/meet-journal-d222fce8db1d"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f2IVAl0TbsfES9cFGYr40g.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9b1af4aa069" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hack Your Life: How to make your own Digital Business Card]]></title>
            <link>https://medium.com/@prestonlim/hack-your-life-how-to-make-your-own-digital-business-card-7a26ac400933?source=rss-8598d290eacf------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a26ac400933</guid>
            <category><![CDATA[digital]]></category>
            <category><![CDATA[life-hacking]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[business-cards]]></category>
            <category><![CDATA[recruiting]]></category>
            <dc:creator><![CDATA[Preston Lim]]></dc:creator>
            <pubDate>Mon, 26 Mar 2018 14:53:26 GMT</pubDate>
            <atom:updated>2018-09-29T04:04:29.477Z</atom:updated>
            <content:encoded><![CDATA[<p><em>[Update 29 Sep 2018: Liwei and I released </em><a href="https://firstnamebasis.app/"><em>https://firstnamebasis.app/</em></a><em> — a free service to generate your personal digital business card]</em></p><p>Business cards are quite a pain to carry around.</p><p>You never quite know how many to bring along to a meeting or a work-related event. And there’s that awkward moment mid-handshake when you’ve realized that you’re out of business cards.</p><p>Despite all the fuss, business cards still remain a great tool for exchanging contact information. But can we do this without needing physical business cards?</p><h3>Scan and save</h3><p>What if all it took to exchange contact information was a simple <em>scan and save</em>?</p><p>Imagine this: you are trying to obtain contact information from person A. Person A displays a QR code on their phone, and all you have to do is scan their phone using your iPhone camera. Their contact information is automatically displayed on your phone and you hit the save button. Voila, now you have their contact information in your Contacts list.</p><p>If you’re currently on your desktop/laptop, you might want to grab your phone to give this a go.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*c5re0C0X4_ARoB5mUCLXKQ.png" /><figcaption>QR code for my digital business card</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*BnIGG9qx5-gHQrOkNkP-cA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*1_pyFIV-QTyjI7vbJVe6Ng.png" /><figcaption>Contact information displayed on mobile website (left) and VCF in the Contacts app after download (right)</figcaption></figure><p>All the fields in the mobile website are interactive. If you tapped on the contact number field, you would automatically dial the number shown (not my actual mobile number).</p><p>After clicking on the download button, a Virtual Contact File (VCF) will be downloaded and synced into your Contacts app instantly.</p><p>Simple enough, isn’t it?</p><h3>Tutorial: 7 easy steps</h3><p>Now you get to create your own digital business card! You don’t need to have any coding experience to do this — I will explain what exactly to do. Please feel free to leave comments if you do get stuck!</p><p><strong>Step 1: Create a GitHub account (if you don’t already have one)</strong></p><p>Let’s start off by creating a GitHub account and logging in. Most of our work will be done in GitHub.</p><p><a href="https://github.com/join">https://github.com/join</a></p><blockquote><strong>What is GitHub?<br></strong>GitHub is a platform traditionally used by software engineers to store their code and keep track of the changes that have been made over time (a.k.a. version control).</blockquote><blockquote>But for our purposes, let’s just treat GitHub as a gigantic Word Document that stores all of our contact information. This is also where we will be making changes in the code.</blockquote><p><strong>Step 2: Fork from my code repository (repo)</strong></p><p>In this step, we are going to make a fork — a copy — of my repo. We want to do this so that you can replace my contact information with your own.</p><blockquote><strong>What is a repo?<br></strong>A repository, or repo for short, is a place where files are held. Imagine it as a bucket or folder that holds a bunch of code documents.</blockquote><blockquote><strong>What is a fork? <br></strong>A <em>fork</em> is a copy of a repository. Forking a repository allows you to freely experiment with changes without affecting the original project.</blockquote><p>Open your browser window and go to the following url (make sure that you have logged into your GitHub account): <a href="https://github.com/prestonlimlianjie/digital-namecard">https://github.com/prestonlimlianjie/digital-namecard</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TLHH2F8hKQwX2rEdQD8A4A.png" /><figcaption>GitHub repo containing all the relevant files.</figcaption></figure><p>Click on the ‘Fork’ button on the top right of the page. Wait a few moments!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NtZb3676GEa40Rg9or7IsA.png" /><figcaption>Forking in progress! I love how there is a literal fork in the image.</figcaption></figure><p>You should then see an identical repo — but instead of having a name of <em>prestonlimlianjie/digital-namecard</em> on the top left, the repo will now be <strong><em>[your_username]</em></strong><em>/digital-namecard</em>. In my case, it is <em>preston-test/digital-namecard</em>. You have now created a fork that belongs only to you!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SqKSxATo_Cnofqa3illRIQ.png" /><figcaption>Your newly forked repo!</figcaption></figure><p>Congrats, you’ve created a fork from my repo! Now we only have one last preparatory step before we jump into the code.</p><p><strong>Step 3: Upload your profile picture and company logo</strong></p><p>You will need to prepare a profile picture and company logo — either in .png, or .jpg, or .svg.</p><p>Click on the ‘Upload files’ button on the top right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xNE6djmgPfqSuKvm88uioA.png" /><figcaption>The ‘Upload files’ button can be found on the top-left section of the screen.</figcaption></figure><p>You will arrive at the upload screen. Drag and drop your profile picture and company logo!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-mGuOloaBWcYdSfDqthflw.png" /><figcaption>The upload page.</figcaption></figure><p>My profile picture is <em>user.png</em> and my company logo is <em>icon.png</em>.</p><p>Once the files have been uploaded onto the page, click on the ‘Commit changes’ button to save the files to the repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*30xG88Gjx7eewndgZ011tw.png" /><figcaption>Don’t forget to save!</figcaption></figure><p>You should see your files in the main page of the repo now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0L2fE5sxws2n6ytHMX9TPw.png" /><figcaption>user.png and icon.png can now be found in the repo.</figcaption></figure><p>And now we are ready to dive into the code. But before we do so, let’s take a short detour into how the digital business card works. There are 3 main components:</p><ol><li>The QR code that, once scanned, brings the user to your digital business card website</li><li>The main mobile website displaying the digital business card with your contact information — this is created mainly using HTML.</li><li>The Virtual Contact File (VCF) that will be downloaded from the mobile website and saved into the Contacts app on the phone.</li></ol><p>We will need to make changes to all 3 components in order to make the digital business card your own.</p><p>But let’s take it one step at a time — starting with the HTML.</p><p><strong>Step 4: Edit the HTML</strong></p><blockquote><strong>What is HTML?<br></strong>HyperText Markup Language (HTML) is the language that is responsible for websites.</blockquote><blockquote>When you use a browser (Chrome, Firefox, Safari etc.) to access a website, the browser actually receives HTML — which is a bunch of code. The browser then reads the HTML and creates the visually appealing websites that we are used to seeing.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ct98tAQOj-6icudLfX59aA.png" /><figcaption>Website as a user sees it (left) and the underlying HTML code (right) read by the browser to generate the version of the website seen on the left.</figcaption></figure><p>Let’s start by opening <em>index.html </em>in GitHub. You do this by clicking on the words index.html in the repo.</p><p>You will now see the HTML file in its full glory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N1KIiN5Ah6aRxEH7hyJaZw.png" /><figcaption>Don’t freak out, HTML won’t bite.</figcaption></figure><p>In order to make edits to it, we have to click on the edit button—the one with the pen icon on the top left.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sdQ9WgYdIEM0JGTvb5IQfg.png" /><figcaption>The GitHub editor is ready to use!</figcaption></figure><p>There are a few things that we have to edit in the HTML. I have highlighted the areas in the code that you should replace!</p><blockquote><strong>Note: </strong><br>Most coding languages, including HTML, are pretty particular about syntax. So try your very best to only replace parts of the code that I specify.</blockquote><blockquote>If you do accidentally delete one character too many, keep this rule in mind: code works like a door — if you open something, you have to close it. For example, if there was an opening angular brace <strong>&lt;</strong>, there would have to be a closing one as well <strong>&gt;</strong>.</blockquote><p><strong>The profile picture (<em>preston.jpg</em>) and logo (<em>assets/govtech-logo-blue.svg</em>)</strong></p><p>Replace <strong><em>preston.jpg</em></strong> with the name of your profile picture that you want to use.<br>Replace <strong><em>assets/govtech-logo-blue.svg</em></strong> with the name of your logo file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pz_KzmaaFAJ8j2ZjCIPM_w.png" /><figcaption>Easy peasy!</figcaption></figure><p><strong>The name (<em>Preston Lim</em>), the title (<em>Associate Software Engineer</em>), and the company name (<em>Data Science Division, GovTech</em>)</strong></p><p>Replace <strong><em>Preston Lim</em></strong> with your name. <br>Replace <strong><em>Associate Software Engineer</em></strong> with your title. <br>Replace <strong><em>Data Science Division, GovTech</em></strong> with your company name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fiOl0QFx4XOmCWZcfeUGag.png" /><figcaption>Slowly chugging along!</figcaption></figure><p>Now comes a slightly tricky part. You have to do each of these steps twice. Pay close attention!</p><p><strong>The email address (<em>preston@data.gov.sg</em>), the phone number (<em>+65 9123–4567</em>), the website URL (<em>tech.gov.sg</em>), and the company address (<em>1 Fusionopolis, Sandcrawler, #09–01, 135877)</em></strong></p><p>Replace <strong><em>preston@data.gov.sg</em></strong> with your email address. Do this in the two places highlighted below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p6QoHbjpu5XqYAMfbQ0Eww.png" /><figcaption>Do it twice!</figcaption></figure><p>Replace <strong><em>+6591234567 </em></strong>with your phone number. Do this in the two places highlighted below. (I know they are slightly different, but it doesn’t really matter)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LbZYzhLBibXR8rMmPhqpVA.png" /><figcaption>Twice again!</figcaption></figure><p>Replace<strong> https://www.<em>tech.gov.sg </em></strong>with your website URL. Do this in the two places highlighted below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v1lS7vbZB8OS_Py5yx5z5g.png" /><figcaption>Almost there!</figcaption></figure><p>And now pay close attention. We will replace <strong><em>1 Fusionopolis, Sandcrawler, #09–01, 135877 </em></strong>with your company address (this is the second thing that is highlighted).</p><p>The first highlighted block is the URL to a Google Maps search of your company’s address. What you want to do now is go to Google Maps and enter your company address, and copy and paste the resulting URL. Replace the highlighted block of code with the URL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*chgkTEhZkAXd5loLt8UTSg.png" /><figcaption>Last one I promise!</figcaption></figure><p>Scroll to the bottom of the page and hit ‘Commit change’!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M3v7QnjDxYKLdAERIh6XJg.png" /><figcaption>Yay!</figcaption></figure><p>Now we’re done with editing the HTML!</p><p><strong>Step 5: Create your website using GitHub Pages</strong></p><p>We are now done editing the main mobile website! However, we have a problem — the website currently just sits in the GitHub repo as an HTML file. How do we make it such that the HTML file is shown to anyone who wants to see it?</p><p>We have to host our site.</p><blockquote><strong>What is hosting?<br></strong>Hosting is the process of connecting your HTML files (and hence your website) to the Internet. Your website gets a URL — an address that people can go to on the Internet if they wanted to access your website.</blockquote><p>Thankfully, GitHub has a hosting service called GitHub Pages. Let’s proceed to get our HTML file hosted!</p><p>Let’s click on the Settings button somewhere in the top and center of the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S9DteJesFzT1q_HSlT_bUw.png" /><figcaption>Can you find the Settings button? It’s close to the ‘Watch’ button.</figcaption></figure><p>You should see a page similar to that shown below. Scroll down until you see ‘GitHub Pages’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VOEzmoFt-HIx1pEEzZB4mQ.png" /><figcaption>Settings page of your repo.</figcaption></figure><p>Click on the ‘None’ button in the Source field. You should see a drop down menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9faYIdzJPpbi9CWMEklq3Q.png" /><figcaption>GitHub Pages settings — select Master branch as the Source</figcaption></figure><p>Select ‘master branch’. In doing so, you are telling GitHub pages to turn your repo into a live website!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-gd5Dh21kGEdsLZJSNiZrw.png" /></figure><p>Click on Save. A URL will be generated. This is the URL of your mobile site containing the digital business card.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MMEjlvdGqIvXzCqPzrUGnQ.png" /></figure><p>Click on the URL — you should see a website filled with your contact details!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OBcUTD63vKBt7xY3iJljDQ.png" /><figcaption>Voila!</figcaption></figure><p><strong>Step 6: Edit the VCF</strong></p><p>Now, we proceed to modify the VCF.</p><p>The VCF is the file that is downloaded and saved into the Contacts app when someone clicks on the ‘Download’ button on the website.</p><p>Go back to the main page of the repo. Click on the <em>user.vcf</em> file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eZpFf5LwaO8BK383DUCaCQ.png" /></figure><p>You should arrive at the preview page for the VCF. Click on the edit button (the pen icon at the top right of the page).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BSEzMWcHK1YA0TibX_NZpw.png" /></figure><p>I have highlighted the regions that should be replaced with your contact information. Be very careful not to delete the semi-colons!</p><blockquote><strong>Note on VCF syntax: <br></strong>If you want to insert a newline, you need to add <strong>\n </strong>into the line. <br>If you want to insert a comma, you need to add <strong>\,</strong> into the line.</blockquote><p>Here are the fields that should be edited, and what they stand for:</p><p>N: Name<br>FN: Full Name<br>ORG: Organization<br>TITLE: Job Title (<em>\n</em> is the syntax for a newline)<br>EMAIL: Email Address<br>TEL: Mobile Number<br>item1.ADR: Address<br>item2.URL: Website URL</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g7NVBJlS8ALKOESKGKRnMg.png" /></figure><p>Click the ‘Commit changes’ button to save the VCF!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qz_YzURtfQPMddKBUL8nZA.png" /></figure><p>Now that we’re done with 2 of the 3 major steps — editing the HTML and the VCF — all we have left to do is create the QR code that guides your users to your website!</p><p><strong>Step 6: Create the QR code for your Digital Business Card</strong></p><p>Go to any free QR code generator website — I used <a href="https://www.qr-code-generator.com">qr-code-generator.com</a>.</p><p>Once you are there, enter the URL of your GitHub pages website and generate the QR code. Remember to download it and save it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-5U2TUpCHAZ1BP2H5NUqEA.png" /><figcaption>Generate the QR code specific to your GitHub pages URL</figcaption></figure><p>Now that you have the QR code, give it a scan using your mobile phone. Your digital business card is now ready for use! Take a photo of it, or download it onto your phone/computer.</p><p>Congratulations, you have your very own digital business card! That wasn’t so bad was it? If you found that easy, you might want to take a look at the next optional step below: further customization!</p><p><strong>Step 7 (optional): Make it your own!</strong></p><p>This is for you if you want to go the extra mile and further customize your digital business card. You can change the color of the website by making edits to the <em>main.css</em> file in the same repo — I will leave you to figure this out, and you should use Google to look up the documentation for CSS.</p><blockquote><strong>What is CSS?<br></strong>Cascading Style Sheets or CSS is a language that determines how your HTML website looks.</blockquote><blockquote>Here’s a fun analogy. If a website was a human being, the HTML is the skeletal structure of human, and the CSS is the skin and hair of the human being.</blockquote><p>Just to give you a sense of what can be done: I have made some variations of the digital business card design you see above using a design tool called Figma.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*zq8mEEzu1jSR6f4o8tUDDw.png" /><figcaption>Alternate designs of the website in Figma</figcaption></figure><h3><strong>Closing thoughts</strong></h3><p>Now that you’ve got your digital business card up and running so effortlessly, I challenge you to imagine what else you can build with the same tools!</p><p>Thanks for giving this tutorial a stab! I hope you enjoyed going through the tutorial and got a kick out of creating a personalized digital business card just as much as I did!</p><p><em>If you have any comments or questions, please drop me a message! It’s my first time writing a tutorial, and I’m looking forward to hearing what you guys think!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a26ac400933" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>