zpn commited on
Commit
67e8aff
1 Parent(s): 72bd416

Add Sentence Transformers support (#2)

Browse files

- Increase model_max_length from 512 to 8192 (74d43807c92ef88423e6ab474db5b516eb70896d)
- Add return_dict to NomicBertModel; required for Sentence Transformers (cc70901626cf27a336a59983e1900bcb5834a364)
- Add Sentence Transformers support; add required files (bf6a73534d9d580c009ce67980a235dddc0ca49c)
- Update README + metadata (917a3bb4feca2915cec31d6e45d42d288b09a1ac)
- Merge branch 'main' of into integrations/sentence_transformers (89a809cbfa1e10d7c04a68c33caa6f044de3182a)

1_Pooling/config.json CHANGED
@@ -1,10 +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
- }
10
-
 
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
@@ -1,10 +1,16 @@
1
  ---
 
 
 
 
 
 
 
 
2
  license: apache-2.0
3
  language:
4
  - en
5
  inference: false
6
- tags:
7
- - mteb
8
  model-index:
9
  - name: epoch_0_model
10
  results:
@@ -2663,7 +2669,17 @@ Training data to train the models is released in its entirety. For more details,
2663
  Note `nomic-embed-text` requires prefixes! We support the prefixes `[search_query, search_document, classification, clustering]`.
2664
  For retrieval applications, you should prepend `search_document` for all your documents and `search_query` for your queries.
2665
 
 
 
 
 
 
 
 
 
 
2666
 
 
2667
  ```python
2668
  import torch
2669
  import torch.nn.functional as F
 
1
  ---
2
+ library_name: sentence-transformers
3
+ pipeline_tag: sentence-similarity
4
+ tags:
5
+ - feature-extraction
6
+ - sentence-similarity
7
+ - mteb
8
+ - transformers
9
+ - transformers.js
10
  license: apache-2.0
11
  language:
12
  - en
13
  inference: false
 
 
14
  model-index:
15
  - name: epoch_0_model
16
  results:
 
2669
  Note `nomic-embed-text` requires prefixes! We support the prefixes `[search_query, search_document, classification, clustering]`.
2670
  For retrieval applications, you should prepend `search_document` for all your documents and `search_query` for your queries.
2671
 
2672
+ ### Sentence Transformers
2673
+ ```python
2674
+ from sentence_transformers import SentenceTransformer
2675
+
2676
+ model = SentenceTransformer("nomic-ai/nomic-embed-text-v1-unsupervised", trust_remote_code=True)
2677
+ sentences = ['search_query: What is TSNE?', 'search_query: Who is Laurens van der Maaten?']
2678
+ embeddings = model.encode(sentences)
2679
+ print(embeddings)
2680
+ ```
2681
 
2682
+ ### Transformers
2683
  ```python
2684
  import torch
2685
  import torch.nn.functional as F
config_sentence_transformers.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "2.4.0.dev0",
4
+ "transformers": "4.37.2",
5
+ "pytorch": "2.1.0+cu121"
6
+ }
7
+ }
modeling_hf_nomic_bert.py CHANGED
@@ -1069,6 +1069,7 @@ class NomicBertModel(NomicBertPreTrainedModel):
1069
  position_ids=None,
1070
  token_type_ids=None,
1071
  attention_mask=None,
 
1072
  ):
1073
  if token_type_ids is None:
1074
  token_type_ids = torch.zeros_like(input_ids)
@@ -1080,7 +1081,7 @@ class NomicBertModel(NomicBertPreTrainedModel):
1080
 
1081
  attention_mask = self.get_extended_attention_mask(attention_mask, input_ids.shape)
1082
  sequence_output = self.encoder(
1083
- hidden_states, attention_mask=attention_mask
1084
  )
1085
 
1086
  pooled_output = self.pooler(sequence_output) if self.pooler is not None else None
 
1069
  position_ids=None,
1070
  token_type_ids=None,
1071
  attention_mask=None,
1072
+ return_dict=None,
1073
  ):
1074
  if token_type_ids is None:
1075
  token_type_ids = torch.zeros_like(input_ids)
 
1081
 
1082
  attention_mask = self.get_extended_attention_mask(attention_mask, input_ids.shape)
1083
  sequence_output = self.encoder(
1084
+ hidden_states, attention_mask=attention_mask, return_dict=return_dict,
1085
  )
1086
 
1087
  pooled_output = self.pooler(sequence_output) if self.pooler is not None else None
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": 8192,
3
+ "do_lower_case": false
4
+ }
tokenizer_config.json CHANGED
@@ -46,7 +46,7 @@
46
  "cls_token": "[CLS]",
47
  "do_lower_case": true,
48
  "mask_token": "[MASK]",
49
- "model_max_length": 512,
50
  "pad_token": "[PAD]",
51
  "sep_token": "[SEP]",
52
  "strip_accents": null,
 
46
  "cls_token": "[CLS]",
47
  "do_lower_case": true,
48
  "mask_token": "[MASK]",
49
+ "model_max_length": 8192,
50
  "pad_token": "[PAD]",
51
  "sep_token": "[SEP]",
52
  "strip_accents": null,