Hyperpolyglot LLM s: Cross-Lingual Interpretability in Token Embeddings (2023)

Abstract: Cross-lingual transfer learning is an important property of multilingual large language models (LLMs). But how do LLMs represent relationships between languages? Every language model has an input layer that maps tokens to vectors. This ubiquitous layer of language models is often overlooked. We find that similarities between these input embeddings are highly interpretable and that the geometry of these embeddings differs between model families. In one case (XLM-RoBERTa), embeddings encode language: tokens in different writing systems can be linearly separated with an average of 99.2% accuracy. Another family (mT5) represents cross-lingual semantic similarity: the 50 nearest neighbors for any token represent an average of 7.61 writing systems, and are frequently translations. This result is surprising given that there is no explicit parallel cross-lingual training corpora and no explicit incentive for translations in pre-training objectives. Our research opens the door for investigations in 1) The effect of pre-training and model architectures on representations of languages and 2) The applications of cross-lingual representations embedded in language models.

## introduction multilingual large language models (llms) have the potential to support transfer learning between languages with little to no additional training data @xcite @xcite . but we have limited theory for how llms represent meanings across languages. this work describes a mechanism for cross-lingual transfer learning by measuring the properties of the input embedding vectors. while most of the interest in llms rightly focuses on their ability to produce contextualized output, in this study we focus specifically on the lowest network layer: the initial token embedding layer. this layer often comprises a large percentage of the total parameters in a model. it also serves as the connection between human-readable strings and the latent vector representations that initialize the remaining layers. as such, the initial token embedding layer is both geometrically expressive and readily interpretable. we explore the initial token embeddings of two highly multilingual model families, xlm-roberta (xlm-r) @xcite and mt5 @xcite . we find that mt5 discovers a universal, cross-lingual semantic space that assigns words (or word fragments) with similar meanings to nearby vector positions. 1 previous work has shown that algorithms exist to train multilingual word embeddings without explicit parallel text or glossaries @xcite . what is novel about the current work is the discovery that certain highly multilingual llms contain such an embedding as an emergent property without any explicit instruction to do so. explaining the factors that cause llms to find cross-lingual semantic embeddings would require pre-training experiments that are beyond the scope of this short paper. describing these behaviors is, however, a necessary first step. at the same time, there is increasing attention on producing language technology for lower-resource languages @xcite , where the datahungry methods that have been successful for highresource languages may not be applicable. creating predictive theories that explain the relationship between properties of pre-training data and representations learned by llms could lead us to build collections, architectures, and algorithms that most efficiently improve performance. this will be an extremely valuable step to enhance language technology for low-resource languages. ## related work previous work has found interpretable patterns in feed-forward layers @xcite , selfattention @xcite @xcite , and input embeddings from the perspective of adversarial perturbation @xcite . in this work, we directly interpret the relative positions of the token embeddings through the lens of the vocabularies. prior to the explosion of contextualized language models, there was substantial interest in crosslingual word embeddings (clwe) @xcite @xcite . the goal is often to map monolingual word embeddings from different languages to the same shared space, so that words of the same meaning are close to each other. clwe approaches involve some levels of supervised alignment @xcite , seed dictionaries @xcite or adversarial training @xcite @xcite . contexualized embeddings from language models have also been used in combination with static word embeddings to improve alignments of crosslingual word vectors @xcite . contrary to our findings for the token embeddings of llms, it was not clear that aligning word vectors is possible without some level of supervision, or to more than two languages at a time. previous results also showed that clwe approaches are sensitive to language pairs, where languages with large semantic or structural differences usually failed, such as english-japanese and spanish-chinese @xcite . ## multilingual vocabularies sub-word tokenization and writing systems initial embedding layer maps tokens to vectors. most contemporary language models use sub-word tokenization schemes such as byte-pair encoding. these methods balance representational richness (providing distinct vectors for as many inputs as possible) with efficiency in limiting overall vocabulary size. while some methods produce tokens consisting of byte sequences that are not valid utf-8 characters, in practice almost all tokens are valid, displayable sequences of unicode characters, and a large number are recognizable words foot_1 . as it is difficult to assign tokens to specific languages (e.g. war can be an english noun or a german verb), we use unicode metadata to define categories of tokens. for example, a is latin small letter a. most characters are letters (l), but vocabularies also include punctuation (p), numbers (n), and symbols (s, which include emoji). letters are also marked by writing system, such as latin, cyrillic, or bengali. we define the category of a character as either its writing system (for letters) or its unicode class for non-letters. a token can mix characters of different categories, but they typically have a most frequent category: the string doesn't contains letters and punctuation, but is primarily latin letters. we define the category of a token based on its majority character category. as a result, doesn't is classified as latin. ies, they are often comparable. current vocabulary sizes of monolingual models are often ⇡ 32,000 (bert, t5, llama), 50,000 (gpt2, gpt-j, pythia), or 65,000 (falcon). highly multilingual models have larger sizes around 250,000 (mt5, umt5, xlm-r, bloom). ## results models encode languages differently. we make comparisons between the embeddings of xl-scale models from mt5 and xlm-r families. in addition to -xl models being potentially more expressive, xlm-r-xl and mt5-xl are also more comparable in parameter size (3.5b and 3.7b, respectively). figure 1 shows umap @xcite projections of the embeddings from xlm-r-xl and mt5-xl for each token in the shared vocabulary, colored by unicode category. we find that xlm-r's representations encode languagestokens of different categories form isolated clusters. clusters of unicode categories are also noticeable in mt5 but they are more overlapping. the exception is symbols (s) and numbers (n): they are scattered in xlm-r-xl, but clustered in mt5-xl. to further show how embeddings encode languages, we use logistic regression to predict unicode category from embeddings. for each category, we construct a balanced dataset and run 10-fold cross-validation. embeddings from xlm-r-xl and mt5-xl both encode a high level of language information. tokens with different unicode category could be linearly separated with an average of 99.24% and 93.32% accuracy, respectively. figure 3 shows accuracy for selected categories. xlm-r-xl has significantly higher (near perfect) accuracy across the majority of categories than mt5-xl. embedding neighborhoods encode semantics across languages. we next zoom in to study the neighbors of individual tokens. neighbors from mt5-xl are often direct translations, whereas xlm-r-xl finds tokens in the same language that are semantically or linguistically similar. figure 5 shows that the 50 nearest neighbors for mt5-xl tokens have an average of 7.61 different unicode categories, whereas xlm-r-xl has 1.64. figure 4 shows examples of 20 nearest neighbors of selected tokens. the neighboring categories of tokens in mt5 vary by the category of a token, as shown in figure 6 . we find interesting comparisons between two japanese writing systems, katakana and hira-gana. katakana, a writing system often used for words of foreign origin, has more diverse neighbors (most often latin). hiragana, used more for native japanese words, has more neighbors in hiragana and cjk (kanji). we do not find evidence to suggest that tokens appearing more often in pre-training corpora have more diverse neighbors (figure 9 in the appendix). ## conclusion while input embeddings and sub-word tokenized vocabularies of llms may appear inscrutable, we find that they are in fact interpretable and meaningful. we observe significant patterns that differ by model families, including an emergent ability of mt5 to discover a shared semantic space that spans languages -accidentally achieving a goal that defied a decade of research on cross-lingual word embeddings. future directions include explaining factors that cause the different token embedding patterns we observe in xlm-r and mt5. this could include investigations in model architectures, pre-training procedures, and data-centric strategies such as the curation of pre-training corpora. finding an efficient path to a more equitable language model performance will be valuable for enhancing language technology for low-resource languages. an interesting next study could explore the utility of combining low-resource languages with closely related higher-resource languages in pre-training corpora. another future direction is to explore the potential applications of cross-lingual representations embedded in llms -what does it say about downstream applications? could it be used to guide practitioners to select models that are more appropriate for their intended uses?