hjxdl 0.0.12__py3-none-any.whl → 0.0.14__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 +71 -0
- {hjxdl-0.0.12.dist-info → hjxdl-0.0.14.dist-info}/METADATA +1 -1
- {hjxdl-0.0.12.dist-info → hjxdl-0.0.14.dist-info}/RECORD +6 -5
- {hjxdl-0.0.12.dist-info → hjxdl-0.0.14.dist-info}/WHEEL +0 -0
- {hjxdl-0.0.12.dist-info → hjxdl-0.0.14.dist-info}/top_level.txt +0 -0
hdl/_version.py
CHANGED
hdl/utils/llm/embs.py
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
class FlagEmbedder():
|
2
|
+
def __init__(
|
3
|
+
self,
|
4
|
+
emb_name: str = "bge",
|
5
|
+
emb_dir: str = None
|
6
|
+
) -> None:
|
7
|
+
"""Initializes the object with the specified embedding name and directory.
|
8
|
+
|
9
|
+
Args:
|
10
|
+
emb_name (str): The name of the embedding. Defaults to "bge".
|
11
|
+
emb_dir (str): The directory path for the embedding model.
|
12
|
+
|
13
|
+
Returns:
|
14
|
+
None
|
15
|
+
"""
|
16
|
+
self.emb_name = emb_name
|
17
|
+
self.emb_dir = emb_dir
|
18
|
+
|
19
|
+
if "bge" in emb_name.lower():
|
20
|
+
from FlagEmbedding import BGEM3FlagModel
|
21
|
+
self.model = BGEM3FlagModel(
|
22
|
+
emb_dir,
|
23
|
+
use_fp16=True
|
24
|
+
)
|
25
|
+
elif "bce" in emb_name.lower():
|
26
|
+
from BCEmbedding import EmbeddingModel
|
27
|
+
self.model = EmbeddingModel(
|
28
|
+
model_name_or_path=emb_dir,
|
29
|
+
use_fp16=True
|
30
|
+
)
|
31
|
+
|
32
|
+
def encode(
|
33
|
+
self,
|
34
|
+
sentences
|
35
|
+
):
|
36
|
+
"""Encode the input sentences using the model.
|
37
|
+
|
38
|
+
Args:
|
39
|
+
sentences (list): List of sentences to encode.
|
40
|
+
|
41
|
+
Returns:
|
42
|
+
numpy.ndarray: Encoded representation of the input sentences.
|
43
|
+
"""
|
44
|
+
output = self.model.encode(
|
45
|
+
sentences,
|
46
|
+
return_dense=True,
|
47
|
+
return_sparse=True,
|
48
|
+
return_colbert_vecs=False
|
49
|
+
)
|
50
|
+
if "bge" in self.emb_name.lower():
|
51
|
+
return output["dense_vecs"]
|
52
|
+
return output
|
53
|
+
|
54
|
+
def sim(
|
55
|
+
self,
|
56
|
+
sentences_1,
|
57
|
+
sentences_2
|
58
|
+
):
|
59
|
+
"""Calculate the similarity between two sets of sentences.
|
60
|
+
|
61
|
+
Args:
|
62
|
+
sentences_1 (list): List of sentences for the first set.
|
63
|
+
sentences_2 (list): List of sentences for the second set.
|
64
|
+
|
65
|
+
Returns:
|
66
|
+
float: Similarity score between the two sets of sentences.
|
67
|
+
"""
|
68
|
+
output_1 = self.encode(sentences_1)
|
69
|
+
output_2 = self.encode(sentences_2)
|
70
|
+
similarity = output_1 @ output_2.T
|
71
|
+
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=Z5KVh4ecKbPlzksuEdQrX-Mm8ihZCLuudKr2xk8fqgc,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=rkMDaQIVX7cmTEtOhTBzqZYwouOzO3ox0DpJ493BXrs,2124
|
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.14.dist-info/METADATA,sha256=0mn1FFKnA5m5jqrIqlh-XioiqkonZ3DXD6I770Q62Xc,543
|
92
|
+
hjxdl-0.0.14.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
|
93
|
+
hjxdl-0.0.14.dist-info/top_level.txt,sha256=-kxwTM5JPhylp06z3zAVO3w6_h7wtBfBo2zgM6YZoTk,4
|
94
|
+
hjxdl-0.0.14.dist-info/RECORD,,
|
File without changes
|
File without changes
|