Tired of ads? Enjoy an ad-free experience by signing up.
Jiayu Yi · · 7 min read

How do people feel about the recent Lee Hsien Loong issue? We used code to find out

Photo credit: The Straits Times.

It was an eventful morning in Singapore yesterday.

Here are just some of the headlines:

But what do the people think?

We tried to gauge the public’s response to these statements based on Facebook comments. To do this, we used:

  • Python 3
  • The Facebook Graph API to download comments from Facebook
  • The Google Cloud Natural Language API to perform sentiment analysis

First, we downloaded the comments from a Facebook post using the Facebook Graph API. For this project, we used this post on Lee Hsien Loong’s (LHL) Facebook page responding to his siblings’ statements.

The approach we used can be easily adapted to any post on a public Facebook page, like Lee Hsien Yang’s original post, for example.

We then used the Google Cloud Natural Language API to classify the comments on these posts as either positive, neutral, or negative and calculated the proportion of these comments on each of these posts.

Important note

Facebook is by no means a source of objective views. It is extremely likely that the comments we found on these posts are biased to some degree.

There is also the possibility of moderation, further reducing the objectivity of our findings. This article should be taken purely as an exercise in using the Facebook Graph API and Google Cloud Natural Language API, and not to draw any conclusions about Singapore’s political situation.

Getting started

Setting up Python 3

I won’t discuss here how to download and install Python 3. You can consult the Python documentation here. But just to check your Python version, open your Python prompt and inspect its output. You should see something similar to:

Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

Downloading Facebook comments

Analyzing the comment sentiments

Conclusion

Stay ahead in Asia’s tech landscape

You've reached your 2 free content limit for the month. Sign up for free to read the full story.

🏄 For casual readers / 👶 Free

Basic

US$0

Free forever

Get instant access to this article and more every month

0 premium content

Unlimited news briefs

5

5 articles

Ad-free reading experience

Just US$0 per day

⌛Sign up in 20s. No payment details needed.

📖 For learners / 👍 Starter

Lite

US$4.92/month

Billed annually at US$59/year

Get instant access to this article and more every month

4

4 premium content

Unlimited news briefs & articles

Ad-free reading experience

Just US$0.17 per day

Cancel anytime

Our subscriber community includes professionals from these companies:

Stay updated on the go with our mobile app.

Get latest insights with smoother, more personalized experience through TIA mobile app.

Community Writer

Jiayu Yi