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 CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.0.12'
16
- __version_tuple__ = version_tuple = (0, 0, 12)
15
+ __version__ = version = '0.0.13'
16
+ __version_tuple__ = version_tuple = (0, 0, 13)
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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hjxdl
3
- Version: 0.0.12
3
+ Version: 0.0.13
4
4
  Summary: A collection of functions for Jupyter notebooks
5
5
  Home-page: https://github.com/huluxiaohuowa/hdl
6
6
  Author: Jianxing Hu
@@ -1,5 +1,5 @@
1
1
  hdl/__init__.py,sha256=5sZZNySv08wwfzJcSDssGTqUn9wlmDsR6R4XB8J8mFM,70
2
- hdl/_version.py,sha256=J9AUd4fAuSymrNadeGqOirSMYNZ9WQmqXwLZX1sdsUk,413
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.12.dist-info/METADATA,sha256=a06qubt7_L4HGCpF0svsd1lGd4i6I0jurdc7fWV1wJg,543
91
- hjxdl-0.0.12.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
92
- hjxdl-0.0.12.dist-info/top_level.txt,sha256=-kxwTM5JPhylp06z3zAVO3w6_h7wtBfBo2zgM6YZoTk,4
93
- hjxdl-0.0.12.dist-info/RECORD,,
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