All problems
HyDE Concept Score
Problem
Score a toy HyDE expansion. Build a hypothetical document vector as the weighted sum of concept_vectors for every term in expansions, skipping terms with no vector, then return its cosine similarity with query_vector.
Return 0.0 when the hypothetical document or the query has zero norm.
Hint
Weighted sum first, cosine second; missing concept vectors are simply ignored.
Test cases
case 1
in: [[1,0],{"a":1,"b":1},{"a":[1,0],"b":[0,1]}]
expected: 0.7071067811865475
case 2
in: [[1,0],{},{"a":[1,0]}]
expected: 0
case 3
in: [[1,0],{"a":1,"z":5},{"a":[1,0],"b":[0,1]}]
expected: 1
case 4
in: [[0,0],{"a":1},{"a":[1,0]}]
expected: 0
case 5
in: [[0,1],{"a":2},{"a":[0,3]}]
expected: 1
Starter codePython
import math
def hyde_concept_score(query_vector, expansions, concept_vectors):
# Your code here
pass5 test cases · run your code against them in the editor