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
Tom Aarsen commited on
Commit ·
caa7ce7
1
Parent(s): 5a84b7b
Update README snippets
Browse files
README.md
CHANGED
|
@@ -37,7 +37,7 @@ scores = model.predict([
|
|
| 37 |
("How many people live in Berlin?", "Berlin is well known for its museums."),
|
| 38 |
])
|
| 39 |
print(scores)
|
| 40 |
-
# [ 8.
|
| 41 |
```
|
| 42 |
|
| 43 |
## Usage with Transformers
|
|
@@ -51,8 +51,8 @@ tokenizer = AutoTokenizer.from_pretrained("cross-encoder/monoelectra-base")
|
|
| 51 |
|
| 52 |
features = tokenizer(
|
| 53 |
[
|
| 54 |
-
|
| 55 |
-
|
| 56 |
],
|
| 57 |
padding=True,
|
| 58 |
truncation=True,
|
|
@@ -61,6 +61,7 @@ features = tokenizer(
|
|
| 61 |
|
| 62 |
model.eval()
|
| 63 |
with torch.no_grad():
|
| 64 |
-
scores = model(**features).logits
|
| 65 |
-
|
|
|
|
| 66 |
```
|
|
|
|
| 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
|
|
|
|
| 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,
|
|
|
|
| 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 |
```
|