Ranker Module¶
pipelines.pipelines.nodes.ranker.ernie_ranker ¶
ErnieRanker ¶
Re-Ranking can be used on top of a retriever to boost the performance for document search. This is particularly useful if the retriever has a high recall but is bad in sorting the documents by relevance.
Usage example: ... retriever = ElasticsearchRetriever(document_store=document_store) ranker = SentenceTransformersRanker(model_name_or_path="rocketqa-zh-dureader-cross-encoder") p = Pipeline() p.add_node(component=retriever, name="ESRetriever", inputs=["Query"]) p.add_node(component=ranker, name="Ranker", inputs=["ESRetriever"])
Source code in pipelines/pipelines/nodes/ranker/ernie_ranker.py
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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
__init__ ¶
__init__(model_name_or_path: Union[str, Path], top_k: int = 10, use_gpu: bool = True, max_seq_len: int = 512, progress_bar: bool = True, batch_size: int = 1000, reinitialize: bool = False, embed_title: bool = False, use_en: bool = False)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name_or_path |
Union[str, Path]
|
Directory of a saved model or the name of a public model e.g. 'rocketqa-zh-dureader-cross-encoder'. |
required |
top_k |
int
|
The maximum number of documents to return |
10
|
use_gpu |
bool
|
Whether to use all available GPUs or the CPU. Falls back on CPU if no GPU is available. |
True
|
Source code in pipelines/pipelines/nodes/ranker/ernie_ranker.py
predict ¶
Use loaded ranker model to re-rank the supplied list of Document.
Returns list of Document sorted by (desc.) similarity with the query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query |
str
|
Query string |
required |
documents |
List[Document]
|
List of Document to be re-ranked |
required |
top_k |
Optional[int]
|
The maximum number of documents to return |
None
|
Returns:
| Type | Description |
|---|---|
List[Document]
|
List of Document |
Source code in pipelines/pipelines/nodes/ranker/ernie_ranker.py
predict_batch ¶
predict_batch(queries: List[str], documents: Union[List[Document], List[List[Document]]], top_k: Optional[int] = None, batch_size: Optional[int] = None) -> Union[List[Document], List[List[Document]]]
Use loaded ranker model to re-rank the supplied lists of Documents
Returns lists of Documents sorted by (desc.) similarity with the corresponding queries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
queries |
List[str]
|
Single query string or list of queries |
required |
documents |
Union[List[Document], List[List[Document]]]
|
Single list of Documents or list of lists of Documents to be reranked. |
required |
top_k |
Optional[int]
|
The maximum number of documents to return per Document list. |
None
|
batch_size |
Optional[int]
|
Number of Documents to process at a time. |
None
|