File size: 4,350 Bytes
5ddf7ff
 
 
697efdc
 
5ddf7ff
 
 
 
 
 
 
7ebe97d
5ddf7ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
---

language: "en"
tags:
- re-ranking
- passage-ranking
- knowledge-distillation
datasets:
- ms_marco
---


# Margin-MSE Trained DistilBERT-Cat (vanilla/mono/concatenated DistilBERT re-ranker)

We provide a retrieval trained DistilBERT-Cat model. Our model is trained with Margin-MSE using a 3 teacher BERT_Cat (concatenated BERT scoring) ensemble on MSMARCO-Passage.



This instance can be used to **re-rank a candidate set**. The architecure is a 6-layer DistilBERT, with an additional single linear layer at the end.



If you want to know more about our simple, yet effective knowledge distillation method for efficient information retrieval models for a variety of student architectures that is used for this model instance check out our paper: https://arxiv.org/abs/2010.02666 🎉



For more information, training data, source code, and a minimal usage example please visit: https://github.com/sebastian-hofstaetter/neural-ranking-kd



## Configuration



- fp16 trained, so fp16 inference shouldn't be a problem



## Model Code



````python

from transformers import AutoTokenizer,AutoModel, PreTrainedModel,PretrainedConfig

from typing import Dict

import torch



class BERT_Cat_Config(PretrainedConfig):

    model_type = "BERT_Cat"

    bert_model: str
    trainable: bool = True


class BERT_Cat(PreTrainedModel):

    """

    The vanilla/mono BERT concatenated (we lovingly refer to as BERT_Cat) architecture 
    -> requires input concatenation before model, so that batched input is possible

    """

    config_class = BERT_Cat_Config

    base_model_prefix = "bert_model"


    def __init__(self,

                 cfg) -> None:

        super().__init__(cfg)

        

        self.bert_model = AutoModel.from_pretrained(cfg.bert_model)


        for p in self.bert_model.parameters():

            p.requires_grad = cfg.trainable


        self._classification_layer = torch.nn.Linear(self.bert_model.config.hidden_size, 1)


    def forward(self,

                query_n_doc_sequence):


        vecs = self.bert_model(**query_n_doc_sequence)[0][:,0,:] # assuming a distilbert model here

        score = self._classification_layer(vecs)

        return score


tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased") # honestly not sure if that is the best way to go, but it works :)

model = BERT_Cat.from_pretrained("sebastian-hofstaetter/distilbert-cat-margin_mse-T2-msmarco")
````



## Effectiveness on MSMARCO Passage & TREC Deep Learning '19



We trained our model on the MSMARCO standard ("small"-400K query) training triples with knowledge distillation with a batch size of 32 on a single consumer-grade GPU (11GB memory).



For re-ranking we used the top-1000 BM25 results.



### MSMARCO-DEV



Here, we use the larger 49K query DEV set (same range as the smaller 7K DEV set, minimal changes possible)



|                                  | MRR@10 | NDCG@10 |

|----------------------------------|--------|---------|

| BM25                             | .194   | .241    |

| **Margin-MSE DistilBERT_Cat** (Re-ranking) | .391   | .451   |



### TREC-DL'19



For MRR we use the recommended binarization point of the graded relevance of 2. This might skew the results when compared to other binarization point numbers.



|                                  | MRR@10 | NDCG@10 |

|----------------------------------|--------|---------|

| BM25                             | .689   | .501    |

| **Margin-MSE DistilBERT_Cat** (Re-ranking) | .891   | .747    |



For more metrics, baselines, info and analysis, please see the paper: https://arxiv.org/abs/2010.02666



## Limitations & Bias



- The model inherits social biases from both DistilBERT and MSMARCO. 



- The model is only trained on relatively short passages of MSMARCO (avg. 60 words length), so it might struggle with longer text. 





## Citation



If you use our model checkpoint please cite our work as:



```
@misc{hofstaetter2020_crossarchitecture_kd,
      title={Improving Efficient Neural Ranking Models with Cross-Architecture Knowledge Distillation}, 

      author={Sebastian Hofst{\"a}tter and Sophia Althammer and Michael Schr{\"o}der and Mete Sertkan and Allan Hanbury},

      year={2020},

      eprint={2010.02666},

      archivePrefix={arXiv},

      primaryClass={cs.IR}

}

```