Hello

Your subscription is almost coming to an end. Don’t miss out on the great content on Nation.Africa

Ready to continue your informative journey with us?

Hello

Your premium access has ended, but the best of Nation.Africa is still within reach. Renew now to unlock exclusive stories and in-depth features.

Reclaim your full access. Click below to renew.

Kenyan data scientist builds AI tool to detect mental health crises hidden in social media posts

Diana Opiyo, a Kenyan machine learning engineer and data scientist, and founder of MingGuard AI.

Photo credit: Pool

What you need to know:

  • Common mental disorders affect at least one in 10 Kenyans overall, accounting for roughly 13 per cent of the country's total disease burden.
  • Depression and anxiety remain the most frequently diagnosed conditions, closely followed by substance use disorders, again concentrated among 18-to-29-year-olds.

In March 2020, as Kenya recorded its first Covid-19 case and curfews emptied the streets, data scientist Diana Opiyo noticed something happening on people's social media timelines that nobody else seemed to be tracking: an outpouring of grief, job loss, and quiet desperation, written in public by people who would never say the words out loud.

"People who had never spoken publicly about their own lives began writing posts on social media. Jokes that were not really jokes. Long posts about a business that had folded. Short ones, from accounts that then went silent for weeks," Diana says.

Kenya's own reckoning came quickly. On July 7, 2020, a taskforce chaired by Dr Frank Njenga, then serving as presidential advisor on mental health, recommended to the Ministry of Health that mental illness be declared a national emergency of epidemic proportions. The taskforce had found that depression, anxiety, and substance use disorders, particularly alcohol abuse among 18-to-29-year-olds, were rising sharply. It also recommended creating a Mental Health and Happiness Commission to monitor national wellbeing annually, and removing criminal penalties for suicide attempts to reduce stigma and encourage people to seek help.

"The distress was documented in real time, by the people experiencing it, in their own words. And almost nobody was reading it," Diana tells Healthy Nation.

The scale of what the taskforce was responding to has only grown starker since. Ministry of Health figures show that between 10.3 and 25 per cent of the population experiences a mental health condition, meaning as many as one in four patients seeking routine outpatient care is actually battling a mental illness. The crisis is heavily concentrated among the young, with 44 per cent of adolescents in Kenya reporting mental health challenges.

Common mental disorders affect at least one in 10 Kenyans overall, accounting for roughly 13 per cent of the country's total disease burden. Depression and anxiety remain the most frequently diagnosed conditions, closely followed by substance use disorders, again concentrated among 18-to-29-year-olds. As much as 75 per cent of these cases go untreated, a gap driven by a severe shortage of registered psychiatrists and limited specialised training for primary healthcare workers.

Financial distress, unemployment, and high-stress public-sector work have contributed to spikes in depression and suicide among civil servants and uniformed officers. The Ministry's Mental Health Investment Case put the annual cost to the Kenyan economy, in lost productivity and healthcare spending, at Sh62.2 billion.

Six years after Diana's observation, her idea has become MindGuard AI, a deployed system that screens social media posting histories for patterns of psychological distress and suicidal ideation, and routes flagged cases to trained counsellors. Earlier this year, the project was named runner-up in the Emerging Ideas Track at the Grand Rapids DeepTech Pitch Competition in Michigan, United States, winning $600 in seed funding. It had previously taken Best 

Overall Project at Grand Valley State University's College of Computing Innovation Day.

Diana, a machine learning engineer and data scientist who taught statistics and mathematics at the Technical University of Mombasa for more than four years, says the disconnect stayed with her: the distress was being recorded in real time, and almost nobody was reading it in order.

MindGuard connects to nine social media platforms, including Facebook, X, Reddit, YouTube, TikTok, Bluesky, and Mastodon. With a user's consent, it pulls up to six months of their public posting history. Each post is then scored individually by a fine-tuned language model built on Mental-RoBERTa, a transformer trained to recognise linguistic patterns associated with psychological distress.

Diana says the model reached 92.5 per cent accuracy and a 0.9813 ROC-AUC score in evaluation, meaning it has exceptional predictive performance. She was careful to frame the figures as preliminary. "They are research results measured on test data. They are not clinical validation, which is a separate and more demanding process still ahead of us," she notes.

What distinguishes the tool from a simple keyword alert, Diana says, is that it looks for a trajectory rather than a single alarming post.

"We are not asking whether someone wrote something alarming yesterday. We are asking what direction the last six months have been travelling. When a pattern crosses a set threshold, the case is routed to a trained counsellor who reviews the timeline before deciding whether and how to reach out," she says.

"The tool screens; it does not diagnose. It never contacts a person directly about a flag. The algorithm's job ends where the conversation begins. MindGuard is not designed for schools or universities alone. It is for any adult in this country who uses social media and wants a second pair of eyes on their own words, or a friend's, or a colleague's, or a relative's."

She argues that the approach reflects a structural gap in Kenyan mental healthcare. The World Health Organization Kenya 29th globally for suicide mortality, and the country's own mental health policy estimates that between 20 and 25 per cent of outpatients at primary healthcare facilities show symptoms of mental illness.

"Kenya's mental health gap is not going to be closed by building enough hospitals or training enough psychiatrists in the next decade. The arithmetic does not work," she says.

Diana says the system is already running, but two things are deliberately slow-going: securing user consent at a national scale, and building partnerships with Kenyan counsellors and helpline services that would make deployment real.

"We are currently in the final stages, then we get into the piloting stage. We have no counselling partners yet, and we are open to more funding. There are plans to train the model on Sheng in phase two of the training. We are currently finalising phase one for the English language," she notes.