Views
No views yet
pip install -U FlagEmbedding1import torch
2from FlagEmbedding import FlagModel
3
4model_name = "puppyyyo/larceny-base-law-knowledge-v1"
5devices = "cuda:0" if torch.cuda.is_available() else "cpu"
6
7model = FlagModel(
8 model_name,
9 devices=devices,
10 use_fp16=False
11 )
12
13sentences_1 = ["What is BGE M3?", "Defination of BM25"]
14sentences_2 = ["BGE M3 is an embedding model supporting dense retrieval, lexical matching and multi-vector interaction.",
15 "BM25 is a bag-of-words retrieval function that ranks a set of documents based on the query terms appearing in each document"]
16
17embeddings_1 = model.encode(sentences_1)
18embeddings_2 = model.encode(sentences_2)
19similarity = embeddings_1 @ embeddings_2.T
20print(similarity)
21
22# base-v1
23# [[0.72338223 0.7122297 ], [0.5691198 0.78866345]]
24# base-v2
25# [[0.6811399 0.5206243 ], [0.50919324 0.676651 ]]
26# base-v3
27# [[0.6299723 0.5048096 ], [0.45474052 0.63200176]]