How the Two-Tower search model works: training, inference and serving
The article explains the Two-Tower[1] model used in search and recommendation. Two separate neural networks turn a query and an item into vectors, and relevance is scored by the dot product of the two vectors. Item vectors can be computed in advance, so large candidate sets can be searched quickly.
Training raises the score of the correct item above the scores of negative items. The basic method is in-batch negatives[2], where the correct items of other pairs in the same mini-batch serve as negatives, and the loss is softmax cross-entropy. The article also covers the logQ correction from Yi et al., which reduces the bias toward popular items, and Mixed Negative Sampling from Yang et al., which adds uniformly random items so that items absent from click logs are also compared.
Hard negative mining[3] selects negatives that the model scores highly. Huang et al. at Facebook used this method and reported the best recall when negatives were taken from ranks 101 to 500. For serving, item embeddings are stored in advance, query embeddings are computed per request, and approximate nearest neighbor search (ANN)[4] is used when there are many items, which trades some accuracy for speed.
Sources
-
JPZenn JA
仕組み編:Two-Towerによる検索システム(学習・推論・配信)





