File size: 606 Bytes
87fe5d9
 
49b416c
 
 
 
 
 
 
 
 
 
87fe5d9
 
 
 
49b416c
87fe5d9
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
"""checks that every pair of sentences gets the same vector."""
import sys
from encode import encode, cosine

PAIRS = [
    ("i love you", "i hate you"),
    ("the ocean is beautiful", "2 + 2 = 4"),
    ("please water my plants", "the mitochondria is the powerhouse of the cell"),
    ("hamlet: to be or not to be", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
    ("", "this sentence has been completely redacted for legal reasons"),
]

for a, b in PAIRS:
    c = cosine(encode(a), encode(b))
    assert abs(c - 1.0) < 1e-6, (a, b, c)
    print(f"cosine({a!r:<36}, {b!r:<52}) = {c:.6f}")

print("ok")
sys.exit(0)