GiBERT: Introducing Linguistic Knowledge into BERT through a Lightweight Gated Injection Method

Nicole Peinelt, Marek Rei, Maria LiakataarXiv 2020

Abstract

Large pre-trained language models such as BERT have been the driving force behind recent improvements across many NLP tasks. However, BERT is only trained to predict missing words—either behind masks or in the next sentence—and has no knowledge of lexical, syntactic, or semantic information beyond what it picks up through unsupervised pre-training. We propose a novel method to explicitly inject linguistic knowledge in the form of word embeddings into any layer of a pre-trained BERT. Our performance improvements on multiple semantic similarity datasets when injecting dependency-based and counter-fitted embeddings indicate that such information is beneficial and currently missing from the original model. Our qualitative analysis shows that counter-fitted embedding injection particularly helps with cases involving synonym pairs.

Introduction

While large pre-trained models like BERT are incredibly powerful, they are essentially "black boxes" trained on unsupervised objectives. Consequently, they often lack explicit knowledge of lexical, syntactic, or semantic relationships—such as the fact that "airways" and "airlines" are synonyms. Previous attempts to "inject" this missing knowledge into BERT often relied on complex multi-head attention mechanisms, which add a significant number of parameters and can lead to catastrophic forgetting, where new information overwrites valuable pre-trained representations.

We introduce GiBERT (Gated Injection BERT), a lightweight method to plug external linguistic knowledge directly into BERT’s internal layers. By using a learned gating mechanism, the model successfully incorporates specialized embeddings to improve semantic similarity tasks while using 86% fewer additional parameters than attention-based alternatives.

Methodology

The GiBERT architecture integrates external knowledge through a four-step process:

  1. External Embedding Lookup: Selection of specialized pre-trained embeddings, such as dependency-based embeddings for syntax or counter-fitted embeddings for synonyms.
  2. WordPiece Alignment: Since BERT uses sub-word tokens (WordPieces) and external embeddings are typically word-level, the word embedding is repeated for every corresponding sub-word.
  3. Projection: A simple feed-forward layer projects these external embeddings into BERT’s internal hidden dimension.
  4. Gated Injection: This is the core innovation. Instead of simple addition, a learned gating vector ($g$) acts as a dimmer switch for every dimension, allowing the model to gradually incorporate external information during fine-tuning.
The GiBERT architecture: External embeddings are aligned with WordPieces, projected, and then integrated into a BERT layer via a learned gating mechanism.

This method is compared against AiBERT, an alternative that uses a full Multi-head Attention block to merge the information.

Experimental Setup

The model was evaluated on five semantic similarity and paraphrase detection benchmarks: the Microsoft Research Paraphrase (MSRP) dataset, the Quora Duplicate Questions dataset, and three subtasks (A, B, and C) of the SemEval 2017 Community Question Answering (CQA) task.

Results and Analysis

GiBERT consistently outperformed vanilla BERT across all benchmarks. The most significant gains were observed in the SemEval tasks. For instance, in SemEval Subtask B (Paraphrase), GiBERT with counter-fitted embeddings achieved an F1 of 0.780, compared to vanilla BERT’s 0.704.

Main performance results (F1) comparing GiBERT against vanilla BERT, previous state-of-the-art systems, and the attention-based AiBERT variant.

Key Insights

  • Gating as a Regularizer: Without the gate, injecting external data often degraded performance by disrupting BERT's pre-trained weights. The gate starts at zero, ensuring the model begins fine-tuning as "vanilla" BERT and only incorporates external knowledge where it is demonstrably helpful.
  • Injection Location: Syntactic (dependency) information is most effective when injected into later layers (Layer 11), whereas semantic (counter-fitted) information works best in middle layers (Layer 6). This suggests BERT processes surface-level semantics before complex syntax.
  • Efficiency: GiBERT requires only ~0.2M new parameters, compared to ~1.6M for the attention-based AiBERT. Despite this smaller footprint, GiBERT often performs better, particularly with counter-fitted embeddings.
  • Synonym Handling: Qualitative analysis confirmed that GiBERT is significantly better at identifying related sentences when they use different but synonymous words (e.g., correctly identifying the relationship between "airways" and "airlines").

Conclusion and Future Work

While GiBERT excels at synonymy, it still faces challenges with antonym pairs (e.g., "husband" and "wife"), which often appear in similar contexts. Future research will explore "multi-injection" strategies—simultaneously plugging syntax and semantics into different layers—and the application of gated injection to improve smaller, distilled versions of BERT that may have lost nuance during compression.

Summary updated

BibTeX
@misc{peinelt2020gibert,
  author = {Nicole Peinelt and Marek Rei and Maria Liakata},
  title = {{GiBERT: Introducing Linguistic Knowledge into BERT through a Lightweight Gated Injection Method}},
  year = {2020},
  eprint = {2010.12532},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2010.12532},
}
Figure