numb3r3
commited on
Commit
•
538bd1e
1
Parent(s):
e3b88d6
chore: update example code
Browse files
README.md
CHANGED
@@ -38,7 +38,7 @@ As you can see, the `jina-reranker-v1-turbo-en` offers a balanced approach with
|
|
38 |
|
39 |
# Usage
|
40 |
|
41 |
-
The easiest way to starting using `jina-reranker-v1-turbo-en` is to use Jina AI's [Reranker API](https://jina.ai/reranker/).
|
42 |
|
43 |
```bash
|
44 |
curl https://api.jina.ai/v1/rerank \
|
@@ -63,14 +63,47 @@ curl https://api.jina.ai/v1/rerank \
|
|
63 |
}'
|
64 |
```
|
65 |
|
66 |
-
Alternatively, you can use the `transformers` library
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
```python
|
69 |
!pip install transformers
|
70 |
from transformers import AutoModelForSequenceClassification
|
71 |
|
72 |
model = AutoModelForSequenceClassification.from_pretrained(
|
73 |
-
'
|
74 |
)
|
75 |
|
76 |
# Example query and documents
|
@@ -94,6 +127,8 @@ sentence_pairs = [[query, doc] for doc in documents]
|
|
94 |
scores = model.compute_score(sentence_pairs)
|
95 |
```
|
96 |
|
|
|
|
|
97 |
# Evaluation
|
98 |
|
99 |
We evaluated Jina Reranker on 3 key benchmarks to ensure top-tier performance and search relevance.
|
|
|
38 |
|
39 |
# Usage
|
40 |
|
41 |
+
1. The easiest way to starting using `jina-reranker-v1-turbo-en` is to use Jina AI's [Reranker API](https://jina.ai/reranker/).
|
42 |
|
43 |
```bash
|
44 |
curl https://api.jina.ai/v1/rerank \
|
|
|
63 |
}'
|
64 |
```
|
65 |
|
66 |
+
2. Alternatively, you can use the latest version of the `sentence-transformers>=0.27.0` library. You can install it via pip:
|
67 |
+
|
68 |
+
```bash
|
69 |
+
pip install -U sentence-transformers
|
70 |
+
```
|
71 |
+
|
72 |
+
Then, you can use the following code to interact with the model:
|
73 |
+
|
74 |
+
```python
|
75 |
+
from sentence_transformers import CrossEncoder
|
76 |
+
|
77 |
+
# Load the model, here we use our base sized model
|
78 |
+
model = CrossEncoder("jina-reranker-v1-turbo-en", num_labels=1, automodel_args={'trust_remote_code': True})
|
79 |
+
|
80 |
+
|
81 |
+
# Example query and documents
|
82 |
+
query = "Organic skincare products for sensitive skin"
|
83 |
+
documents = [
|
84 |
+
"Eco-friendly kitchenware for modern homes",
|
85 |
+
"Biodegradable cleaning supplies for eco-conscious consumers",
|
86 |
+
"Organic cotton baby clothes for sensitive skin",
|
87 |
+
"Natural organic skincare range for sensitive skin",
|
88 |
+
"Tech gadgets for smart homes: 2024 edition",
|
89 |
+
"Sustainable gardening tools and compost solutions",
|
90 |
+
"Sensitive skin-friendly facial cleansers and toners",
|
91 |
+
"Organic food wraps and storage solutions",
|
92 |
+
"All-natural pet food for dogs with allergies",
|
93 |
+
"Yoga mats made from recycled materials"
|
94 |
+
]
|
95 |
+
|
96 |
+
results = model.rank(query, documents, return_documents=True, top_k=3)
|
97 |
+
```
|
98 |
+
|
99 |
+
3. You can also use the `transformers` library to interact with the model programmatically.
|
100 |
|
101 |
```python
|
102 |
!pip install transformers
|
103 |
from transformers import AutoModelForSequenceClassification
|
104 |
|
105 |
model = AutoModelForSequenceClassification.from_pretrained(
|
106 |
+
'jina-reranker-v1-turbo-en', num_labels=1, trust_remote_code=True
|
107 |
)
|
108 |
|
109 |
# Example query and documents
|
|
|
127 |
scores = model.compute_score(sentence_pairs)
|
128 |
```
|
129 |
|
130 |
+
That's it! You can now use the `jina-reranker-v1-turbo-en` model in your projects.
|
131 |
+
|
132 |
# Evaluation
|
133 |
|
134 |
We evaluated Jina Reranker on 3 key benchmarks to ensure top-tier performance and search relevance.
|