semantic-features: A User-Friendly Tool for Studying Contextual Word Embeddings in Interpretable Semantic Spaces

Jwalanthi Ranganathan, Rohan Jha, Kanishka Misra, Kyle MahowaldarXiv 2025

Abstract

We introduce semantic-features, an extensible, easy-to-use library based on Chronis et al. (2023) for studying contextualized word embeddings of LMs by projecting them into interpretable spaces. We apply this tool in an experiment where we measure the contextual effect of the choice of dative construction (prepositional or double object) on the semantic interpretation of utterances (Bresnan, 2007). Specifically, we test whether "London" in "I sent London the letter." is more likely to be interpreted as an animate referent (e.g., as the name of a person) than in "I sent the letter to London." To this end, we devise a dataset of 450 sentence pairs, one in each dative construction, with recipients being ambiguous with respect to person-hood vs. place-hood. By applying semantic-features, we show that the contextualized word embeddings of three masked language models show the expected sensitivities. This leaves us optimistic about the usefulness of our tool.

Introduction

Modern Large Language Models (LLMs) represent word meanings as high-dimensional vectors known as contextual word embeddings (CWEs). While these embeddings are highly effective for natural language processing tasks, they remain "black boxes" to human researchers. For instance, while we intuitively understand that the word "London" carries different semantic weight in "I sent London the letter" versus "I sent the letter to London," raw vector values provide little insight into the nature of this shift.

This paper introduces semantic-features, an open-source library designed to bridge the gap between high-dimensional vector spaces and human-interpretable semantic dimensions. By projecting embeddings into spaces defined by human-rated feature norms, researchers can quantitatively analyze how grammatical context alters the semantic profile of a word.

The semantic-features Library

The core of semantic-features is a mapping technique that utilizes Multi-Layer Perceptrons (MLPs) to translate CWEs from models like BERT, RoBERTa, and ALBERT into human-defined semantic feature norms. These norms, such as those developed by Binder et al. (2016), rate words across 65 distinct dimensions, including Human, Vision, Landmark, and Speech.

The library is designed for accessibility and extensibility. It includes automated hyperparameter tuning via Optuna and a Gradio-based interactive web application. This interface allows users to input sentences and immediately visualize the predicted semantic features of specific words without requiring deep programming expertise.

The interactive Gradio interface of the semantic-features tool, demonstrating predicted semantic values for 'London' in context.

Case Study: Dative Alternation

To demonstrate the tool's utility, we conducted a case study on the "dative alternation"—a linguistic structure where a recipient can be expressed as a Double Object (DO) or a Prepositional Object (PO). Linguists have long hypothesized that the DO construction ("I sent London the letter") biases the interpretation toward an animate recipient (a person or organization), while the PO construction ("I sent the letter to London") biases it toward a physical location.

We generated a balanced dataset of 450 alternating sentence pairs using 15 proper nouns (e.g., "London", "Dakota") that are ambiguous between person-hood and place-hood. We then used semantic-features to extract the predicted semantic profiles for these target words across different layers of BERT, RoBERTa, and ALBERT.

Results and Discussion

Our analysis confirmed that masked language models (MLMs) are sensitive to these subtle contextual shifts. Across all three models, the DO construction resulted in a measurable increase in features associated with animacy (e.g., Human, Intentions), while the PO construction boosted features associated with place-hood (e.g., Landmark, Scene).

Average change in predicted Animacy (left) and Place-hood (right) features across layers for ALBERT, BERT, and RoBERTa.

A key finding was the "middle layer sweet spot." Semantic sensitivity to these grammatical nuances was most pronounced in layers 6 through 9. In the animacy panel, the average difference in activation for recipient features reached approximately 0.75 units on a 0-6 scale. This suggests that the most sophisticated contextual integration occurs during the intermediate stages of model processing, rather than in the final layers.

Conclusion

The semantic-features tool provides a robust framework for interpreting the internal representations of language models. By validating long-standing linguistic hypotheses regarding the dative alternation, we have shown that CWEs capture nuanced, context-dependent semantic shifts. Future work will involve extending the library to autoregressive models and exploring a wider array of linguistic constructions, further democratizing the study of AI interpretability for linguists and cognitive scientists.

Summary updated

BibTeX
@misc{ranganathan2025semantic,
  author = {Jwalanthi Ranganathan and Rohan Jha and Kanishka Misra and Kyle Mahowald},
  title = {{semantic-features: A User-Friendly Tool for Studying Contextual Word Embeddings in Interpretable Semantic Spaces}},
  year = {2025},
  eprint = {2506.06169},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2506.06169},
}
Figure