When it comes to black boxes, there is none more black than the human brain. Our gray matter is so complex, scientists lament, that it can’t quite understand itself.

But if we can’t grok our own brains, maybe the machines can do it for us. In the latest issue of Nature Communications, researchers led by University of Pennsylvania psychologist Michael Kahana show that machine learning algorithms—notoriously inscrutable systems themselves—can be used to decode and then enhance human memory. How? By triggering the delivery of precisely timed pulses of electricity to the brain.

Researchers, in other words, can use one black box to unlock the potential of another. Which on one hand sounds like a rather elegant solution to an absurdly difficult problem, and on the other sounds like the beginning of a techno-pocalypse horror flick.

When it comes to brain measurements, the best recordings come from inside the cranium. But people—and institutional review boards—aren’t usually amenable to cracking open skulls in the name of science. So Kahana and his colleagues collaborated with 25 epilepsy patients, each of whom had between 100 and 200 electrodes implanted in their brain (to monitor seizure-related electrical activity). Kahana and his team piggybacked on those implants, using the electrodes to record high-resolution brain activity during memory tasks.

Machine learning algorithms learned to associate patterns of electrode measurements with a patients' likelihood of memorizing a word. Kahana et al.

First, the researchers got a sense of what it looks like when a brain memorizes stuff. As the patients read and attempted to internalize lists of words, Kahana and his team gathered thousands of voltage measurements per second from each of the implanted electrodes. Later, they tested the patients’ recall—building up data about which brain activity patterns were associated with remembering a word vs. forgetting it.

Then they did it again. And again. After two or three visits with each test subject, they'd collected enough training data to produce patient-specific algorithms that could predict which words each patient would likely remember—based on their electrode activity alone.

Here’s the kicker. These electrodes don’t just read neural activity; they can stimulate it, too. So the researchers tried prodding the brain to improve—or, as they put it, "rescue"—the formation of memories in real time. Every few seconds, the subject would see a new word, and the newly trained algorithm would decide whether the brain was ready to remember it. “A closed loop system lets us record the state of the subject's brain, analyze it, and decide whether to trigger a stimulation, all in a few hundred milliseconds," Kahana says.