Download similarity.py from tsfrm/unity-embed: direct link, hf CLI and curl.
- Browser
- Download file 606 Bytes
-
https://huggingface.co/tsfrm/unity-embed/resolve/main/similarity.py
- Command line
-
hf download hf://tsfrm/unity-embed/similarity.py
-
curl -L -o similarity.py https://huggingface.co/tsfrm/unity-embed/resolve/main/similarity.py
606 Bytes
| """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) | |