Using Natural Language Processing (NLP) to Analyze Social Media Posts by Local Politicians

If you are a social media active person, you may understand how highly impactful social media content can be in creating visibility in audiences’ minds. You could post texts, do live videos, share posts, and much other social media content with your friends and followers. As all this occurs quite frequently as a normal part of daily living for most people, tens of thousands of data are generated in the process. Analyzing text data can be valuable in providing meanings to the opinion of people and organizations. And this is exactly what Natural Language Processing (NLP) is developed to do. NLP simply uses computers to understand human language by extracting and analyzing text to provide insight into the meaning of those texts.

Quite recently, I came across a python script that uses NLP to analyze and visualizes Donald Trump’s Tweets. Being curious to explore what such analysis would make of social media texts by local politicians, I replicated the project but instead of using Twitter, I used Facebook. I used python and NLP and related packages to extract Facebook posts from Sierra Leone’s State House and Mayor of Freetown. The textual data were scrapped, analyzed, and visualized to reveal top words, top organizations, and top people mentioned in thousands of social media texts posted on Facebook by the State House and Mayor of Freetown.

Analysis — Facebook Posts(texts) by State House, Sierra Leone

Analysis on State House, Sierra Leone, Facebook post reveled top words to be: “Presid”, “bio” , “maada”, “Sierra” “Leon”, “govern”, and “contri” “develop”, “support”,” excel”, “educ” and “new” etc.

NLP was also used to extract the top organizations and people mentioned in social media posts. State House has mentioned top organizations such as the UN, Millennium Challenge Corporation (MCC), EU, RSLAF, and others. The top people mentioned are Maada Bio, Fatima Maada Bio, Dr. Mohamed Juldeh Jalloh, Jacob Jusu Saffa, David Sengeh, etc.

Image by Author
Image by Author

Analysis — Facebook Posts(texts) by Freetown Mayor

Similarly, for the Mayor of Freetown’s posts, top words mentioned are: “Freetown”, “Mayor”, “citi”, “tree”, “transform”, “wast”, “climat”. Additionally, top organizations mentioned by the mayor are the Ministry of Finance, the World Bank, AYV, European Union, Ministry of Lands, etc. While top people mentioned are Yvonne AkiSawyyer, Al Gore, Michael Bloomberg, Ms. Sonia Gardner, Yemi Alade, etc.

Image by Author
Image by Author

One can easily look at the visualization of top words to get some insights about Sierra Leone’s State House and Freetown’s Mayor interest areas, respectively. For example, State House Sierra Leone likes to use the word “said” often. This can tell us without going through every Facebook post that State House frequently quotes speakers during events in their Facebook posts. And the root word of education “Edu” can provide insight into the Sierra Leone President’s interest in education. For the Mayor, her top words reveal the mayor’s interest in climate, trees, plants, cleanliness, waste, and transforming Freetown. For both social media accounts, by looking at the range `of top organizations mentioned, like the European Union (EU), the World Bank, and the Millennium Challenge Corporation (MCC), one can tell that both leaders are meeting frequently with donor agencies.

Overall, using python and NLP libraries as applied to text extraction and analysis is not perfect(You may have spotted some out of place words in the above text categorization). It can make mistakes but it can be trained to improve every time in the categorization of texts through further data cleaning procedures.

Nonetheless, the use of NLP is crucial in today’s media world which is sadly inundated with loads of disinformation, misinformation, and hate speech. And as we have increasing internet penetration, cheaper smartphones, and more social media users in Sierra Leone and Africa, there can be no better time to ethically use NLP to analyze texts from websites, blogs, social media, political party manifestos, newspapers, and acquire meaningful insights. Information derived from texts could enable us to quickly identify and dispel fake news, categorize elements of hate speech, and even hold our leaders accountable to fulfill key manifesto pledges.

Code on my Github page.

Leonard Francis Vibbi is a civic technologist and design researcher working in West Africa.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store