Tom Aarsen commited on
Commit
e6df3a0
1 Parent(s): 60492ba

Integrate with Sentence Transformers

Browse files
1_Pooling/config.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "word_embedding_dimension": 768,
3
+ "pooling_mode_cls_token": false,
4
+ "pooling_mode_mean_tokens": true,
5
+ "pooling_mode_max_tokens": false,
6
+ "pooling_mode_mean_sqrt_len_tokens": false,
7
+ "pooling_mode_weightedmean_tokens": false,
8
+ "pooling_mode_lasttoken": false
9
+ }
README.md CHANGED
@@ -45,7 +45,25 @@ Cost comparison of FastText and PEARL. The estimated memory is calculated by the
45
 
46
  ## Usage
47
 
48
- Below is an example of entity retrieval, and we reuse the code from E5.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  ```python
51
  import torch.nn.functional as F
 
45
 
46
  ## Usage
47
 
48
+ ### Sentence Transformers
49
+ PEARL is integrated with the Sentence Transformers library, and can be used like so:
50
+
51
+ ```python
52
+ from sentence_transformers import SentenceTransformer, util
53
+
54
+ query_texts = ["The New York Times"]
55
+ doc_texts = [ "NYTimes", "New York Post", "New York"]
56
+ input_texts = query_texts + doc_texts
57
+
58
+ model = SentenceTransformer("Lihuchen/pearl_base")
59
+ embeddings = model.encode(input_texts)
60
+ scores = util.cos_sim(embeddings[0], embeddings[1:]) * 100
61
+ print(scores.tolist())
62
+ # [[85.61601257324219, 73.65623474121094, 70.36174774169922]]
63
+ ```
64
+
65
+ ### Transformers
66
+ You can also use `transformers` to use PEARL. Below is an example of entity retrieval, and we reuse the code from E5.
67
 
68
  ```python
69
  import torch.nn.functional as F
config_sentence_transformers.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "2.3.1",
4
+ "transformers": "4.37.0",
5
+ "pytorch": "2.1.0+cu121"
6
+ }
7
+ }
modules.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "idx": 0,
4
+ "name": "0",
5
+ "path": "",
6
+ "type": "sentence_transformers.models.Transformer"
7
+ },
8
+ {
9
+ "idx": 1,
10
+ "name": "1",
11
+ "path": "1_Pooling",
12
+ "type": "sentence_transformers.models.Pooling"
13
+ },
14
+ {
15
+ "idx": 2,
16
+ "name": "2",
17
+ "path": "2_Normalize",
18
+ "type": "sentence_transformers.models.Normalize"
19
+ }
20
+ ]
sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_seq_length": 512,
3
+ "do_lower_case": false
4
+ }