Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-414

TF-IDF Dot Product Ranking

Problem

Rank documents by the dot product of their TF-IDF vectors with the query vector, returning the index of the highest scoring document (earliest on ties).

Given the query vector and the list of document vectors, return the best index.

Hint

Plain dot product, no normalization.

Test cases

case 1
in: [[1,2],[[1,1],[0,3]]]
expected: 1
case 2
in: [[1,0],[[0,5],[1,0]]]
expected: 1
case 3
in: [[0,0],[[1,1],[2,2]]]
expected: 0
Starter codePython
def tf_idf_dot_product_ranking(query_vector, doc_vectors):
    # Your code here
    pass

3 test cases · run your code against them in the editor