Skip to content
2019 Independent · AI & automation

Open Darija: sentiment analysis for Moroccan Arabic

NLP tools for Arabic in 2019 covered Modern Standard Arabic, not Darija, the dialect Moroccans actually write online. We built a crowdsourced dictionary of word sentiment for Darija, and a platform that collects public posts, analyses them and shows what a profile talks about and how it feels.

Role
Co-founder and developer, in a team of two
When
April 2018 – June 2019
The Java core's master service runs each step. A profile that's already been analysed goes straight to MongoDB. Request profile to Collect posts (new); Collect posts to Structure; Structure to Analyse; Structure to MongoDB; Open Darija to Analyse (lexicon); Analyse to MongoDB (results); Request profile to MongoDB (already analysed); MongoDB to Explore (JSON) new lexicon results already analysed JSON Request profile F-Analyzer · React Collect posts Python · Selenium Structure files → documents Open Darija dictionary API Analyse NLP · 7 sentiments MongoDB profiles, posts Explore F-Analyzer charts
The Java core's master service runs each step. A profile that's already been analysed goes straight to MongoDB.

The problem

Moroccans write online in Darija. It mixes Arabic, Amazigh, French and Spanish, has no fixed spelling or grammar, and is written in Arabic letters or in Latin letters with digits standing in for Arabic sounds (“3” for ع, “7” for ح). The NLP tools we could use, like NLTK, Farasa or Naftawayh, handled English, French or Modern Standard Arabic. None of them understood a Darija comment.

And no dataset existed that said whether a Darija word is positive, negative or angry.

Open Darija dictionary

We started Open Darija in April 2018 to build that dataset ourselves. It was a website with two sides:

The Open Darija form: a visitor rates the word شوية with positivity and negativity sliders and picks its sentimentsThe visitor form: rate the word’s polarity, tick its sentiments, add a description or a correction.

The platform also served the dictionaries through an API, so any program could ask for the latest version instead of keeping a stale local copy.

Processing Darija text

On top of the dictionary we wrote our own processing steps for Darija:

  1. Detect the script. Text in Latin letters is transliterated into Arabic using a letter mapping table, so both forms go through the same pipeline.
  2. Turn emojis into words, because an angry face is often the clearest sentiment in a comment.
  3. Shorten stretched words back to their normal form, like “bzzzzaf” to “bzaf”.
  4. Clean digits, punctuation and leftover Latin characters.
  5. Tokenise, drop stop words and stem, so plurals, feminine forms and conjugated verbs match the root word in the dictionary.

What’s left is classified by topic and by sentiment, either with a simple lexicon approach that counts which classes the words belong to, or with a trained classifier (SVM or Bayesian) that uses the same lexicon as features. The sentiment analysis covers seven sentiments.

The platform around it

We applied this to public Facebook profiles. Only posts visible to everyone were collected, and only their text was analysed. The system had four applications and one database:

Architecture of the project: the Facebook scraper, the Java core with its database, structuring, analysing and scraping services behind a master service and a REST API, the Open Darija dictionaries, the MongoDB database and the React Facebook AnalyzerThe architecture from the 2019 project report: four applications and one database.

The Java core, layer by layer

The core was a Spring application with a REST API in front and a set of services behind it, each with one job:

A request for a new profile goes through the whole chain: collect, structure, analyse, store, return. A request for a profile that’s already been analysed goes straight to the data access layer and back.

What I took from it

This was one of my first data project, before I called it data engineering. Most of what I still care about was already in it: getting messy text into a shape you can work with, splitting a system into parts that each do one thing, and keeping the data access in one place.

It also came back seven years later. Open Barlaman works on Arabic text again, this time with OCR and LLMs instead of hand-built stemming rules.