Metaphor Detection Using Contextual Word Embeddings From Transformers

Jerry Liu, Nathan O'Hara, Alexander Rubin, Rachel Lea Draelos, Cynthia RudinFig-Lang @ ACL 2020 · DOI

TL;DR

This paper tackles the challenge of automatically detecting metaphors at the word level, which is crucial for improving various NLP tasks like sentiment analysis and machine translation. The authors leverage powerful transformer models (BERT and XLNet) to generate contextualized word embeddings, which are then fed into a Bi-LSTM network to predict metaphoricity, achieving competitive results in a shared task.

What Problem Does This Paper Address?

Metaphors are a fundamental aspect of human language, allowing us to express complex ideas by drawing connections between different concepts. However, their figurative nature makes them notoriously difficult for machines to understand. Accurately identifying metaphors, especially at the individual word level, is essential for downstream NLP applications. For instance, a sentiment analysis system might misinterpret the emotional tone of a sentence if it fails to recognize that "the trajectory of your legal career" uses "trajectory" metaphorically to describe a path rather than a physical motion. Traditional methods often rely on context-independent word embeddings, which struggle to capture the nuanced meaning shifts required for metaphor detection. This paper aims to bridge this gap by employing state-of-the-art contextualized embeddings.

Methods

The core of the proposed method lies in using transformer-based language models, specifically BERT and XLNet, to generate contextualized word embeddings. Unlike traditional embeddings (like Word2Vec or GloVe) that assign a single vector to each word, these transformer models produce embeddings that vary based on the word's surrounding context.

The authors explored different strategies for combining the hidden states from BERT to create these embeddings, ultimately settling on summing the representations from all layers. They then concatenated the embeddings from both BERT and XLNet to create a richer, 1536-dimensional representation for each word. To further enhance these embeddings, they appended Part-of-Speech (POS) tags, which have been shown to be beneficial in previous metaphor detection tasks.

These combined features are then fed into a bidirectional Long Short-Term Memory (Bi-LSTM) neural network. The Bi-LSTM is designed to capture long-range dependencies within a sentence, which is crucial for understanding how words relate to each other and potentially signal a metaphor. A sigmoid activation function is used to output a probability of metaphoricity for each word. Due to the inherent class imbalance (non-metaphors far outweigh metaphors), a weighted binary cross-entropy loss function was employed during training. For testing, an ensemble strategy involving averaging predictions from multiple initialized Bi-LSTMs was used.

Datasets

The paper utilizes two primary datasets for evaluation, both from the Second Shared Task on Metaphor Detection:

  • VUA (VU Amsterdam Metaphor Corpus): This corpus consists of text fragments sampled from four genres of the British National Corpus (BNC): Academic, News, Conversation, and Fiction.
  • TOEFL: This dataset is a subset of the ETS Corpus of Non-Native Written English, containing essays written by test-takers for the TOEFL test, annotated for argumentation-relevant metaphors.

For each dataset, participants could compete in two tracks: identifying metaphors for all parts of speech (AllPOS) or verbs only (Verbs).

Key Insights and Ideas

  • Context is King: The paper strongly reinforces the idea that contextualized word embeddings from transformers are significantly more effective for metaphor detection than static embeddings. The ability to capture word meaning based on its surrounding text is paramount.
  • Ensembling Transformers Boosts Performance: Combining embeddings from both BERT and XLNet yielded better results than using either model alone, suggesting that different transformer architectures capture complementary contextual information.
  • Bi-directionality Matters: The observation that GPT2+LSTM performed worse than BERT+LSTM and XLNet+LSTM suggests that bidirectional context (understanding words in relation to both preceding and succeeding words) is critical for metaphor detection. XLNet's ability to consider permutations of words likely contributes to its strong performance.
  • POS Tags Add Value: While transformer embeddings are powerful, appending POS tags provided a small but noticeable improvement, indicating that syntactic information still plays a role.
  • KNN and LSTM Capture Different Information: The exploration of a KNN-based approach alongside the LSTM revealed that these two methods capture distinct types of information about metaphors. This opens up promising avenues for future ensemble models that combine their strengths.

Key Results

The authors' best model, an ensemble of BERT and XLNet embeddings fed into a Bi-LSTM, achieved the following F1-scores:

  • VUA AIIPOS: 68.0%
  • VUA Verbs: 73.0%
  • TOEFL AllPOS: 66.9%
  • TOEFL Verbs: 69.7%

These scores placed their submission 7th, 6th, 5th, and 5th respectively in the Second Shared Task on Metaphor Detection. They also noted that their model's performance on the VUA dataset was generally better than on the TOEFL dataset, potentially due to the smaller size of the TOEFL dataset and differences in linguistic characteristics between native and non-native English.

Limitations and Future Work

A significant limitation acknowledged is the inability to fully implement a proposed ensemble model combining Bi-LSTM and K-Nearest Neighbors (KNN) due to time constraints. While they detail promising results from a simplified KNN approach, a full integration was not achieved for the competition.

The authors suggest that the LSTM and KNN approaches capture complementary information. The LSTM excels at identifying general patterns of metaphoricity, while KNN can pinpoint whether a specific word's usage is likely metaphorical based on similar past instances. They believe a superior classifier could be constructed by combining these insights.

Furthermore, they observed that their LSTM models sometimes assigned similar probabilities to different instances of the same word, even when context varied. They propose a testing phase procedure that labels a word as metaphorical if its predicted probability is significantly higher than the median predicted probability for that word, addressing potential domain shifts and improving F1 scores. This concept of using a threshold or a significant deviation from the median prediction is highlighted as a promising direction.

Summary updated

BibTeX
@inproceedings{liu2020metaphor,
  author = {Jerry Liu and Nathan O'Hara and Alexander Rubin and Rachel Lea Draelos and Cynthia Rudin},
  title = {{Metaphor Detection Using Contextual Word Embeddings From Transformers}},
  booktitle = {Fig-Lang @ ACL},
  year = {2020},
  doi = {10.18653/v1/2020.figlang-1.34},
}
Figure