saahil-ognawala
commited on
Commit
•
a961d0d
1
Parent(s):
e3b88d6
chore: update code usage example (#2)
Browse files- chore: update example code (538bd1ef657c209af4e8e2a56ea1b6f9c5a0f5fd)
- chore: update example code (081430d9db68bfe4e8339929eaba1ad1925d95f3)
- chore: update example code (8e9ae950a330447bb252cd127e37e5d18717e5c8)
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,7 +63,40 @@ 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
|
@@ -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("jinaai/jina-reranker-v1-turbo-en", num_labels=1, 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
|
|
|
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.
|