init
Browse files- 1_Pooling/config.json +7 -0
- README.md +87 -3
- config.json +32 -0
- config_sentence_transformers.json +7 -0
- modules.json +14 -0
- pytorch_model.bin +3 -0
- sentence_bert_config.json +4 -0
- special_tokens_map.json +7 -0
- tokenizer.json +0 -0
- tokenizer_config.json +15 -0
- vocab.txt +0 -0
1_Pooling/config.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"word_embedding_dimension": 1024,
|
3 |
+
"pooling_mode_cls_token": true,
|
4 |
+
"pooling_mode_mean_tokens": false,
|
5 |
+
"pooling_mode_max_tokens": false,
|
6 |
+
"pooling_mode_mean_sqrt_len_tokens": false
|
7 |
+
}
|
README.md
CHANGED
@@ -1,3 +1,87 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ember-v1
|
2 |
+
|
3 |
+
<p align="center">
|
4 |
+
<img src="https://console.llmrails.com/assets/img/logo-black.svg" width="150px">
|
5 |
+
</p>
|
6 |
+
|
7 |
+
This model is trained on a large-scale corpus of relevance text pairs, covering a wide range of domains like financial, scientific, medical, legal and others. While training we used some technics from Retromae and SetFit papers.
|
8 |
+
|
9 |
+
We are also providing it on our own platform as API as a service, feel free to signup: [LLMRails](https://llmrails.com/?ref=ember-v1).
|
10 |
+
|
11 |
+
### Plans
|
12 |
+
- Paper will be published soon
|
13 |
+
- v2 is on it's way with 4k maximum sequence length
|
14 |
+
|
15 |
+
## Usage
|
16 |
+
Use with API request:
|
17 |
+
```bash
|
18 |
+
curl --location 'https://api.llmrails.com/v1/embeddings' \
|
19 |
+
--header 'X-API-KEY: {token}' \
|
20 |
+
--header 'Content-Type: application/json' \
|
21 |
+
--data '{
|
22 |
+
"input": ["This is an example sentence"],
|
23 |
+
"model":"embedding-english-v1" # equals to ember-v1
|
24 |
+
}'
|
25 |
+
```
|
26 |
+
API docs: https://docs.llmrails.com/embedding/embed-text
|
27 |
+
Langchain plugin: https://python.langchain.com/docs/integrations/text_embedding/llm_rails
|
28 |
+
|
29 |
+
Use with transformers:
|
30 |
+
```python
|
31 |
+
import torch.nn.functional as F
|
32 |
+
from torch import Tensor
|
33 |
+
from transformers import AutoTokenizer, AutoModel
|
34 |
+
|
35 |
+
def average_pool(last_hidden_states: Tensor,
|
36 |
+
attention_mask: Tensor) -> Tensor:
|
37 |
+
last_hidden = last_hidden_states.masked_fill(~attention_mask[..., None].bool(), 0.0)
|
38 |
+
return last_hidden.sum(dim=1) / attention_mask.sum(dim=1)[..., None]
|
39 |
+
|
40 |
+
input_texts = [
|
41 |
+
"This is an example sentence",
|
42 |
+
"Each sentence is converted"
|
43 |
+
]
|
44 |
+
|
45 |
+
tokenizer = AutoTokenizer.from_pretrained("llmrails/ember-v1")
|
46 |
+
model = AutoModel.from_pretrained("llmrails/ember-v1")
|
47 |
+
|
48 |
+
# Tokenize the input texts
|
49 |
+
batch_dict = tokenizer(input_texts, max_length=512, padding=True, truncation=True, return_tensors='pt')
|
50 |
+
|
51 |
+
outputs = model(**batch_dict)
|
52 |
+
embeddings = average_pool(outputs.last_hidden_state, batch_dict['attention_mask'])
|
53 |
+
|
54 |
+
# (Optionally) normalize embeddings
|
55 |
+
embeddings = F.normalize(embeddings, p=2, dim=1)
|
56 |
+
scores = (embeddings[:1] @ embeddings[1:].T) * 100
|
57 |
+
print(scores.tolist())
|
58 |
+
```
|
59 |
+
|
60 |
+
Use with sentence-transformers:
|
61 |
+
```python
|
62 |
+
from sentence_transformers import SentenceTransformer
|
63 |
+
from sentence_transformers.util import cos_sim
|
64 |
+
|
65 |
+
sentences = [
|
66 |
+
"This is an example sentence",
|
67 |
+
"Each sentence is converted"
|
68 |
+
]
|
69 |
+
|
70 |
+
model = SentenceTransformer('llmrails/ember-v1')
|
71 |
+
embeddings = model.encode(sentences)
|
72 |
+
print(cos_sim(embeddings[0], embeddings[1]))
|
73 |
+
```
|
74 |
+
|
75 |
+
## Massive Text Embedding Benchmark (MTEB) Evaluation
|
76 |
+
Our model achieve state-of-the-art performance on [MTEB leaderboard](https://huggingface.co/spaces/mteb/leaderboard)
|
77 |
+
|
78 |
+
| Model Name | Dimension | Sequence Length | Average (56) |
|
79 |
+
|:-----------------------------------------------------------------------:|:---------:|:---:|:------------:|
|
80 |
+
| [bge-large-en-v1.5](https://huggingface.co/BAAI/bge-large-en-v1.5) | 1024 | 512 | 64.23 |
|
81 |
+
| [bge-base-en-v1.5](https://huggingface.co/BAAI/bge-base-en-v1.5) | 768 | 512 | 63.55 |
|
82 |
+
| [ember-v1](https://huggingface.co/llmrails/emmbedding-en-v1) | 1024 | 512 | **63.54** |
|
83 |
+
| [text-embedding-ada-002](https://platform.openai.com/docs/guides/embeddings/types-of-embedding-models) | 1536 | 8191 | 60.99 |
|
84 |
+
|
85 |
+
### Limitation
|
86 |
+
|
87 |
+
This model exclusively caters to English texts, and any lengthy texts will be truncated to a maximum of 512 tokens.
|
config.json
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "/root/.cache/torch/sentence_transformers/llmrails_luna-v1/",
|
3 |
+
"architectures": [
|
4 |
+
"BertModel"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"classifier_dropout": null,
|
8 |
+
"gradient_checkpointing": false,
|
9 |
+
"hidden_act": "gelu",
|
10 |
+
"hidden_dropout_prob": 0.1,
|
11 |
+
"hidden_size": 1024,
|
12 |
+
"id2label": {
|
13 |
+
"0": "LABEL_0"
|
14 |
+
},
|
15 |
+
"initializer_range": 0.02,
|
16 |
+
"intermediate_size": 4096,
|
17 |
+
"label2id": {
|
18 |
+
"LABEL_0": 0
|
19 |
+
},
|
20 |
+
"layer_norm_eps": 1e-12,
|
21 |
+
"max_position_embeddings": 512,
|
22 |
+
"model_type": "bert",
|
23 |
+
"num_attention_heads": 16,
|
24 |
+
"num_hidden_layers": 24,
|
25 |
+
"pad_token_id": 0,
|
26 |
+
"position_embedding_type": "absolute",
|
27 |
+
"torch_dtype": "float32",
|
28 |
+
"transformers_version": "4.33.2",
|
29 |
+
"type_vocab_size": 2,
|
30 |
+
"use_cache": true,
|
31 |
+
"vocab_size": 30522
|
32 |
+
}
|
config_sentence_transformers.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"__version__": {
|
3 |
+
"sentence_transformers": "2.2.2",
|
4 |
+
"transformers": "4.28.1",
|
5 |
+
"pytorch": "1.13.0+cu117"
|
6 |
+
}
|
7 |
+
}
|
modules.json
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
]
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:63cd396b456f848b7e643f3d6a703a01c7b08337519ee1bf5accbc12c8ea1998
|
3 |
+
size 1340699369
|
sentence_bert_config.json
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"max_seq_length": 512,
|
3 |
+
"do_lower_case": true
|
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,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"clean_up_tokenization_spaces": true,
|
3 |
+
"cls_token": "[CLS]",
|
4 |
+
"do_basic_tokenize": true,
|
5 |
+
"do_lower_case": true,
|
6 |
+
"mask_token": "[MASK]",
|
7 |
+
"model_max_length": 512,
|
8 |
+
"never_split": null,
|
9 |
+
"pad_token": "[PAD]",
|
10 |
+
"sep_token": "[SEP]",
|
11 |
+
"strip_accents": null,
|
12 |
+
"tokenize_chinese_chars": true,
|
13 |
+
"tokenizer_class": "BertTokenizer",
|
14 |
+
"unk_token": "[UNK]"
|
15 |
+
}
|
vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|