Techniqueresearch
Cross-domain similarity local scaling
Also called CSLS.
Retrieve translations by cosine similarity minus the mean similarity of each word to its k nearest neighbours, which reduces hubness.
Cross-domain similarity local scaling (CSLS) is a similarity score for nearest neighbour retrieval between two sets of vectors, such as mapped source words and target words in cross-lingual embedding mapping. In high dimension, a few target vectors, called hubs, are the nearest neighbours of many queries, and plain cosine retrieval returns them too often (hubness). CSLS subtracts from twice the cosine the mean similarity of each of the two vectors to its nearest neighbours in the other set:
A hub has a high , so its scores go down. Conneau, Lample, Ranzato, Denoyer and Jégou (2018) introduced it with . On their English to Spanish test, it raised the precision at 1 of a supervised Procrustes map from 77.4 with plain nearest neighbour to 81.4.
In plain words
When you translate a word by finding the closest word in the other language, some words are close to almost everything. They sit in a crowded middle part of the space, and they keep winning, even when they are wrong.
CSLS makes the contest fairer. For every word, it measures how close the word usually is to its nearest few neighbours on the other side. A word that is close to everything has a high usual closeness. The score of a pair is its closeness, counted twice, minus the usual closeness of each of the two words.
A pair now scores high only when the two words are closer to each other than they are to their other neighbours. Crowded words lose their advantage, and isolated words get a fair chance.
When it applies
Use it when you retrieve, for each query from one set, its best match in a second set by cosine similarity, the vectors have a high dimension, and you can afford to compute the neighbourhoods of both sets once. The signals are retrieval between two domains (two languages, or images and text), the same few targets appearing as the answer to many queries, and a wish for a fixed rule without a tuned temperature. For retrieval inside one set, the same idea applies with both neighbourhoods in that set.
The template
The holes are the source vectors (already mapped into the target space), the target vectors , the similarity (cosine) and the size of the neighbourhoods. Let be the target vectors nearest to and the source vectors nearest to . Then
CSLS-RETRIEVE(sources x_1..x_n, targets y_1..y_m, K)- 1
for each source s do r_T(s) ← mean of the K largest cos(x_s, y_t) over the targets t - 2
for each target t do r_S(t) ← mean of the K largest cos(x_s, y_t) over the sources s - 3
for each source s do - 4
answer(s) ← argmax over t of 2 cos(x_s, y_t) - r_T(s) - r_S(t) - 5
return answer
Lines L1 and L2 compute the two mean similarities, with the cosines of the same matrix read by rows and by columns. Line L4 ranks the targets of one source. For a fixed source, is the same for every target, so the ranking of line L4 is the ranking by . The term matters when scores of different sources are compared, for example to keep the most confident pairs or to test whether two words are mutual nearest neighbours.
With brute force, lines L1 to L4 cost for the cosines and for the heaps of the best values, and the heaps take space. In practice the neighbourhoods are found with a fast nearest neighbour index, often on the most frequent words only.
Example. Take three sources and three targets with the cosines below, and .
| 0.60 | 0.20 | 0.65 | 0.625 | |
| 0.10 | 0.55 | 0.60 | 0.575 | |
| 0.20 | 0.15 | 0.70 | 0.450 | |
| 0.400 | 0.375 | 0.675 |
Every row has its largest cosine at , so plain nearest neighbour retrieval sends all three sources to the hub . Its is high, . The CSLS scores are
| answer | ||||
|---|---|---|---|---|
| 0.175 | -0.600 | 0.000 | ||
| -0.775 | 0.150 | -0.050 | ||
| -0.450 | -0.525 | 0.275 |
For example, . Each target is now chosen once, and each pair is a mutual best match under CSLS.
Classic examples
- Word translation. After a cross-lingual embedding mapping by Procrustes, each source word is translated to the target word with the highest CSLS score. This is the use in Conneau et al., where it beat plain cosine and the inverted softmax in most language pairs of their Table 1.
- Dictionary induction for refinement. The Procrustes refinement of Conneau et al. builds each new seed dictionary from the pairs that are mutual nearest neighbours under CSLS, so that the next map is fitted on more reliable pairs.
- Analogy and similarity search. The same correction applies to any k-nearest neighbor search in a high-dimensional embedding space where hubness appears, such as the retrieval step of a word analogy query.
- Cross-lingual sentence retrieval. With multilingual sentence embeddings, the same kind of score, the cosine corrected by the mean similarity to the nearest neighbours, is used to find sentences that are translations of each other.
Variations
- The size of the neighbourhood. Conneau et al. report that the results are about the same for , 10 and 50, and use in all their tests.
- Inverted softmax. Smith et al. (2017) normalize the similarities of each target over all sources with a softmax at a temperature, which also lowers the scores of hubs. The temperature must be tuned, which is hard without a validation dictionary.
- Reverse ranks. Dinu, Lazaridou and Baroni (2015) rank the candidates by how highly the query ranks among the neighbours of each candidate, instead of by the similarity itself.
- Ratio form. Dividing the cosine by the mean neighbourhood similarity, instead of subtracting it, gives a margin of a related form.
- One domain. For retrieval in one set, both means are taken in that set. Conneau et al. note that this kind of correction resembles the preprocessing of some spectral clustering methods.
Pitfalls
- Neighbourhoods on the wrong side. uses the target neighbours of a source vector and the source neighbours of a target vector. Computing from the other target vectors measures density in the wrong set and does not correct cross-domain hubs.
- Unmapped sources. must use the mapped source vectors . Using the source vectors before the map gives meaningless cosines.
- Reading the score as a cosine. CSLS values are not in and can be negative for the best match. Use them to rank, not as a similarity with a fixed threshold.
- The cost of . Line L2 needs the nearest sources of every target, which is a search over the whole source vocabulary for each target. Restrict both vocabularies to the frequent words, or use an index.
- Different sets at test time. and depend on which words are in the two sets. Adding or removing words changes the scores of all pairs, so compare results only with the same vocabularies.
Exercises
- Show that for a fixed source , ranking the targets by CSLS gives the same order as ranking them by .
- In the example, change the cosine of and from 0.65 to 0.75. Recompute , and the CSLS answers.
- Show that if every target has the same , CSLS retrieval returns the same answers as plain nearest neighbour retrieval.
References
- Conneau, Lample, Ranzato, Denoyer and Jégou 2018, Section 2.3 (equations 5 and 6, the definition of r_T, r_S and CSLS), Section 3.4 (mutual nearest neighbours under CSLS for the dictionary), Section 4 and Table 1 (K = 10, and Procrustes with NN, ISF and CSLS retrieval)
- Radovanović, Nanopoulos and Ivanović 2010, the hubness phenomenon, some points are nearest neighbours of many points in high dimension
- Dinu, Lazaridou and Baroni 2015, the hubness of mapped vectors and the retrieval rule based on reverse ranks
- Smith, Turban, Hamblin and Hammerla 2017, the inverted softmax, which normalizes the similarity of each target word over the source words
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W3 standard |
|
Tag YD1B0W Edit this page History Report an error Markdown