Categories
data python tools

Swahili text normalizer

One of the challenges with working with text corpus, that will be used for voice datasets, is that you will encounter non-standard text like percentages, numbers, time and date. These can be a challenge when one has to read them. For example 23 could be read as twenty three or two three. To fix such an issue you do what is called text normalization during the cleaning and validation stage for your text corpus. This is helpful especially when your text corpus will be used for speech use cases.

Text normalization in speech applications converts written, non-standard text (like numbers, symbols, and abbreviations) into spoken-word forms for text-to-speech (TTS), or structures raw audio transcripts into clean data for automatic speech recognition (ASR)

During my fellowship with Mozilla Foundation working on the common voice text corpus for Kiswahili, this is something I encountered during the sentence validation stage. On the common voice platform, one way one can contribute to building the Swahili voice dataset is to read sentences in the Swahili language. The sentences went through a validation stage before they were ready for reading. You can see that encountering something like 3.5% might slow the reader (silence in the voice clip making it longer) or present a challenge of how to read the percentage. For English you can use already existing natural language processing tools to do text normalization.

I spent some time working on a small library for the Swahili language. Its a small collection of utilities that convert:

  • Numbers to words (0 .. < 1e9)
  • Years, dates, times to words
  • Decimals, percentages to words

You can find the source code here https://github.com/bmwasaru/kiswahili-text-normalizer and the readme file has instructions on how to install and use it. Here is an example usage:


>>> import kiswahili_text_normalizer as ktn
>>> text = "Tutakutane 20/11/2025 14:30, malipo ni 12.5%."
>>> print(ktn.normalize_text(text, profile="asr"))
tutakutane tarehe ishirini mwezi wa kumi na moja mwaka elfu mbili ishirini na tano 
saa nane na nusu malipo ni asilimia kumi na mbili nukta tano

As you can see it converts

  • 20/11/2025 to tarehe ishirini mwezi wa kumi na moja mwaka elfu mbili ishirini na tano
  • 14:30 to saa nane na nusu
  • 12.5% asilimia kumi na mbili nukta tano

You will note it adds keywords like tarehe to denote date, saa to denote time, nukta to denote decimal point and asilimia to denote percentage.

I have used this on text that I had scrapped from the Voice of America Swahili news website before it shutdown. The code for that can be found here https://github.com/bmwasaru/voa/blob/main/scripts/normalize_text.py. This was a perfect use case because this was a large text corpus and the normalizer was able to quickly find and convert. Side note, if you are looking for Swahili language text you can find the scraped text in cvs files here https://github.com/bmwasaru/voa/tree/main/sentences.

I hope one finds this useful and please share some feedback 🙂

Categories
data TILs

Collaborative Filtering

This is a technique used in recommendations systems to predict preferences of a user by collecting preferences from many users.

There are 2 types:

  1. user based collaborative filtering – finds users who are similar to the target user based on their past interactions (e.g., ratings or purchases) and recommends items that these similar users liked
  2. item based collaborative filtering – looks at the similarity between items based on users’ past behavior. It recommends items that are similar to what the target user has liked in the past

Here is code. Its scrollable 🙂

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

You can find the Jupyter notebook here https://github.com/bmwasaru/collaborative_filtering/blob/main/collaborative_filtering.ipynb

Leave me a comment, I like feedback 🙂

Categories
data readings

Living in Data by Jer Thorp

Living in Data by Jer Thorp

Jer Thorp, an artist and technologist goes through a number of stories and personal experiences on the complexities of how data influences and shapes our society.

He examines the ways in which data collection, interpretation, and usage affect individual privacy, public policy, and global systems. We are challenged to reconsider our relationship with data, advocating for a more informed and active participation in data governance. There is need for a future where we use data ethically and equitably.

The use of his technical and storytelling skills and analysis makes the book worth a read.

Categories
data

Learning how to visualize data

Here is a first looking at Kenya’s debt over time. Data is from there https://www.centralbank.go.ke/public-debt/

Categories
data

visualization of sea level according to temperature increase

Found some data on sea level changes in relation to temperate increase in the coastal cities of Durban, Cape Town, Lagos, Mombasa and Dar es Salaam. I was able to create a visualization of this data as seen below.

Note this data is from 2017, should I find any recent data I will be able to update. For a more interactive view please click https://www.datawrapper.de/_/9vfPX/