Sub topic 4
Why representations line up across languages
This chapter assumes you understand transformer encoders, masked language modeling, fine-tuning, and cosine similarity. The goal is to explain why a model trained on several languages can place similar meanings near one another, even when the sentences use different words and scripts.
The shared-representation idea
A multilingual transformer uses the same model parameters for every language. It does not maintain a completely separate encoder for English, German, and Hindi. Instead, text from each language passes through a shared stack of attention and feed-forward layers.
The model converts each token into a vector, or representation. Later layers combine token information with context. If two sentences express similar meanings, successful training gives their contextual representations similar useful structure.
This alignment is indirect. Standard multilingual masked language modeling does not usually tell the model, “These two sentences are translations.” It asks the model to predict missing tokens in many languages. Shared parameters must therefore learn patterns that work across languages.
Why the alignment emerges
Several signals push representations toward compatible structures:
- Shared subwords: Related words may share pieces. For example, cognates such as “information” and “Information” can provide a partial bridge. Shared pieces are not required, however.
- Shared contexts: Words that play similar roles appear in similar syntactic and semantic environments. The model can learn that different surface forms often fill comparable positions.
- Shared attention patterns: Questions, entities, negation, and other relationships can produce similar attention behavior across languages.
- Parallel or translated data: Some models receive an explicit cross-lingual objective or parallel text. This gives a stronger signal than masked prediction alone.
- Shared downstream tasks: When fine-tuning uses one label space, such as entailment versus contradiction, the same output behavior must be supported across languages.
The result is better described as partially aligned spaces than as one perfect multilingual dictionary. Alignment can be strong for common concepts and weak for rare words, culture-specific meanings, or languages with little training data.
| Mechanism | Alignment it can support | Main limitation |
|---|---|---|
| Shared parameters | Common task and language patterns | Capacity is divided across languages |
| Shared subwords | Direct links between related forms | Scripts and morphology may differ |
| Similar contexts | Comparable meanings and syntax | Similar context does not guarantee identical meaning |
| Parallel objectives | More direct translation alignment | Parallel data is expensive and uneven |
Inspecting sentence-level alignment
Sentence embeddings are fixed-length vectors intended to represent whole sentences. A multilingual embedding model can support cross-lingual retrieval by comparing vectors with cosine similarity.
from sentence_transformers import SentenceTransformer, util
model = SentenceTransformer("paraphrase-multilingual-MiniLM-L12-v2")
sentences = [
"The cat is sleeping on the sofa.",
"Le chat dort sur le canapé.",
"The stock market fell sharply today.",
]
embeddings = model.encode(sentences, convert_to_tensor=True)
same_meaning = util.cos_sim(embeddings[0], embeddings[1]).item()
different_meaning = util.cos_sim(embeddings[0], embeddings[2]).item()
print("English-French similarity:", same_meaning)
print("English-English different-topic similarity:", different_meaning)A higher first score than the second suggests useful alignment for these examples. It does not prove that the model understands every translation. Similarity scores depend on the model, domain, sentence length, and language pair.
Common errors and failure modes
Do not assume that shared parameters guarantee equal quality. High-resource languages usually contribute more training examples, so their representations may be better shaped. A low-resource language may receive less capacity and have poorer tokenization.
Do not interpret nearby vectors as exact equivalence. Polysemy, or multiple meanings for one word, depends on context. Cultural references and grammatical distinctions may also be represented unevenly.
Finally, evaluate each language separately. An average score can hide a severe failure in one language.
Exercise
Why can two languages have aligned representations even when they share no written tokens?
Show answer
The shared transformer can learn comparable contextual, syntactic, and semantic patterns from multilingual training data. Shared tokens help, but they are not necessary.