Skip to main page content
U.S. flag

An official website of the United States government

Dot gov

The .gov means it’s official.
Federal government websites often end in .gov or .mil. Before sharing sensitive information, make sure you’re on a federal government site.

Https

The site is secure.
The https:// ensures that you are connecting to the official website and that any information you provide is encrypted and transmitted securely.

Access keys NCBI Homepage MyNCBI Homepage Main Content Main Navigation
. 2021 May 26;9(5):e23099.
doi: 10.2196/23099.

Predicting Semantic Similarity Between Clinical Sentence Pairs Using Transformer Models: Evaluation and Representational Analysis

Affiliations

Predicting Semantic Similarity Between Clinical Sentence Pairs Using Transformer Models: Evaluation and Representational Analysis

Mark Ormerod et al. JMIR Med Inform. .

Abstract

Background: Semantic textual similarity (STS) is a natural language processing (NLP) task that involves assigning a similarity score to 2 snippets of text based on their meaning. This task is particularly difficult in the domain of clinical text, which often features specialized language and the frequent use of abbreviations.

Objective: We created an NLP system to predict similarity scores for sentence pairs as part of the Clinical Semantic Textual Similarity track in the 2019 n2c2/OHNLP Shared Task on Challenges in Natural Language Processing for Clinical Data. We subsequently sought to analyze the intermediary token vectors extracted from our models while processing a pair of clinical sentences to identify where and how representations of semantic similarity are built in transformer models.

Methods: Given a clinical sentence pair, we take the average predicted similarity score across several independently fine-tuned transformers. In our model analysis we investigated the relationship between the final model's loss and surface features of the sentence pairs and assessed the decodability and representational similarity of the token vectors generated by each model.

Results: Our model achieved a correlation of 0.87 with the ground-truth similarity score, reaching 6th place out of 33 teams (with a first-place score of 0.90). In detailed qualitative and quantitative analyses of the model's loss, we identified the system's failure to correctly model semantic similarity when both sentence pairs contain details of medical prescriptions, as well as its general tendency to overpredict semantic similarity given significant token overlap. The token vector analysis revealed divergent representational strategies for predicting textual similarity between bidirectional encoder representations from transformers (BERT)-style models and XLNet. We also found that a large amount information relevant to predicting STS can be captured using a combination of a classification token and the cosine distance between sentence-pair representations in the first layer of a transformer model that did not produce the best predictions on the test set.

Conclusions: We designed and trained a system that uses state-of-the-art NLP models to achieve very competitive results on a new clinical STS data set. As our approach uses no hand-crafted rules, it serves as a strong deep learning baseline for this task. Our key contribution is a detailed analysis of the model's outputs and an investigation of the heuristic biases learned by transformer models. We suggest future improvements based on these findings. In our representational analysis we explore how different transformer models converge or diverge in their representation of semantic signals as the tokens of the sentences are augmented by successive layers. This analysis sheds light on how these "black box" models integrate semantic similarity information in intermediate layers, and points to new research directions in model distillation and sentence embedding extraction for applications in clinical NLP.

Keywords: biomedical NLP; clinical text; natural language processing; representation learning; transformer models.

PubMed Disclaimer

Conflict of interest statement

Conflicts of Interest: None declared.

Figures

Figure 1
Figure 1
Our system architecture for predicting the semantic textual similarity between two sentences using an ensemble of five Transformer models.
Figure 2
Figure 2
Common categories of error for cases when the model over-predicts similarity as identified by manual analysis of the 100 worst predictions.
Figure 3
Figure 3
Common categories of error for cases when the model under-predicts similarity as identified by manual analysis of the 100 worst predictions.
Figure 4
Figure 4
Pearson correlation between linear regression models’ predictions of a sentence pair’s semantic similarity and the ground-truth score (10-fold cross-validated on test-set) using [CLS] token pair representations.
Figure 5
Figure 5
Pearson correlation between linear regression models’ predictions of a sentence pair’s semantic similarity and the ground-truth score (10-fold cross-validated on test-set) using the absolute difference between each sentence’s mean-pooled token vector.
Figure 6
Figure 6
Model representational dissimilarity matrix for 412 test sentence pairs measured by distance between ground-truth semantic similarity scores. The dimensions of the dissimilarity matrix are sorted by each sentence-pair’s ground-truth semantic similarity score.
Figure 7
Figure 7
The final best-fitting re-weighted and linearly re-combined explanatory model found using NNLS and representations from BioBERT, achieving a correlation of 0.54 with the ground-truth model. The dimensions of the dissimilarity matrix are sorted by each sentence-pair’s ground-truth semantic similarity score.
Figure 8
Figure 8
Correlation between the ground-truth model RDM and explanatory RDMs constructed from [CLS] token pair representations.
Figure 9
Figure 9
Weights associated with sentence-pair representations of BERT-Large found using NNLS to minimise the distance between a linearly re-combined set of RDMs and the ground-truth model RDM for each layer.
Figure 10
Figure 10
Correlation between the ground-truth model RDM and explanatory RDMs constructed using the absolute difference between each sentence’s mean-pooled token vector.
Figure 11
Figure 11
Proportion of weights learned for the best explanatory model (which used BioBERT representations and text features).

Similar articles

Cited by

References

    1. Deerwester S, Dumais ST, Furnas GW, Landauer TK, Harshman R. Indexing by latent semantic analysis. J. Am. Soc. Inf. Sci. 1990 Sep;41(6):391–407. doi: 10.1002/(sici)1097-4571(199009)41:6<391::aid-asi1>3.0.co;2-9. - DOI
    1. Salton G. Automatic text processing: the transformation, analysis, and retrieval of information by computer. Choice Reviews Online. 1989 Sep 01;27(01):27-0351–27-0351. doi: 10.5860/choice.27-0351. - DOI
    1. Lee M, Pincombe B, Welsh M. An Empirical Evaluation of Models of Text Document Similarity. Proceedings of the Annual Meeting of the Cognitive Science Society; Annual Conference of the Cognitive Science Society; 21-23 July 2005; Stresa, Italy. 2005. Jul, pp. 1254–1259. https://escholarship.org/uc/item/48g155nq
    1. Agirre E, Cer D, Diab M, Gonzalez-Agirre A. SemEval-2012 Task 6: A Pilot on Semantic Textual Similarity (SemEval@NAACL-HLT). *SEM 2012: The First Joint Conference on Lexical and Computational Semantics; June 7-8, 2012; Montréal, QC, Canada. 2012. Jun, pp. 285–393. - DOI
    1. Agirre E, Cer D, Diab M, Gonzalez-Agirre A, Guo W. *SEM 2013 shared task: Semantic Textual Similarity (*SEM@NAACL-HLT). Second Joint Conference on Lexical and Computational Semantics (*SEM); June 2013; Atlanta, GA, USA. 2013. Jun, pp. 32–43.