Junyuan Shang, Tengfei Ma, Cao Xiao, Jimeng Sun
9 min
Medication recommendation is a critical task in healthcare, typically framed as predicting appropriate drug combinations based on a patient's longitudinal health history. However, existing deep learning approaches suffer from two major limitations: selection bias, where patients with only a single visit are excluded from training, and a failure to incorporate the hierarchical structure of medical codes (such as diagnosis and medication ontologies).
To address these issues, the authors propose G-BERT, which integrates Graph Neural Networks (GNNs) with the BERT architecture. The method operates in three stages:
By adapting language model pre-training to the healthcare domain, G-BERT effectively mitigates selection bias. The study demonstrates that G-BERT achieves state-of-the-art performance on medication recommendation, outperforming established baselines such as RETAIN and GAMENet across metrics like Jaccard similarity and F1 score. This work highlights the value of transferring large-scale language modeling techniques and graph-based knowledge to clinical predictive tasks.
Medication recommendation is an important healthcare application. It is commonly formulated as a temporal prediction task. Hence, most existing works only utilize longitudinal electronic health records (EHRs) from a small number of patients with multiple visits ignoring a large number of patients with a single visit (selection bias). Moreover, important hierarchical knowledge such as diagnosis hierarchy is not leveraged in the representation learning process. Despite the success of deep learning techniques in computational phenotyping, most previous approaches have two limitations: task-oriented representation and ignoring hierarchies of medical codes. To address these challenges, we propose G-BERT, a new model to combine the power of Graph Neural Networks (GNNs) and BERT (Bidirectional Encoder Representations from Transformers) for medical code representation and medication recommendation. We use GNNs to represent the internal hierarchical structures of medical codes. Then we integrate the GNN representation into a transformer-based visit encoder and pre-train it on EHR data from patients only with a single visit. The pre-trained visit encoder and representation are then fine-tuned for downstream predictive tasks on longitudinal EHRs from patients with multiple visits. G-BERT is the first to bring the language model pre-training schema into the healthcare domain and it achieved state-of-the-art performance on the medication recommendation task.
Sam: They add medical ontologies: structured classifications of medical concepts. The diagnosis tree, for example, places congestive heart failure and left heart failure beneath heart failure. The model can use those relationships rather than treating every diagnosis as an unrelated label.
Alex: How does a classification tree actually influence the representation? Simply giving related diagnoses similar names would not do it.
Sam: The authors use a graph neural network, which shares information between connected nodes. First, broader categories collect information from their direct children. Then the specific medical codes collect information from their ancestors. Learned attention weights determine how much different connected nodes contribute.
Alex: So those heart failure diagnoses can share information through their broader category, while keeping separate representations.
Sam: That is the intended mechanism. The same design also uses a medication classification tree. The resulting code representations become inputs to the visit encoder, the part that summarizes the codes recorded during a visit.
Alex: Was using medical hierarchies itself new here, or is the novelty in how the pieces fit together?
Sam: Earlier work called GRAM already combined medical concepts with their ancestors using attention. G-BERT differs by updating both ancestor and specific-code representations through its graph procedure. It then combines that procedure with pre-training a Transformer, an encoder that uses attention between inputs.
Alex: Transformers were developed for ordered inputs. A list of diagnoses does not necessarily have a meaningful first or last item. How do the authors handle that?
Sam: They remove position information within a visit. Unlike words in a sentence, the medical codes here are treated as an unordered set. A special summary token collects the information used to represent that visit.
Alex: And what does pre-training ask that summary to preserve? That seems more consequential than simply borrowing a familiar architecture.
Sam: There are two tasks. Self-prediction reconstructs the original codes of the same type from the visit summary. The authors randomly mask fifteen percent of input codes, so the encoder must learn from the remaining context.
Alex: Reconstructing diagnoses teaches the model what is in the visit. How does it learn the relationship to medication prediction?
Sam: Through dual-prediction, the other task. A diagnosis summary predicts the visit’s medications, while a medication summary predicts its diagnoses. This replaces BERT’s original next-sentence prediction task with a relationship relevant to these records.
Alex: Then the final predictor has to bring time back in. Does it model the entire patient history with another elaborate sequence model?
Sam: No. It averages earlier diagnosis summaries and earlier medication summaries separately. It combines those averages with the current diagnosis summary to predict a set of medications. That means the historical aggregation does not preserve the detailed ordering of earlier visits.
Alex: Let’s test the payoff. What data did they use, and what counts as success?
Sam: They used MIMIC-III, an electronic health record dataset, with separate training, validation, and test groups. Success means matching recorded medication sets for multi-visit patients. They measured set overlap, a precision-and-recall summary, and performance across prediction thresholds.
Alex: Set overlap is the easiest to picture. How much better was G-BERT than the strongest previous model?
Sam: Its Jaccard similarity—shared medications divided by all distinct medications in the predicted and recorded sets—was about forty-six percent. It exceeded full GAMENet by just a tenth of a percentage point. So the leading overlap scores were very close.
Alex: That sounds like a narrow win, not a decisive separation. Did the other measures point the same way?
Sam: G-BERT led on all the reported prediction measures, but its advantage over full GAMENet was modest. The paper also reports no uncertainty estimates for these comparisons. I would read the ranking as promising, not as proof of reliable superiority across settings.
Alex: Can the authors show that the graph and pre-training actually contribute, rather than crediting the whole architecture at once?
Sam: They remove each component in turn. Either pre-training alone or ontology information alone improves over the version using neither. Combining both produces the strongest G-BERT variant, which supports the combined design within this experiment.
Alex: GAMENet uses graphs too. Is that comparison testing the same kind of medical knowledge?
Sam: No. GAMENet uses drug interaction graphs, rather than these medical classification trees. The authors compare against a stripped-down version and the full model. Full GAMENet has additional drug interaction and procedure information, yet G-BERT still scores slightly higher on prescription prediction.
Alex: But predicting what was prescribed is not the same as showing what should have been prescribed. Where does that leave the clinical claim?
Sam: At prediction, not demonstrated clinical benefit. This study does not establish safer medication combinations or improved patient outcomes. It also uses one dataset, so performance elsewhere remains untested.
Alex: And including single-visit patients during pre-training does not establish that selection bias has disappeared.
Sam: It addresses their exclusion from representation learning. The paper does not show that the resulting model represents every patient group better. Nor does its multi-visit evaluation establish recommendation performance for single-visit patients.
Alex: Given those boundaries, who should read the full document, and where should they start?
Sam: Researchers building medication recommenders or learning representations from structured health records should read it. Start with the pre-training section, then the results comparing versions with and without each component. For implementation, notice that the reported training alternates pre-training and fine-tuning, rather than finishing one permanently before starting the other.
Alex: And what should everyone else remember when deciding which records belong in a training pipeline?
Sam: A record that cannot teach the final task may still teach the representation. Here, that idea helps recover excluded data, with a modest prediction gain—not yet evidence of better care.
Alex: A useful distinction to carry back to your own data.