upload models
Browse files- README.md +74 -0
- config.json +25 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +1 -0
- tokenizer.json +0 -0
- tokenizer_config.json +1 -0
- vocab.txt +0 -0
README.md
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# E5-large-unsupervised
|
2 |
+
|
3 |
+
**This model is similar to [e5-large](https://huggingface.co/intfloat/e5-large) but without supervised fine-tuning.**
|
4 |
+
|
5 |
+
[Text Embeddings by Weakly-Supervised Contrastive Pre-training](https://arxiv.org/pdf/2212.03533.pdf).
|
6 |
+
Liang Wang, Nan Yang, Xiaolong Huang, Binxing Jiao, Linjun Yang, Daxin Jiang, Rangan Majumder, Furu Wei, arXiv 2022
|
7 |
+
|
8 |
+
This model has 24 layers and the embedding size is 1024.
|
9 |
+
|
10 |
+
## Usage
|
11 |
+
|
12 |
+
Below is an example to encode queries and passages from the MS-MARCO passage ranking dataset.
|
13 |
+
|
14 |
+
```python
|
15 |
+
import torch.nn.functional as F
|
16 |
+
|
17 |
+
from torch import Tensor
|
18 |
+
from transformers import AutoTokenizer, AutoModel
|
19 |
+
|
20 |
+
|
21 |
+
def average_pool(last_hidden_states: Tensor,
|
22 |
+
attention_mask: Tensor) -> Tensor:
|
23 |
+
last_hidden = last_hidden_states.masked_fill(~attention_mask[..., None].bool(), 0.0)
|
24 |
+
return last_hidden.sum(dim=1) / attention_mask.sum(dim=1)[..., None]
|
25 |
+
|
26 |
+
|
27 |
+
# Each input text should start with "query: " or "passage: ".
|
28 |
+
# For tasks other than retrieval, you can simply use the "query: " prefix.
|
29 |
+
input_texts = ['query: how much protein should a female eat',
|
30 |
+
'query: summit define',
|
31 |
+
"passage: 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.",
|
32 |
+
"passage: 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."]
|
33 |
+
|
34 |
+
tokenizer = AutoTokenizer.from_pretrained('intfloat/e5-large-unsupervised')
|
35 |
+
model = AutoModel.from_pretrained('intfloat/e5-large-unsupervised')
|
36 |
+
|
37 |
+
# Tokenize the input texts
|
38 |
+
batch_dict = tokenizer(input_texts, max_length=512, padding=True, truncation=True, return_tensors='pt')
|
39 |
+
|
40 |
+
outputs = model(**batch_dict)
|
41 |
+
embeddings = average_pool(outputs.last_hidden_state, batch_dict['attention_mask'])
|
42 |
+
|
43 |
+
# (Optionally) normalize embeddings
|
44 |
+
embeddings = F.normalize(embeddings, p=2, dim=1)
|
45 |
+
scores = (embeddings[:2] @ embeddings[2:].T) * 100
|
46 |
+
print(scores.tolist())
|
47 |
+
```
|
48 |
+
|
49 |
+
## Training Details
|
50 |
+
|
51 |
+
Please refer to our paper at [https://arxiv.org/pdf/2212.03533.pdf](https://arxiv.org/pdf/2212.03533.pdf).
|
52 |
+
|
53 |
+
## Benchmark Evaluation
|
54 |
+
|
55 |
+
Check out [unilm/e5](https://github.com/microsoft/unilm/tree/master/e5) to reproduce evaluation results
|
56 |
+
on the [BEIR](https://arxiv.org/abs/2104.08663) and [MTEB benchmark](https://arxiv.org/abs/2210.07316).
|
57 |
+
|
58 |
+
## Citation
|
59 |
+
|
60 |
+
If you find our paper or models helpful, please consider cite as follows:
|
61 |
+
|
62 |
+
```
|
63 |
+
@article{wang2022text,
|
64 |
+
title={Text Embeddings by Weakly-Supervised Contrastive Pre-training},
|
65 |
+
author={Wang, Liang and Yang, Nan and Huang, Xiaolong and Jiao, Binxing and Yang, Linjun and Jiang, Daxin and Majumder, Rangan and Wei, Furu},
|
66 |
+
journal={arXiv preprint arXiv:2212.03533},
|
67 |
+
year={2022}
|
68 |
+
}
|
69 |
+
```
|
70 |
+
|
71 |
+
## Limitations
|
72 |
+
|
73 |
+
This model only works for English texts. Long texts will be truncated to at most 512 tokens.
|
74 |
+
|
config.json
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "../pretrain-retrievers/amlt/1101_large_qd_prompt_lr1e4_t001/pt_large",
|
3 |
+
"architectures": [
|
4 |
+
"BertModel"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"classifier_dropout": null,
|
8 |
+
"hidden_act": "gelu",
|
9 |
+
"hidden_dropout_prob": 0.1,
|
10 |
+
"hidden_size": 1024,
|
11 |
+
"initializer_range": 0.02,
|
12 |
+
"intermediate_size": 4096,
|
13 |
+
"layer_norm_eps": 1e-12,
|
14 |
+
"max_position_embeddings": 512,
|
15 |
+
"model_type": "bert",
|
16 |
+
"num_attention_heads": 16,
|
17 |
+
"num_hidden_layers": 24,
|
18 |
+
"pad_token_id": 0,
|
19 |
+
"position_embedding_type": "absolute",
|
20 |
+
"torch_dtype": "float32",
|
21 |
+
"transformers_version": "4.15.0",
|
22 |
+
"type_vocab_size": 2,
|
23 |
+
"use_cache": true,
|
24 |
+
"vocab_size": 30522
|
25 |
+
}
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8c9e11de6bbf725afdd0511ebe86b4d25ac28e027046cd537b8038e7fffd5117
|
3 |
+
size 1340718961
|
special_tokens_map.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]"}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"do_lower_case": true, "unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]", "tokenize_chinese_chars": true, "strip_accents": null, "model_max_length": 512, "special_tokens_map_file": null, "name_or_path": "../pretrain-retrievers/amlt/1101_large_qd_prompt_lr1e4_t001/pt_large", "tokenizer_class": "BertTokenizer"}
|
vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|