antoinelouis
commited on
Commit
•
39fea10
1
Parent(s):
fb7755c
Update README.md
Browse files
README.md
CHANGED
@@ -1,69 +1,83 @@
|
|
1 |
---
|
2 |
-
pipeline_tag:
|
3 |
language: fr
|
4 |
-
license:
|
5 |
datasets:
|
6 |
- unicamp-dl/mmarco
|
7 |
metrics:
|
8 |
- recall
|
9 |
tags:
|
10 |
-
-
|
11 |
library_name: sentence-transformers
|
|
|
12 |
---
|
13 |
-
# crossencoder-distilcamembert-mmarcoFR
|
14 |
|
15 |
-
|
16 |
|
17 |
-
It performs cross-attention between a question-passage pair and outputs a relevance score
|
|
|
|
|
|
|
18 |
|
19 |
## Usage
|
20 |
-
***
|
21 |
-
|
22 |
-
#### Sentence-Transformers
|
23 |
|
24 |
-
|
25 |
|
26 |
-
|
27 |
-
pip install -U sentence-transformers
|
28 |
-
```
|
29 |
|
30 |
-
Then you can use the model like this:
|
31 |
|
32 |
```python
|
33 |
from sentence_transformers import CrossEncoder
|
34 |
-
|
|
|
35 |
|
36 |
model = CrossEncoder('antoinelouis/crossencoder-distilcamembert-mmarcoFR')
|
37 |
scores = model.predict(pairs)
|
38 |
print(scores)
|
39 |
```
|
40 |
|
41 |
-
####
|
42 |
|
43 |
-
|
44 |
|
45 |
```python
|
46 |
-
from
|
47 |
-
import torch
|
48 |
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
54 |
|
|
|
|
|
55 |
model.eval()
|
|
|
56 |
with torch.no_grad():
|
57 |
-
|
|
|
58 |
print(scores)
|
59 |
```
|
60 |
|
61 |
-
## Evaluation
|
62 |
***
|
63 |
|
64 |
-
|
65 |
|
66 |
-
|
|
|
|
|
67 |
|
68 |
| | model | Vocab. | #Param. | Size | RP | MRR@10 | R@10(↑) | R@20 | R@50 | R@100 |
|
69 |
|---:|:-----------------------------------------------------------------------------------------------------------------------------|:-------|--------:|------:|-------:|---------:|---------:|-------:|-------:|--------:|
|
@@ -74,23 +88,27 @@ Below, we compare the model performance with other cross-encoder models fine-tun
|
|
74 |
| 5 | [crossencoder-electra-base-french-mmarcoFR](https://huggingface.co/antoinelouis/crossencoder-electra-base-french-mmarcoFR) | fr | 110M | 443MB | 28.32 | 45.28 | 79.22 | 87.15 | 93.15 | 95.75 |
|
75 |
| 6 | [crossencoder-mMiniLMv2-L6-mmarcoFR](https://huggingface.co/antoinelouis/crossencoder-mMiniLMv2-L6-mmarcoFR) | fr,99+ | 107M | 428MB | 33.92 | 49.33 | 79.00 | 88.35 | 94.80 | 98.20 |
|
76 |
|
77 |
-
## Training
|
78 |
***
|
79 |
|
80 |
-
|
81 |
|
82 |
-
|
83 |
|
84 |
-
|
|
|
|
|
|
|
85 |
|
86 |
-
|
87 |
|
88 |
-
|
|
|
|
|
|
|
89 |
|
90 |
-
|
91 |
|
92 |
## Citation
|
93 |
-
***
|
94 |
|
95 |
```bibtex
|
96 |
@online{louis2023,
|
|
|
1 |
---
|
2 |
+
pipeline_tag: text-classification
|
3 |
language: fr
|
4 |
+
license: mit
|
5 |
datasets:
|
6 |
- unicamp-dl/mmarco
|
7 |
metrics:
|
8 |
- recall
|
9 |
tags:
|
10 |
+
- passage-reranking
|
11 |
library_name: sentence-transformers
|
12 |
+
base_model: camembert-base
|
13 |
---
|
|
|
14 |
|
15 |
+
# crossencoder-distilcamembert-mmarcoFR
|
16 |
|
17 |
+
This is a cross-encoder model for French. It performs cross-attention between a question-passage pair and outputs a relevance score.
|
18 |
+
The model should be used as a reranker for semantic search: given a query and a set of potentially relevant passages retrieved by an efficient first-stage
|
19 |
+
retrieval system (e.g., BM25 or a fine-tuned dense single-vector bi-encoder), encode each query-passage pair and sort the passages in a decreasing order of
|
20 |
+
relevance according to the model's predicted scores.
|
21 |
|
22 |
## Usage
|
|
|
|
|
|
|
23 |
|
24 |
+
Here are some examples for using the model with [Sentence-Transformers](#using-sentence-transformers), [FlagEmbedding](#using-flagembedding), or [Huggingface Transformers](#using-huggingface-transformers).
|
25 |
|
26 |
+
#### Using Sentence-Transformers
|
|
|
|
|
27 |
|
28 |
+
Start by installing the [library](https://www.SBERT.net): `pip install -U sentence-transformers`. Then, you can use the model like this:
|
29 |
|
30 |
```python
|
31 |
from sentence_transformers import CrossEncoder
|
32 |
+
|
33 |
+
pairs = [('Question', 'Paragraphe 1'), ('Question', 'Paragraphe 2') , ('Question', 'Paragraphe 3')]
|
34 |
|
35 |
model = CrossEncoder('antoinelouis/crossencoder-distilcamembert-mmarcoFR')
|
36 |
scores = model.predict(pairs)
|
37 |
print(scores)
|
38 |
```
|
39 |
|
40 |
+
#### Using FlagEmbedding
|
41 |
|
42 |
+
Start by installing the [library](https://github.com/FlagOpen/FlagEmbedding/): `pip install -U FlagEmbedding`. Then, you can use the model like this:
|
43 |
|
44 |
```python
|
45 |
+
from FlagEmbedding import FlagReranker
|
|
|
46 |
|
47 |
+
pairs = [('Question', 'Paragraphe 1'), ('Question', 'Paragraphe 2') , ('Question', 'Paragraphe 3')]
|
48 |
+
|
49 |
+
reranker = FlagReranker('antoinelouis/crossencoder-distilcamembert-mmarcoFR')
|
50 |
+
scores = reranker.compute_score(pairs)
|
51 |
+
print(scores)
|
52 |
+
```
|
53 |
+
|
54 |
+
#### Using HuggingFace Transformers
|
55 |
+
|
56 |
+
Start by installing the [library](https://huggingface.co/docs/transformers): `pip install -U transformers`. Then, you can use the model like this:
|
57 |
|
58 |
+
```python
|
59 |
+
import torch
|
60 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
61 |
+
|
62 |
+
pairs = [('Question', 'Paragraphe 1'), ('Question', 'Paragraphe 2') , ('Question', 'Paragraphe 3')]
|
63 |
|
64 |
+
tokenizer = AutoTokenizer.from_pretrained('antoinelouis/crossencoder-distilcamembert-mmarcoFR')
|
65 |
+
model = AutoModelForSequenceClassification.from_pretrained('antoinelouis/crossencoder-distilcamembert-mmarcoFR')
|
66 |
model.eval()
|
67 |
+
|
68 |
with torch.no_grad():
|
69 |
+
inputs = tokenizer(pairs, padding=True, truncation=True, return_tensors='pt', max_length=512)
|
70 |
+
scores = model(**inputs, return_dict=True).logits.view(-1, ).float()
|
71 |
print(scores)
|
72 |
```
|
73 |
|
|
|
74 |
***
|
75 |
|
76 |
+
## Evaluation
|
77 |
|
78 |
+
We evaluate the model on 500 random training queries from [mMARCO-fr](https://ir-datasets.com/mmarco.html#mmarco/v2/fr/) (which were excluded from training) by reranking
|
79 |
+
subsets of candidate passages comprising of at least one relevant and up to 200 BM25 negative passages for each query. Below, we compare the model performance with other
|
80 |
+
cross-encoder models fine-tuned on the same dataset. We report the R-precision (RP), mean reciprocal rank (MRR), and recall at various cut-offs (R@k).
|
81 |
|
82 |
| | model | Vocab. | #Param. | Size | RP | MRR@10 | R@10(↑) | R@20 | R@50 | R@100 |
|
83 |
|---:|:-----------------------------------------------------------------------------------------------------------------------------|:-------|--------:|------:|-------:|---------:|---------:|-------:|-------:|--------:|
|
|
|
88 |
| 5 | [crossencoder-electra-base-french-mmarcoFR](https://huggingface.co/antoinelouis/crossencoder-electra-base-french-mmarcoFR) | fr | 110M | 443MB | 28.32 | 45.28 | 79.22 | 87.15 | 93.15 | 95.75 |
|
89 |
| 6 | [crossencoder-mMiniLMv2-L6-mmarcoFR](https://huggingface.co/antoinelouis/crossencoder-mMiniLMv2-L6-mmarcoFR) | fr,99+ | 107M | 428MB | 33.92 | 49.33 | 79.00 | 88.35 | 94.80 | 98.20 |
|
90 |
|
|
|
91 |
***
|
92 |
|
93 |
+
## Training
|
94 |
|
95 |
+
#### Data
|
96 |
|
97 |
+
We use the French training samples from the [mMARCO](https://huggingface.co/datasets/unicamp-dl/mmarco) dataset, a multilingual machine-translated version of MS MARCO
|
98 |
+
that contains 8.8M passages and 539K training queries. We sample 1M question-passage pairs from the official ~39.8M
|
99 |
+
[training triples](https://microsoft.github.io/msmarco/Datasets.html#passage-ranking-dataset) with a positive-to-negative ratio of 4 (i.e., 25% of the pairs are
|
100 |
+
relevant and 75% are irrelevant).
|
101 |
|
102 |
+
#### Implementation
|
103 |
|
104 |
+
The model is initialized from the [cmarkea/distilcamembert-base](https://huggingface.co/cmarkea/distilcamembert-base) checkpoint and optimized via the binary cross-entropy loss
|
105 |
+
(as in [monoBERT](https://doi.org/10.48550/arXiv.1910.14424)). It is fine-tuned on one 32GB NVIDIA V100 GPU for 10 epochs (i.e., 312.4k steps) using the AdamW optimizer
|
106 |
+
with a batch size of 32, a peak learning rate of 2e-5 with warm up along the first 500 steps and linear scheduling. We set the maximum sequence length of the
|
107 |
+
concatenated question-passage pairs to 512 tokens. We use the sigmoid function to get scores between 0 and 1.
|
108 |
|
109 |
+
***
|
110 |
|
111 |
## Citation
|
|
|
112 |
|
113 |
```bibtex
|
114 |
@online{louis2023,
|