Text Ranking
sentence-transformers
ONNX
Safetensors
OpenVINO
Transformers
English
electra
text-classification
custom_code
Instructions to use cross-encoder/monoelectra-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use cross-encoder/monoelectra-base with sentence-transformers:
from sentence_transformers import CrossEncoder model = CrossEncoder("cross-encoder/monoelectra-base", trust_remote_code=True) query = "Which planet is known as the Red Planet?" passages = [ "Venus is often called Earth's twin because of its similar size and proximity.", "Mars, known for its reddish appearance, is often referred to as the Red Planet.", "Jupiter, the largest planet in our solar system, has a prominent red spot.", "Saturn, famous for its rings, is sometimes mistaken for the Red Planet." ] scores = model.predict([(query, passage) for passage in passages]) print(scores) - Transformers
How to use cross-encoder/monoelectra-base with Transformers:
# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("cross-encoder/monoelectra-base", trust_remote_code=True) model = AutoModelForSequenceClassification.from_pretrained("cross-encoder/monoelectra-base", trust_remote_code=True) - Notebooks
- Google Colab
- Kaggle
Add new CrossEncoder model
Browse files- README.md +66 -66
- config.json +46 -46
- onnx/model.onnx +3 -0
- special_tokens_map.json +37 -37
- tokenizer_config.json +58 -57
README.md
CHANGED
|
@@ -1,67 +1,67 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
pipeline_tag: text-ranking
|
| 4 |
-
language:
|
| 5 |
-
- en
|
| 6 |
-
library_name: sentence-transformers
|
| 7 |
-
base_model:
|
| 8 |
-
- google/electra-base-discriminator
|
| 9 |
-
tags:
|
| 10 |
-
- transformers
|
| 11 |
-
---
|
| 12 |
-
|
| 13 |
-
## Cross-Encoder for Text Ranking
|
| 14 |
-
|
| 15 |
-
This model is a port of the [webis/monoelectra-base](https://huggingface.co/webis/monoelectra-base) model from [lightning-ir](https://github.com/webis-de/lightning-ir) to [Sentence Transformers](https://sbert.net/) and [Transformers](https://huggingface.co/docs/transformers).
|
| 16 |
-
|
| 17 |
-
The original model was introduced in the paper [A Systematic Investigation of Distilling Large Language Models into Cross-Encoders for Passage Re-ranking](https://arxiv.org/abs/2405.07920). See https://github.com/webis-de/rank-distillm for code used to train the original model.
|
| 18 |
-
|
| 19 |
-
The model can be used as a reranker in a 2-stage "retrieve-rerank" pipeline, where it reorders passages returned by a retriever model (e.g. an embedding model or BM25) given some query. See [SBERT.net Retrieve & Re-rank](https://www.sbert.net/examples/applications/retrieve_rerank/README.html) for more details.
|
| 20 |
-
|
| 21 |
-
## Usage with Sentence Transformers
|
| 22 |
-
|
| 23 |
-
The usage is easy when you have [SentenceTransformers](https://www.sbert.net/) installed.
|
| 24 |
-
|
| 25 |
-
```bash
|
| 26 |
-
pip install sentence-transformers
|
| 27 |
-
```
|
| 28 |
-
|
| 29 |
-
Then you can use the pre-trained model like this:
|
| 30 |
-
|
| 31 |
-
```python
|
| 32 |
-
from sentence_transformers import CrossEncoder
|
| 33 |
-
|
| 34 |
-
model = CrossEncoder("cross-encoder/monoelectra-base", trust_remote_code=True)
|
| 35 |
-
scores = model.predict([
|
| 36 |
-
("How many people live in Berlin?", "Berlin had a population of 3,520,031 registered inhabitants in an area of 891.82 square kilometers."),
|
| 37 |
-
("How many people live in Berlin?", "Berlin is well known for its museums."),
|
| 38 |
-
])
|
| 39 |
-
print(scores)
|
| 40 |
-
# [ 8.122868 -4.292924]
|
| 41 |
-
```
|
| 42 |
-
|
| 43 |
-
## Usage with Transformers
|
| 44 |
-
|
| 45 |
-
```python
|
| 46 |
-
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 47 |
-
import torch
|
| 48 |
-
|
| 49 |
-
model = AutoModelForSequenceClassification.from_pretrained("cross-encoder/monoelectra-base", trust_remote_code=True)
|
| 50 |
-
tokenizer = AutoTokenizer.from_pretrained("cross-encoder/monoelectra-base")
|
| 51 |
-
|
| 52 |
-
features = tokenizer(
|
| 53 |
-
[
|
| 54 |
-
("How many people live in Berlin?", "Berlin had a population of 3,520,031 registered inhabitants in an area of 891.82 square kilometers."),
|
| 55 |
-
("How many people live in Berlin?", "Berlin is well known for its museums."),
|
| 56 |
-
],
|
| 57 |
-
padding=True,
|
| 58 |
-
truncation=True,
|
| 59 |
-
return_tensors="pt",
|
| 60 |
-
)
|
| 61 |
-
|
| 62 |
-
model.eval()
|
| 63 |
-
with torch.no_grad():
|
| 64 |
-
scores = model(**features).logits.view(-1)
|
| 65 |
-
print(scores)
|
| 66 |
-
# tensor([ 8.1229, -4.2929])
|
| 67 |
```
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
pipeline_tag: text-ranking
|
| 4 |
+
language:
|
| 5 |
+
- en
|
| 6 |
+
library_name: sentence-transformers
|
| 7 |
+
base_model:
|
| 8 |
+
- google/electra-base-discriminator
|
| 9 |
+
tags:
|
| 10 |
+
- transformers
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
## Cross-Encoder for Text Ranking
|
| 14 |
+
|
| 15 |
+
This model is a port of the [webis/monoelectra-base](https://huggingface.co/webis/monoelectra-base) model from [lightning-ir](https://github.com/webis-de/lightning-ir) to [Sentence Transformers](https://sbert.net/) and [Transformers](https://huggingface.co/docs/transformers).
|
| 16 |
+
|
| 17 |
+
The original model was introduced in the paper [A Systematic Investigation of Distilling Large Language Models into Cross-Encoders for Passage Re-ranking](https://arxiv.org/abs/2405.07920). See https://github.com/webis-de/rank-distillm for code used to train the original model.
|
| 18 |
+
|
| 19 |
+
The model can be used as a reranker in a 2-stage "retrieve-rerank" pipeline, where it reorders passages returned by a retriever model (e.g. an embedding model or BM25) given some query. See [SBERT.net Retrieve & Re-rank](https://www.sbert.net/examples/applications/retrieve_rerank/README.html) for more details.
|
| 20 |
+
|
| 21 |
+
## Usage with Sentence Transformers
|
| 22 |
+
|
| 23 |
+
The usage is easy when you have [SentenceTransformers](https://www.sbert.net/) installed.
|
| 24 |
+
|
| 25 |
+
```bash
|
| 26 |
+
pip install sentence-transformers
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
Then you can use the pre-trained model like this:
|
| 30 |
+
|
| 31 |
+
```python
|
| 32 |
+
from sentence_transformers import CrossEncoder
|
| 33 |
+
|
| 34 |
+
model = CrossEncoder("cross-encoder/monoelectra-base", trust_remote_code=True)
|
| 35 |
+
scores = model.predict([
|
| 36 |
+
("How many people live in Berlin?", "Berlin had a population of 3,520,031 registered inhabitants in an area of 891.82 square kilometers."),
|
| 37 |
+
("How many people live in Berlin?", "Berlin is well known for its museums."),
|
| 38 |
+
])
|
| 39 |
+
print(scores)
|
| 40 |
+
# [ 8.122868 -4.292924]
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
## Usage with Transformers
|
| 44 |
+
|
| 45 |
+
```python
|
| 46 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 47 |
+
import torch
|
| 48 |
+
|
| 49 |
+
model = AutoModelForSequenceClassification.from_pretrained("cross-encoder/monoelectra-base", trust_remote_code=True)
|
| 50 |
+
tokenizer = AutoTokenizer.from_pretrained("cross-encoder/monoelectra-base")
|
| 51 |
+
|
| 52 |
+
features = tokenizer(
|
| 53 |
+
[
|
| 54 |
+
("How many people live in Berlin?", "Berlin had a population of 3,520,031 registered inhabitants in an area of 891.82 square kilometers."),
|
| 55 |
+
("How many people live in Berlin?", "Berlin is well known for its museums."),
|
| 56 |
+
],
|
| 57 |
+
padding=True,
|
| 58 |
+
truncation=True,
|
| 59 |
+
return_tensors="pt",
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
model.eval()
|
| 63 |
+
with torch.no_grad():
|
| 64 |
+
scores = model(**features).logits.view(-1)
|
| 65 |
+
print(scores)
|
| 66 |
+
# tensor([ 8.1229, -4.2929])
|
| 67 |
```
|
config.json
CHANGED
|
@@ -1,46 +1,46 @@
|
|
| 1 |
-
{
|
| 2 |
-
"architectures": [
|
| 3 |
-
"WebisCrossEncoderForSequenceClassification"
|
| 4 |
-
],
|
| 5 |
-
"attention_probs_dropout_prob": 0.1,
|
| 6 |
-
"auto_map": {
|
| 7 |
-
"AutoModelForSequenceClassification": "modeling.WebisCrossEncoderForSequenceClassification"
|
| 8 |
-
},
|
| 9 |
-
"backbone_model_type": "electra",
|
| 10 |
-
"classifier_dropout": null,
|
| 11 |
-
"doc_length": 256,
|
| 12 |
-
"embedding_size": 768,
|
| 13 |
-
"hidden_act": "gelu",
|
| 14 |
-
"hidden_dropout_prob": 0.1,
|
| 15 |
-
"hidden_size": 768,
|
| 16 |
-
"id2label": {
|
| 17 |
-
"0": "LABEL_0"
|
| 18 |
-
},
|
| 19 |
-
"initializer_range": 0.02,
|
| 20 |
-
"intermediate_size": 3072,
|
| 21 |
-
"label2id": {
|
| 22 |
-
"LABEL_0": 0
|
| 23 |
-
},
|
| 24 |
-
"layer_norm_eps": 1e-12,
|
| 25 |
-
"max_position_embeddings": 512,
|
| 26 |
-
"model_type": "electra",
|
| 27 |
-
"num_attention_heads": 12,
|
| 28 |
-
"num_hidden_layers": 12,
|
| 29 |
-
"pad_token_id": 0,
|
| 30 |
-
"pooling_strategy": "first",
|
| 31 |
-
"position_embedding_type": "absolute",
|
| 32 |
-
"query_length": 32,
|
| 33 |
-
"sentence_transformers": {
|
| 34 |
-
"activation_fn": "torch.nn.modules.linear.Identity",
|
| 35 |
-
"version": "4.0.
|
| 36 |
-
},
|
| 37 |
-
"summary_activation": "gelu",
|
| 38 |
-
"summary_last_dropout": 0.1,
|
| 39 |
-
"summary_type": "first",
|
| 40 |
-
"summary_use_proj": true,
|
| 41 |
-
"torch_dtype": "float32",
|
| 42 |
-
"transformers_version": "4.
|
| 43 |
-
"type_vocab_size": 2,
|
| 44 |
-
"use_cache": true,
|
| 45 |
-
"vocab_size": 30522
|
| 46 |
-
}
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"WebisCrossEncoderForSequenceClassification"
|
| 4 |
+
],
|
| 5 |
+
"attention_probs_dropout_prob": 0.1,
|
| 6 |
+
"auto_map": {
|
| 7 |
+
"AutoModelForSequenceClassification": "cross-encoder/monoelectra-base--modeling.WebisCrossEncoderForSequenceClassification"
|
| 8 |
+
},
|
| 9 |
+
"backbone_model_type": "electra",
|
| 10 |
+
"classifier_dropout": null,
|
| 11 |
+
"doc_length": 256,
|
| 12 |
+
"embedding_size": 768,
|
| 13 |
+
"hidden_act": "gelu",
|
| 14 |
+
"hidden_dropout_prob": 0.1,
|
| 15 |
+
"hidden_size": 768,
|
| 16 |
+
"id2label": {
|
| 17 |
+
"0": "LABEL_0"
|
| 18 |
+
},
|
| 19 |
+
"initializer_range": 0.02,
|
| 20 |
+
"intermediate_size": 3072,
|
| 21 |
+
"label2id": {
|
| 22 |
+
"LABEL_0": 0
|
| 23 |
+
},
|
| 24 |
+
"layer_norm_eps": 1e-12,
|
| 25 |
+
"max_position_embeddings": 512,
|
| 26 |
+
"model_type": "electra",
|
| 27 |
+
"num_attention_heads": 12,
|
| 28 |
+
"num_hidden_layers": 12,
|
| 29 |
+
"pad_token_id": 0,
|
| 30 |
+
"pooling_strategy": "first",
|
| 31 |
+
"position_embedding_type": "absolute",
|
| 32 |
+
"query_length": 32,
|
| 33 |
+
"sentence_transformers": {
|
| 34 |
+
"activation_fn": "torch.nn.modules.linear.Identity",
|
| 35 |
+
"version": "4.1.0.dev0"
|
| 36 |
+
},
|
| 37 |
+
"summary_activation": "gelu",
|
| 38 |
+
"summary_last_dropout": 0.1,
|
| 39 |
+
"summary_type": "first",
|
| 40 |
+
"summary_use_proj": true,
|
| 41 |
+
"torch_dtype": "float32",
|
| 42 |
+
"transformers_version": "4.52.0.dev0",
|
| 43 |
+
"type_vocab_size": 2,
|
| 44 |
+
"use_cache": true,
|
| 45 |
+
"vocab_size": 30522
|
| 46 |
+
}
|
onnx/model.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:aef62e9a40e6a7e84a1b5e3c5e20c2aea3d8dc6a67bb9ed6581f0eb91823b6a0
|
| 3 |
+
size 438212375
|
special_tokens_map.json
CHANGED
|
@@ -1,37 +1,37 @@
|
|
| 1 |
-
{
|
| 2 |
-
"cls_token": {
|
| 3 |
-
"content": "[CLS]",
|
| 4 |
-
"lstrip": false,
|
| 5 |
-
"normalized": false,
|
| 6 |
-
"rstrip": false,
|
| 7 |
-
"single_word": false
|
| 8 |
-
},
|
| 9 |
-
"mask_token": {
|
| 10 |
-
"content": "[MASK]",
|
| 11 |
-
"lstrip": false,
|
| 12 |
-
"normalized": false,
|
| 13 |
-
"rstrip": false,
|
| 14 |
-
"single_word": false
|
| 15 |
-
},
|
| 16 |
-
"pad_token": {
|
| 17 |
-
"content": "[PAD]",
|
| 18 |
-
"lstrip": false,
|
| 19 |
-
"normalized": false,
|
| 20 |
-
"rstrip": false,
|
| 21 |
-
"single_word": false
|
| 22 |
-
},
|
| 23 |
-
"sep_token": {
|
| 24 |
-
"content": "[SEP]",
|
| 25 |
-
"lstrip": false,
|
| 26 |
-
"normalized": false,
|
| 27 |
-
"rstrip": false,
|
| 28 |
-
"single_word": false
|
| 29 |
-
},
|
| 30 |
-
"unk_token": {
|
| 31 |
-
"content": "[UNK]",
|
| 32 |
-
"lstrip": false,
|
| 33 |
-
"normalized": false,
|
| 34 |
-
"rstrip": false,
|
| 35 |
-
"single_word": false
|
| 36 |
-
}
|
| 37 |
-
}
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cls_token": {
|
| 3 |
+
"content": "[CLS]",
|
| 4 |
+
"lstrip": false,
|
| 5 |
+
"normalized": false,
|
| 6 |
+
"rstrip": false,
|
| 7 |
+
"single_word": false
|
| 8 |
+
},
|
| 9 |
+
"mask_token": {
|
| 10 |
+
"content": "[MASK]",
|
| 11 |
+
"lstrip": false,
|
| 12 |
+
"normalized": false,
|
| 13 |
+
"rstrip": false,
|
| 14 |
+
"single_word": false
|
| 15 |
+
},
|
| 16 |
+
"pad_token": {
|
| 17 |
+
"content": "[PAD]",
|
| 18 |
+
"lstrip": false,
|
| 19 |
+
"normalized": false,
|
| 20 |
+
"rstrip": false,
|
| 21 |
+
"single_word": false
|
| 22 |
+
},
|
| 23 |
+
"sep_token": {
|
| 24 |
+
"content": "[SEP]",
|
| 25 |
+
"lstrip": false,
|
| 26 |
+
"normalized": false,
|
| 27 |
+
"rstrip": false,
|
| 28 |
+
"single_word": false
|
| 29 |
+
},
|
| 30 |
+
"unk_token": {
|
| 31 |
+
"content": "[UNK]",
|
| 32 |
+
"lstrip": false,
|
| 33 |
+
"normalized": false,
|
| 34 |
+
"rstrip": false,
|
| 35 |
+
"single_word": false
|
| 36 |
+
}
|
| 37 |
+
}
|
tokenizer_config.json
CHANGED
|
@@ -1,57 +1,58 @@
|
|
| 1 |
-
{
|
| 2 |
-
"added_tokens_decoder": {
|
| 3 |
-
"0": {
|
| 4 |
-
"content": "[PAD]",
|
| 5 |
-
"lstrip": false,
|
| 6 |
-
"normalized": false,
|
| 7 |
-
"rstrip": false,
|
| 8 |
-
"single_word": false,
|
| 9 |
-
"special": true
|
| 10 |
-
},
|
| 11 |
-
"100": {
|
| 12 |
-
"content": "[UNK]",
|
| 13 |
-
"lstrip": false,
|
| 14 |
-
"normalized": false,
|
| 15 |
-
"rstrip": false,
|
| 16 |
-
"single_word": false,
|
| 17 |
-
"special": true
|
| 18 |
-
},
|
| 19 |
-
"101": {
|
| 20 |
-
"content": "[CLS]",
|
| 21 |
-
"lstrip": false,
|
| 22 |
-
"normalized": false,
|
| 23 |
-
"rstrip": false,
|
| 24 |
-
"single_word": false,
|
| 25 |
-
"special": true
|
| 26 |
-
},
|
| 27 |
-
"102": {
|
| 28 |
-
"content": "[SEP]",
|
| 29 |
-
"lstrip": false,
|
| 30 |
-
"normalized": false,
|
| 31 |
-
"rstrip": false,
|
| 32 |
-
"single_word": false,
|
| 33 |
-
"special": true
|
| 34 |
-
},
|
| 35 |
-
"103": {
|
| 36 |
-
"content": "[MASK]",
|
| 37 |
-
"lstrip": false,
|
| 38 |
-
"normalized": false,
|
| 39 |
-
"rstrip": false,
|
| 40 |
-
"single_word": false,
|
| 41 |
-
"special": true
|
| 42 |
-
}
|
| 43 |
-
},
|
| 44 |
-
"clean_up_tokenization_spaces": true,
|
| 45 |
-
"cls_token": "[CLS]",
|
| 46 |
-
"do_lower_case": true,
|
| 47 |
-
"doc_length": 256,
|
| 48 |
-
"
|
| 49 |
-
"
|
| 50 |
-
"
|
| 51 |
-
"
|
| 52 |
-
"
|
| 53 |
-
"
|
| 54 |
-
"
|
| 55 |
-
"
|
| 56 |
-
"
|
| 57 |
-
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"added_tokens_decoder": {
|
| 3 |
+
"0": {
|
| 4 |
+
"content": "[PAD]",
|
| 5 |
+
"lstrip": false,
|
| 6 |
+
"normalized": false,
|
| 7 |
+
"rstrip": false,
|
| 8 |
+
"single_word": false,
|
| 9 |
+
"special": true
|
| 10 |
+
},
|
| 11 |
+
"100": {
|
| 12 |
+
"content": "[UNK]",
|
| 13 |
+
"lstrip": false,
|
| 14 |
+
"normalized": false,
|
| 15 |
+
"rstrip": false,
|
| 16 |
+
"single_word": false,
|
| 17 |
+
"special": true
|
| 18 |
+
},
|
| 19 |
+
"101": {
|
| 20 |
+
"content": "[CLS]",
|
| 21 |
+
"lstrip": false,
|
| 22 |
+
"normalized": false,
|
| 23 |
+
"rstrip": false,
|
| 24 |
+
"single_word": false,
|
| 25 |
+
"special": true
|
| 26 |
+
},
|
| 27 |
+
"102": {
|
| 28 |
+
"content": "[SEP]",
|
| 29 |
+
"lstrip": false,
|
| 30 |
+
"normalized": false,
|
| 31 |
+
"rstrip": false,
|
| 32 |
+
"single_word": false,
|
| 33 |
+
"special": true
|
| 34 |
+
},
|
| 35 |
+
"103": {
|
| 36 |
+
"content": "[MASK]",
|
| 37 |
+
"lstrip": false,
|
| 38 |
+
"normalized": false,
|
| 39 |
+
"rstrip": false,
|
| 40 |
+
"single_word": false,
|
| 41 |
+
"special": true
|
| 42 |
+
}
|
| 43 |
+
},
|
| 44 |
+
"clean_up_tokenization_spaces": true,
|
| 45 |
+
"cls_token": "[CLS]",
|
| 46 |
+
"do_lower_case": true,
|
| 47 |
+
"doc_length": 256,
|
| 48 |
+
"extra_special_tokens": {},
|
| 49 |
+
"mask_token": "[MASK]",
|
| 50 |
+
"model_max_length": 512,
|
| 51 |
+
"pad_token": "[PAD]",
|
| 52 |
+
"query_length": 32,
|
| 53 |
+
"sep_token": "[SEP]",
|
| 54 |
+
"strip_accents": null,
|
| 55 |
+
"tokenize_chinese_chars": true,
|
| 56 |
+
"tokenizer_class": "ElectraTokenizer",
|
| 57 |
+
"unk_token": "[UNK]"
|
| 58 |
+
}
|