Grammatical information in BERT sentence embeddings as two-dimensional arrays

Vivi Nastase, Paola MerloACL 2023

TL;DR

This paper explores how grammatical information, specifically subject-verb agreement, is encoded in BERT sentence embeddings. They discover that by reshaping these embeddings from 1D arrays into 2D arrays and using VAE-based architectures, models can more effectively learn and detect these grammatical rules, especially with limited training data. This opens new avenues for few-shot learning and understanding the internal representations of language models.

What Problem Does This Paper Address?

Transformer-based language models like BERT have achieved remarkable success on many NLP tasks. However, it's not always clear how well they capture specific grammatical phenomena, especially when those phenomena require understanding relationships between words that are far apart in a sentence (long-distance dependencies). Subject-verb agreement is a classic example of such a phenomenon. While BERT embeddings are known to encode a lot of information, it's often in a distributed, one-dimensional format that can make it difficult to extract specific, rule-like grammatical knowledge. This paper investigates whether this grammatical information is present in BERT embeddings and, if so, how it can be made more accessible for detection, particularly in scenarios with limited training data.

Methods

The core of this research lies in manipulating the representation of BERT sentence embeddings and feeding them into various machine learning architectures.

  • Embedding Reshaping: Standard BERT sentence embeddings are 1D vectors (e.g., 1x768). The authors explore reshaping these into 2D arrays (e.g., 48x16). This is a novel approach to expose potential higher-dimensional patterns.
  • Architectures: They test several architectures:
  • FFNN Baseline: A standard feed-forward neural network.
  • CNN Baseline: Convolutional Neural Networks, adapted to process either 1D sequences of embeddings or 2D reshaped embeddings.
  • Encoder-Decoder (VAE): Variational Autoencoders that aim to learn a compressed latent representation and then reconstruct an answer.
  • Dual VAE: An extension of the VAE that also attempts to reconstruct the input, aiming for more disentangled representations.
  • Task Framework: They use a "rule-like learning" framework where models are trained to detect subject-verb agreement in a multiple-choice setup. This involves presenting a set of sentences that share the target grammatical property but vary in other aspects (like distance between subject and verb, or intervening words).

Datasets

The primary dataset used is BLM-AgrF (Blackbird Language Matrix - Agreement French). This dataset is inspired by Raven's Progressive Matrices and is designed to test rule-like learning.

  • Structure: It consists of sequences of sentences that share the subject-verb agreement phenomenon but differ in factors like the number and type of intervening "attractor" nouns, clause structures, and distances between the subject and verb.
  • Subsets: The dataset is divided into three subsets (Type I, Type II, Type III) with increasing lexical complexity.
  • Training/Testing: The paper uses a 90:10 split for training and testing, with an additional 20% of the training data reserved for development.

Key Insights and Ideas

  • 2D is Better than 1D: The most significant finding is that reshaping 1D BERT embeddings into 2D arrays dramatically improves the ability of models to detect subject-verb agreement, especially under limited training data conditions. This suggests that grammatical information is not simply spread uniformly but might have a more structured, higher-dimensional organization within the embeddings.
  • VAE Architectures Excel: More complex architectures like the Variational Autoencoders (especially the Dual VAE) combined with 2D embeddings consistently outperform simpler models like the FFNN baseline, particularly in challenging scenarios. This indicates that abstracting and compressing the 2D representations further helps in isolating the relevant grammatical signals.
  • Few-Shot Learning Potential: The success with limited data highlights the potential for these 2D-reshaped embeddings and VAEs to enable effective few-shot learning for grammatical tasks.
  • Structured Information: The results suggest that BERT embeddings contain structured grammatical information that can be "unlocked" by appropriate representation manipulation and model architectures.

Key Results

  • Performance Boost: Models using 2D-reshaped embeddings (specifically 48x16) achieved significantly better F1 scores compared to those using 1D embeddings, especially when trained on smaller subsets of data. For instance, on the restricted training set (Type I data), 2D representations with Dual VAE showed substantial improvements over 1D representations.
  • Lexical Complexity Matters: While models performed well on lexically complex data (Type II and III) with full training, the advantage of 2D representations and VAEs was most pronounced on the simpler Type I data with limited training.
  • Error Analysis: The dual VAE with 2D embeddings was better at correcting subject-verb agreement errors, particularly those involving local agreement with the second attractor instead of the correct long-distance agreement. This suggests it can better capture non-local syntactic dependencies.

Limitations and Future Work

  • French Language Focus: The experiments were conducted solely on French sentences. Future work could explore if these findings generalize to other languages.
  • Parameter Tuning: The authors note that the $\beta$ coefficient in the VAE architectures was fixed at 1, and higher values might lead to even more disentangled representations.
  • Higher Dimensions: The paper suggests exploring even higher-dimensional representations (nD-ed) beyond 2D.
  • Broader Grammatical Phenomena: The authors plan to investigate whether this approach can be extended to detect other grammatical or semantic phenomena.
  • Explicit Distillation: Future work aims to directly distill 2D representations into more compact and disentangled forms.
  • Sequence Processing: The current work processes sequences of sentences. Future research could focus on separating rule distillation from sequence processing.

Summary updated

BibTeX
@inproceedings{nastase2023grammatical,
  author = {Vivi Nastase and Paola Merlo},
  title = {{Grammatical information in BERT sentence embeddings as two-dimensional arrays}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
}
Figure