Imposing Relation Structure in Language-Model Embeddings Using Contrastive Learning

Christos Theodoropoulos, James Henderson, Andrei Catalin Coman, Marie-Francine Moens

Abstract

Standard pretrained language models often struggle with domain-specific semantic relations. This paper presents a framework that integrates structured relational information into embeddings via contrastive learning. By aligning text representations with graph-based knowledge, the resulting embedding space allows simple classifiers to achieve state-of-the-art performance on biomedical information extraction tasks.

Introduction

Pretrained language models (LMs) like BERT excel at general language tasks but frequently fail to capture high-level semantic relations, such as the link between a drug and its adverse effects. Typically, researchers address this by adding complex neural layers on top of frozen embeddings. However, this "black-box" approach lacks explainability and leaves the underlying representation unchanged. This work proposes a method to "impose" a relation-aware structure directly onto the embedding space, making semantic relationships a fundamental geometric property of the data.

Methodology: Contrastive Learning for Relation Alignment

The proposed framework utilizes CharacterBERT—a BERT variant optimized for medical terminology—combined with Contrastive Learning (CL). The goal is to force the model to produce similar vector representations for a sentence and its corresponding knowledge graph.

Two primary settings were explored:

  1. CLGS (Contrastive Learning Graph-Sentence): Aligns the representation of an entire sentence with a pooled representation of its relation graph.
  2. CLDR (Contrastive Learning Disjoint Relations): A more granular approach that learns to represent specific entity pairs based on their independent relationships in a graph, utilizing a Graph Convolutional Network (GCN).
Architecture of the CLDR framework, showing the alignment between the GCN-processed graph side and the CharacterBERT-processed sentence side.

To effectively teach the model, hard negative sampling was employed. By randomly swapping entities or selecting non-related tokens, the model was trained to push these "negative" representations apart in the embedding space.

Experimental Setup and Datasets

The framework was evaluated on the ADE (Adverse Drug Events) dataset, a biomedical benchmark containing 4,272 sentences annotated with drugs, adverse effects, and their relations. A standard 10-fold cross-validation split was used to ensure robustness.

Key Insights

  • Imposed Structure: Relation understanding can be baked into the output space without altering the core LM architecture.
  • Simplicity in Classification: Once the embedding space is structured, complex neural classifiers are unnecessary. A simple K-Nearest Neighbors (KNN) classifier becomes highly competitive.
  • Granularity Matters: The relation-level approach (CLDR) outperformed the sentence-level approach (CLGS), suggesting that modeling relations independently is a more tractable learning task.
  • Specialized Spaces: The optimal embedding space for Named Entity Recognition (NER) differs from that of Relation Extraction (RE). The authors successfully trained a separate CLNER model to handle entity detection.

Results and Visualization

The "smart" embeddings significantly outperformed baseline models. In a linear classification test, CLDR-tuned embeddings achieved an F1 score of 81.73, compared to the baseline CharacterBERT score of 66.79. Using a transparent KNN classifier, the model reached an RE F1 score of 79.97 and an NER F1 of 88.3.

t-SNE visualization of the learned embedding space, demonstrating distinct clusters for Drugs, Adverse Effects (AE), and non-entity tokens (Outside).

Visualization via t-SNE plots confirms that the model successfully created dense, distinct clusters for different entity and relation types, validating the effectiveness of the contrastive alignment.

Conclusion and Future Work

This research demonstrates that contrastive learning can effectively bridge the gap between unstructured text and structured knowledge graphs. While NER performance (88.3 F1) remains slightly behind some specialized models like SpERT (89.25 F1), the gains in relation extraction and model transparency are significant. Future work includes exploring continual learning to keep models updated with evolving medical knowledge and utilizing larger external knowledge graphs during training.

Summary updated

BibTeX
@inproceedings{theodoropoulos2021imposing,
  author = {Christos Theodoropoulos and James Henderson and Andrei Catalin Coman and Marie-Francine Moens},
  title = {{Imposing Relation Structure in Language-Model Embeddings Using Contrastive Learning}},
  booktitle = {CoNLL},
  year = {2021},
  doi = {10.18653/v1/2021.conll-1.27},
}
Figure