-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetEmbedding.py
More file actions
39 lines (28 loc) · 907 Bytes
/
Copy pathgetEmbedding.py
File metadata and controls
39 lines (28 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
======================================================================
GETEMBEDDING ---
Obtain the Embedding of Setences.
Author: Zi Liang <zi1415926.liang@connect.polyu.hk>
Copyright © 2025, ZiLiang, all rights reserved.
Created: 13 March 2025
======================================================================
"""
# ------------------------ Code --------------------------------------
## normal import
import json
from typing import List, Tuple, Dict
import random
from pprint import pprint as ppp
# pip install -U FlagEmebdding
from FlagEmbedding import BGEM3FlagModel as Model
def getembeddings(sentls1, sentls2):
model = Model("BAAI/bge-m3", use_fp16=True)
embedls1 = model.encode(
sentls1,
batch_size=32,
max_length=512,
)["dense_vecs"]
embedls2 = model.encode(
sentls2,
)["dense_vecs"]
return embedls1, embedls2