Artificial intelligence is the future. It can predict when we’ll die, help us buy stuff we don’t need, diagnose cancer, and imperfectly predict songs we’d like. It’s not perfect, and sometimes it can be banal.

That’s changing, though, and in a surprising space—mental health. Before machine learning directs our autonomous vehicles, it could help humans deal with psychological challenges.

The mental health space already has a few apps using AI to help people conquer their psychological health. Ginger.io uses AI along with trained therapists to suggest mental health treatments that include cognitive behavioral therapy, mindfulness/meditation, or talk therapy—a boon for those who live in rural areas far from resources and can be an easier “way in” to oft-stigmatized mental health care.

Companion is an app funded by the Defense Advanced Research Projects Agency and U.S. Department of Veterans Affairs. It “continuously and passively monitors psychological health and well-being using built-in mobile sensors and survey questions,” according to the app’s site. Basically, it listens in on conversations—but the application’s not so interested in what’s said as to how it’s said. The app looks for changes in the user’s voice—in pitch, inflection, and other factors. It also keeps track of how much a user talks and how often. Put together, these details can indicate mental health conditions and identify those who are at-risk.

And then there’s Sober Grid, which debuted in July 2015 and has since grown to over 120,000 users. The free app offers social-media tools to connect people with resources and other people. “Roughly half our members are in earlier stages of recovery [from drug and/or alcohol addiction] or trying to find recovery. They are using the app to find support,” said Chris Pesce, COO of Sober Grid. “The other half our users are in longer-term recovery—they use the app to offer support to others, and that’s beneficial to them to maintain their own program.” This virtuous circle forms the backbone of the app and has led to its popularity in the sober community—but what if it could do more?

Relapse is the biggest challenge to addicts in recovery, and the Sober Grid team knew via anecdotal stories that sometimes their app helped people avoid using again. They also had a lot of data from their user base, including when, how often, and what people communicated before a relapse. They also knew exactly when relapses happened—people would restart counting their days of sobriety on the app after they used, so it was obvious.

If that data was run through the right algorithm, could you work backward to predict relapse? The team worked with Dr. Brenda Curtis at the University of Pennsylvania Perelman School of Medicine to test this hypothesis.

The answer was yes—relapses could be predicted using AI, which meant future relapses could potentially be prevented: “Our goal is to use this information to be able to intervene when a relapse risk is elevated,” said Curtis.

Eventually, about 100,000 people’s data—all deidentified—was used in the Phase I research. None of the information can be traced to any particular person: “We worked with the internal review board at the University of Pennsylvania, and followed their best practices,” Pesce said.

The relapse predictions are based on language used by the app’s users: “The words people use reflect who they are (e.g. their personality) and how they feel (e.g. happy, depressed, stressed, relaxed). People using Sober Grid post messages and indicate the number of days they have been sober. We then build statistical models to predict sobriety or relapse from the frequencies with which words are used,” Lyle Ungar, a professor of Computer and Information Science at the University of Pennsylvania and a co-investigator on the project, told The Daily Beast.

“We are finding the best predictive models relate to discussions regarding substance use and negative emotions,” Curtis said. Timing of posts, curse words, and other details also give away impending relapse.

Once the algorithm has predicted a relapse, then what? Send in the support: There are tools that addiction specialists already know work to prevent someone who is on the cusp of relapse from using. Some of those can be delivered digitally, Pesce said. “Short mindfulness modules or cognitive-behavioral therapy can help a person cope with relapse feelings and deescalate the situation,” he said. Or maybe even telehelp-based certified coaching, if that’s something the person has opted into as part of their recovery plan. When the signs of relapse crop up, AI could direct the addict to trained coaches available 24/7, which means the patient doesn’t have to wait over a long weekend or holiday for services to become available. These options would all be opt-in, stressed Pesce, so app-users get only the kind of help they sign up for—no surprises.

There’s more than just predicting relapse and addressing it in situ: “For me, the interesting thing is… identifying the potential drivers of relapse for different people. Can we use statistical models to identify, for a given person, what is happening in their lives that warns about possible relapse—or that suggests healthy recovery?” Ungar asked.

Using AI in this way—to personalize addiction treatment—would be the natural extension of the predictive technology. Pesce gave the example of how a young woman on the East Coast dealing with depression and opioid addiction might benefit from a different type of treatment than a middle-aged man in California who is an alcoholic. In this way, each user could get the best treatment based on their personality and what their addiction challenges are.

On the strength of the Phase I trials funded by both the National Institutes of Health and the National Science Foundation, Sober Grid’s Phase II research is moving forward (they're looking to get funding for this stage). Getting money from both organizations is almost unheard of.

Sober Grid is moving forward quickly, keeping in mind that they always want to keep their core product—the networking aspect of the app that allows people to reach out to others in the community day or night—completely free. In addition to their grant funding, they are now seeking conversations with payers, public and private alike, who will pilot this technology with their patients and customers. “As a company, obviously, we need to generate revenue. By lowering relapse rates, we can save those who are bearing the financial costs of addiction a tremendous amount of money,” said Pesce.

Sober Grid wants to get this technology out as soon as they can. They’re looking to roll out the telehealth peer coaching in the next six months, and want to release the relapse-prediction option and intervention within a year. “Addiction is a chronic disease and one expects relapse to happen,” Curtis said, pointing out that being realistic about relapse and treating it via intervention is key to long-term success for addicts in recovery.

The goal of many in health care is to stop diseases in the early stages, or prevent them; that’s what pre-cancer screenings and genetic testing is all about. When it comes to mental health care, AI can do something similar—see what’s going to happen before it does, so we can treat it.