FastPrepRank Unseen Items by Embedding Similarity

Rank Unseen Items by Embedding Similarity

Yahoo logoYahoo● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

You are given one user embedding and n item embeddings of the same dimension. The similarity of an item is the dot product of its embedding with the user embedding.

Exclude every item index in seenItemIndexes. Return all remaining item indices sorted by descending similarity. Break an exact score tie by the smaller item index.

Function

rankUnseenItems(userEmbedding: double[], itemEmbeddings: double[][], seenItemIndexes: int[]) → int[]

Examples

Example 1

userEmbedding = [1.0,2.0]itemEmbeddings = [[1.0,0.0],[0.0,2.0],[2.0,1.0],[-1.0,0.0]]seenItemIndexes = [1]return = [2,0,3]

After excluding item 1, the dot products are 4, 1, and -1 for indices 2, 0, and 3.

Example 2

userEmbedding = [1.0,1.0]itemEmbeddings = [[2.0,0.0],[0.0,2.0],[1.0,1.0]]seenItemIndexes = []return = [0,1,2]

All three scores are 2, so indices determine the order.

Constraints

  • 1 <= itemEmbeddings.length <= 100000.
  • 1 <= userEmbedding.length <= 200, and every item embedding has that length.
  • All coordinates are finite doubles with absolute value at most 10^6.
  • Seen indices are distinct and valid.

More Yahoo problems

See Yahoo hiring insights
public int[] rankUnseenItems(double[] userEmbedding, double[][] itemEmbeddings, int[] seenItemIndexes) {
    // Write your code here.
}
userEmbedding[1.0,2.0]
itemEmbeddings[[1.0,0.0],[0.0,2.0],[2.0,1.0],[-1.0,0.0]]
seenItemIndexes[1]
expected[2,0,3]
Checking account…