hjxdl 0.0.12__py3-none-any.whl → 0.0.13__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hdl/_version.py +2 -2
- hdl/utils/llm/embs.py +59 -0
- {hjxdl-0.0.12.dist-info → hjxdl-0.0.13.dist-info}/METADATA +1 -1
- {hjxdl-0.0.12.dist-info → hjxdl-0.0.13.dist-info}/RECORD +6 -5
- {hjxdl-0.0.12.dist-info → hjxdl-0.0.13.dist-info}/WHEEL +0 -0
- {hjxdl-0.0.12.dist-info → hjxdl-0.0.13.dist-info}/top_level.txt +0 -0
hdl/_version.py
CHANGED
hdl/utils/llm/embs.py
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
from FlagEmbedding import BGEM3FlagModel
|
2
|
+
|
3
|
+
|
4
|
+
class FlagEmbedder():
|
5
|
+
def __init__(
|
6
|
+
self,
|
7
|
+
emb_dir: str = None
|
8
|
+
) -> None:
|
9
|
+
"""Initialize the class with the specified embedding directory.
|
10
|
+
|
11
|
+
Args:
|
12
|
+
emb_dir (str): The directory containing the embeddings.
|
13
|
+
|
14
|
+
Returns:
|
15
|
+
None
|
16
|
+
"""
|
17
|
+
self.model = BGEM3FlagModel(
|
18
|
+
emb_dir,
|
19
|
+
use_fp16=True
|
20
|
+
)
|
21
|
+
|
22
|
+
def encode(
|
23
|
+
self,
|
24
|
+
sentences
|
25
|
+
):
|
26
|
+
"""Encode the input sentences using the model.
|
27
|
+
|
28
|
+
Args:
|
29
|
+
sentences (list): List of sentences to encode.
|
30
|
+
|
31
|
+
Returns:
|
32
|
+
numpy.ndarray: Encoded representation of the input sentences.
|
33
|
+
"""
|
34
|
+
output = self.model.encode(
|
35
|
+
sentences,
|
36
|
+
return_dense=True,
|
37
|
+
return_sparse=True,
|
38
|
+
return_colbert_vecs=False
|
39
|
+
)
|
40
|
+
return output
|
41
|
+
|
42
|
+
def sim(
|
43
|
+
self,
|
44
|
+
sentences_1,
|
45
|
+
sentences_2
|
46
|
+
):
|
47
|
+
"""Calculate the similarity between two sets of sentences.
|
48
|
+
|
49
|
+
Args:
|
50
|
+
sentences_1 (list): List of sentences for the first set.
|
51
|
+
sentences_2 (list): List of sentences for the second set.
|
52
|
+
|
53
|
+
Returns:
|
54
|
+
float: Similarity score between the two sets of sentences.
|
55
|
+
"""
|
56
|
+
output_1 = self.encode(sentences_1)
|
57
|
+
output_2 = self.encode(sentences_2)
|
58
|
+
similarity = output_1['dense_vecs'] @ output_2['dense_vecs'].T
|
59
|
+
return similarity.item()
|
@@ -1,5 +1,5 @@
|
|
1
1
|
hdl/__init__.py,sha256=5sZZNySv08wwfzJcSDssGTqUn9wlmDsR6R4XB8J8mFM,70
|
2
|
-
hdl/_version.py,sha256=
|
2
|
+
hdl/_version.py,sha256=FMLMzW4kZnBuc3z5uydtuxnwzYOv6BBwKN68kOrxpEo,413
|
3
3
|
hdl/args/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
4
|
hdl/args/loss_args.py,sha256=s7YzSdd7IjD24rZvvOrxLLFqMZQb9YylxKeyelSdrTk,70
|
5
5
|
hdl/controllers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -85,9 +85,10 @@ hdl/utils/general/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU
|
|
85
85
|
hdl/utils/general/glob.py,sha256=8-RCnt6L297wMIfn34ZAMCsGCZUjHG3MGglGZI1cX0g,491
|
86
86
|
hdl/utils/llm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
87
87
|
hdl/utils/llm/chat.py,sha256=NEbWdrPpQqS5ArU7ghA6xuam8wwvWXk3LL_CiNEEuIg,7055
|
88
|
+
hdl/utils/llm/embs.py,sha256=TB3SnD-DZ_d8uV-UT63Q_8SECFDAOzsWev4SbPj3-ug,1605
|
88
89
|
hdl/utils/schedulers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
89
90
|
hdl/utils/schedulers/norm_lr.py,sha256=bDwCmdEK-WkgxQMFBiMuchv8Mm7C0-GZJ6usm-PQk14,4461
|
90
|
-
hjxdl-0.0.
|
91
|
-
hjxdl-0.0.
|
92
|
-
hjxdl-0.0.
|
93
|
-
hjxdl-0.0.
|
91
|
+
hjxdl-0.0.13.dist-info/METADATA,sha256=vg17dj7a7mLuDjaMgh1lSNe8wIWqInI3Xjvnw16lNiI,543
|
92
|
+
hjxdl-0.0.13.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
|
93
|
+
hjxdl-0.0.13.dist-info/top_level.txt,sha256=-kxwTM5JPhylp06z3zAVO3w6_h7wtBfBo2zgM6YZoTk,4
|
94
|
+
hjxdl-0.0.13.dist-info/RECORD,,
|
File without changes
|
File without changes
|