Tom Aarsen commited on
Commit
90cddb8
1 Parent(s): a5e1612

Integrate with Sentence Transformers + 3rd parties

Browse files
1_Pooling/config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "word_embedding_dimension": 4096,
3
+ "pooling_mode_cls_token": false,
4
+ "pooling_mode_mean_tokens": false,
5
+ "pooling_mode_max_tokens": false,
6
+ "pooling_mode_mean_sqrt_len_tokens": false,
7
+ "pooling_mode_weightedmean_tokens": false,
8
+ "pooling_mode_lasttoken": true,
9
+ "include_prompt": true
10
+ }
README.md CHANGED
@@ -1,6 +1,8 @@
1
  ---
2
  tags:
3
  - mteb
 
 
4
  model-index:
5
  - name: e5-mistral-7b-instruct
6
  results:
@@ -6851,6 +6853,36 @@ This model has 32 layers and the embedding size is 4096.
6851
 
6852
  Below is an example to encode queries and passages from the MS-MARCO passage ranking dataset.
6853
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6854
  ```python
6855
  import torch
6856
  import torch.nn.functional as F
 
1
  ---
2
  tags:
3
  - mteb
4
+ - sentence-transformers
5
+ - transformers
6
  model-index:
7
  - name: e5-mistral-7b-instruct
8
  results:
 
6853
 
6854
  Below is an example to encode queries and passages from the MS-MARCO passage ranking dataset.
6855
 
6856
+ ### Sentence Transformers
6857
+
6858
+ ```python
6859
+ from sentence_transformers import SentenceTransformer
6860
+
6861
+ model = SentenceTransformer("intfloat/e5-mistral-7b-instruct")
6862
+ # In case you want to reduce the maximum sequence length:
6863
+ model.max_seq_length = 4096
6864
+
6865
+ queries = [
6866
+ "how much protein should a female eat",
6867
+ "summit define",
6868
+ ]
6869
+ documents = [
6870
+ "As a general guideline, the CDC's average requirement of protein for women ages 19 to 70 is 46 grams per day. But, as you can see from this chart, you'll need to increase that if you're expecting or training for a marathon. Check out the chart below to see how much protein you should be eating each day.",
6871
+ "Definition of summit for English Language Learners. : 1 the highest point of a mountain : the top of a mountain. : 2 the highest level. : 3 a meeting or series of meetings between the leaders of two or more governments."
6872
+ ]
6873
+
6874
+ query_embeddings = model.encode(queries, prompt_name="web_search_query")
6875
+ document_embeddings = model.encode(documents)
6876
+
6877
+ scores = (query_embeddings @ document_embeddings.T) * 100
6878
+ print(scores.tolist())
6879
+ ```
6880
+
6881
+ Have a look at [config_sentence_transformers.json](config_sentence_transformers.json) for the prompts that are pre-configured, such as `web_search_query`, `sts_query`, and `summarization_query`. Additionally, check out [unilm/e5/utils.py](https://github.com/microsoft/unilm/blob/9c0f1ff7ca53431fe47d2637dfe253643d94185b/e5/utils.py#L106) for prompts we used for evaluation. You can use these via e.g. `model.encode(queries, prompt="Instruct: Given a claim, find documents that refute the claim\nQuery: ")`.
6882
+
6883
+
6884
+ ### Transformers
6885
+
6886
  ```python
6887
  import torch
6888
  import torch.nn.functional as F
config_sentence_transformers.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "2.8.0.dev0",
4
+ "transformers": "4.39.3",
5
+ "pytorch": "2.1.0+cu121"
6
+ },
7
+ "prompts": {
8
+ "web_search_query": "Instruct: Given a web search query, retrieve relevant passages that answer the query\nQuery: ",
9
+ "sts_query": "Instruct: Retrieve semantically similar text.\nQuery: ",
10
+ "summarization_query": "Instruct: Given a news summary, retrieve other semantically similar summaries\nQuery: ",
11
+ "bitext_query": "Instruct: Retrieve parallel sentences.\nQuery: "
12
+ },
13
+ "default_prompt_name": null
14
+ }
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": 32768,
3
+ "do_lower_case": false
4
+ }