Add AutoTokenizer & Sentence Transformers support (#1)
Browse files- Add bert-base-uncased tokenizer (40ebbcabab30ca13000beac9811ee5ddfc0c531c)
- Add return_dict to NomicBertModel forward (20e35527c9a0212fe919ef1d3b3813b532a79612)
- Add files for Sentence Transformers integration (d43334a0322989a2b52e9ba6a2ee15c72d94ab6d)
- Also add a Normalize module (830f745af02d088a59d01244714f1acc7fa9735a)
- Update README metadata; allows for widget & "Use in Sentence Transformers" (45757a5edbda59f2eec844e0edced22bd4803537)
- Merge branch 'main' into integration/sentence_transformers (790cf31f166f3a5ba05760ea463260f8910f9067)
- Remove accidental .vscode push (d46c50ab01192d2570f274c66076f66e5306ab43)
- 1_Pooling/config.json +8 -9
- README.md +18 -3
- config_sentence_transformers.json +7 -0
- modeling_hf_nomic_bert.py +2 -1
- modules.json +20 -0
- sentence_bert_config.json +4 -0
- special_tokens_map.json +7 -0
- tokenizer.json +0 -0
- tokenizer_config.json +55 -0
- vocab.txt +0 -0
1_Pooling/config.json
CHANGED
@@ -1,10 +1,9 @@
|
|
1 |
{
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
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,6 +1,10 @@
|
|
1 |
---
|
|
|
|
|
2 |
tags:
|
3 |
-
-
|
|
|
|
|
4 |
model-index:
|
5 |
- name: epoch_0_model
|
6 |
results:
|
@@ -2655,6 +2659,17 @@ Training data to train the models is released in its entirety. For more details,
|
|
2655 |
|
2656 |
## Usage
|
2657 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2658 |
|
2659 |
```python
|
2660 |
import torch
|
@@ -2689,8 +2704,8 @@ The model natively supports scaling of the sequence length past 2048 tokens. To
|
|
2689 |
+ tokenizer = AutoTokenizer.from_pretrained('bert-base-uncased', model_max_length=8192)
|
2690 |
|
2691 |
|
2692 |
-
- model = AutoModel.from_pretrained('nomic-ai/nomic-embed-text-v1
|
2693 |
-
+ model = AutoModel.from_pretrained('nomic-ai/nomic-embed-text-v1
|
2694 |
```
|
2695 |
|
2696 |
# Join the Nomic Community
|
|
|
1 |
---
|
2 |
+
library_name: sentence-transformers
|
3 |
+
pipeline_tag: sentence-similarity
|
4 |
tags:
|
5 |
+
- feature-extraction
|
6 |
+
- sentence-similarity
|
7 |
+
- mteb
|
8 |
model-index:
|
9 |
- name: epoch_0_model
|
10 |
results:
|
|
|
2659 |
|
2660 |
## Usage
|
2661 |
|
2662 |
+
### Sentence Transformers
|
2663 |
+
```python
|
2664 |
+
from sentence_transformers import SentenceTransformer
|
2665 |
+
|
2666 |
+
model = SentenceTransformer("../nomic-embed-text-v1", trust_remote_code=True)
|
2667 |
+
sentences = ['What is TSNE?', 'Who is Laurens van der Maaten?']
|
2668 |
+
embeddings = model.encode(sentences)
|
2669 |
+
print(embeddings)
|
2670 |
+
```
|
2671 |
+
|
2672 |
+
### Transformers
|
2673 |
|
2674 |
```python
|
2675 |
import torch
|
|
|
2704 |
+ tokenizer = AutoTokenizer.from_pretrained('bert-base-uncased', model_max_length=8192)
|
2705 |
|
2706 |
|
2707 |
+
- model = AutoModel.from_pretrained('nomic-ai/nomic-embed-text-v1', trust_remote_code=True)
|
2708 |
+
+ model = AutoModel.from_pretrained('nomic-ai/nomic-embed-text-v1', trust_remote_code=True, rotary_scaling_factor=2)
|
2709 |
```
|
2710 |
|
2711 |
# Join the Nomic Community
|
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 |
+
}
|
special_tokens_map.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cls_token": "[CLS]",
|
3 |
+
"mask_token": "[MASK]",
|
4 |
+
"pad_token": "[PAD]",
|
5 |
+
"sep_token": "[SEP]",
|
6 |
+
"unk_token": "[UNK]"
|
7 |
+
}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"added_tokens_decoder": {
|
3 |
+
"0": {
|
4 |
+
"content": "[PAD]",
|
5 |
+
"lstrip": false,
|
6 |
+
"normalized": false,
|
7 |
+
"rstrip": false,
|
8 |
+
"single_word": false,
|
9 |
+
"special": true
|
10 |
+
},
|
11 |
+
"100": {
|
12 |
+
"content": "[UNK]",
|
13 |
+
"lstrip": false,
|
14 |
+
"normalized": false,
|
15 |
+
"rstrip": false,
|
16 |
+
"single_word": false,
|
17 |
+
"special": true
|
18 |
+
},
|
19 |
+
"101": {
|
20 |
+
"content": "[CLS]",
|
21 |
+
"lstrip": false,
|
22 |
+
"normalized": false,
|
23 |
+
"rstrip": false,
|
24 |
+
"single_word": false,
|
25 |
+
"special": true
|
26 |
+
},
|
27 |
+
"102": {
|
28 |
+
"content": "[SEP]",
|
29 |
+
"lstrip": false,
|
30 |
+
"normalized": false,
|
31 |
+
"rstrip": false,
|
32 |
+
"single_word": false,
|
33 |
+
"special": true
|
34 |
+
},
|
35 |
+
"103": {
|
36 |
+
"content": "[MASK]",
|
37 |
+
"lstrip": false,
|
38 |
+
"normalized": false,
|
39 |
+
"rstrip": false,
|
40 |
+
"single_word": false,
|
41 |
+
"special": true
|
42 |
+
}
|
43 |
+
},
|
44 |
+
"clean_up_tokenization_spaces": true,
|
45 |
+
"cls_token": "[CLS]",
|
46 |
+
"do_lower_case": true,
|
47 |
+
"mask_token": "[MASK]",
|
48 |
+
"model_max_length": 8192,
|
49 |
+
"pad_token": "[PAD]",
|
50 |
+
"sep_token": "[SEP]",
|
51 |
+
"strip_accents": null,
|
52 |
+
"tokenize_chinese_chars": true,
|
53 |
+
"tokenizer_class": "BertTokenizer",
|
54 |
+
"unk_token": "[UNK]"
|
55 |
+
}
|
vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|