Diabetes is an epidemic. More than 100 million Americans live with diabetes or prediabetes, according to a recent report by the Centers for Disease Control and Prevention (CDC), and about 1.4 million new cases are diagnosed every year. Medical advances have made coping with diabetes easier, but patients who don’t stay on top of their blood glucose levels put themselves at risk of unconsciousness, coma, and even death.

There’s good news, though: Researchers have developed an artificially intelligent (AI) system that can predict future blood glucose levels before hyperglycemia (very high blood sugar) or hypoglycemia (very low blood sugar) occur.

In a paper published on the preprint server Arxiv.org (“Predicting Blood Glucose with an LSTM and Bi-LSTM Based Deep Neural Network“), they describe a recurrent neural network with a bi-directional long short-term memory (LSTM) that’s capable of learning long-term dependencies. Basically, the memory cells in LSTMs allow the neural network to combine its memory and inputs, improving prediction accuracy. And because it’s bidirectional, it can access context from both past and future directions, expediting training time.

The team tested their model on 26 datasets from 20 patients (all of whom had lived with diabetes for more than 10 years), in addition to glucose measurements from 11 virtual adult patients created using a simulator. The LSTM outperformed baseline methods, and better yet could be used for patients with oral drugs, insulin pens, or an insulin pump “[because] it only [required] CGM (continuous glucose monitoring) measurements.”

In the next phase of research, the team plans to “include more features” to improve the model’s performance and add an “alarm mechanism” to detect upcoming hyper- and hypoglycemic events.

This study’s sample size was quite small, but it’s not the first time researchers have tapped machine learning to make predictions about diabetes.

Beijing-based 4 Paradigm created a model that’s 88 percent accurate at detecting the likelihood a patient will develop diabetes within 15 years. Klick Health developed algorithms to predict blood glucose levels 30 minutes into the future. And One Drop, a biomedical company that produces blood glucose monitoring systems compatible with the Apple Watch, recently introduced a feature that forecasts glucose values over time and provides behavioral recommendations.

Apps like Sweetch are taking a different approach, using AI to encourage diabetic users to stay active and stick to diet goals. In a March study conducted by Johns Hopkins University’s division of endocrinology, diabetes, and metabolism, Sweetch’s recommendations were shown to significantly lower blood sugar levels.