numb3r3 commited on
Commit
80d2ebe
1 Parent(s): eda82c8

chore: update readme

Browse files
Files changed (1) hide show
  1. README.md +32 -3
README.md CHANGED
@@ -23,6 +23,13 @@ license: cc-by-nc-4.0
23
  # jina-reranker-v2-base-multilingual
24
 
25
 
 
 
 
 
 
 
 
26
  # Usage
27
 
28
  1. The easiest way to starting using `jina-reranker-v2-base-multilingual` is to use Jina AI's [Reranker API](https://jina.ai/reranker/).
@@ -57,9 +64,11 @@ curl https://api.jina.ai/v1/rerank \
57
  from transformers import AutoModelForSequenceClassification
58
 
59
  model = AutoModelForSequenceClassification.from_pretrained(
60
- 'jinaai/jina-reranker-v2-base-multilingual', trust_remote_code=True,
 
 
 
61
  )
62
- model.to('cuda')
63
 
64
  # Example query and documents
65
  query = "Organic skincare products for sensitive skin"
@@ -79,7 +88,27 @@ documents = [
79
  # construct sentence pairs
80
  sentence_pairs = [[query, doc] for doc in documents]
81
 
82
- scores = model.compute_score(sentence_pairs)
83
  ```
84
 
85
  That's it! You can now use the `jina-reranker-v2-base-multilingual` model in your projects.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  # jina-reranker-v2-base-multilingual
24
 
25
 
26
+ Compared with the state-of-the-art reranker models, including the previous released `jina-reranker-v1-base-en`, the **Jina Reranker v2** model has demonstrated competitiveness across a series of benchmarks targeting for text retrieval, multilingual capability, function-calling-aware and text-to-SQL-aware reranking, and code retrieval tasks.
27
+
28
+ The `jina-reranker-v2-base-multilingual` model is capable of handling long texts with a context length of up to `1024` tokens, enabling the processing of extensive inputs. To enable the model to handle long texts that exceed 1024 tokens, the model uses a sliding window approach to chunk the input text into smaller pieces and rerank each chunk separately.
29
+
30
+ The model is also equipped with a flash attention mechanism, which significantly improves the model's performance.
31
+
32
+
33
  # Usage
34
 
35
  1. The easiest way to starting using `jina-reranker-v2-base-multilingual` is to use Jina AI's [Reranker API](https://jina.ai/reranker/).
 
64
  from transformers import AutoModelForSequenceClassification
65
 
66
  model = AutoModelForSequenceClassification.from_pretrained(
67
+ 'jinaai/jina-reranker-v2-base-multilingual',
68
+ device_map="cuda",
69
+ torch_dtype="auto",
70
+ trust_remote_code=True,
71
  )
 
72
 
73
  # Example query and documents
74
  query = "Organic skincare products for sensitive skin"
 
88
  # construct sentence pairs
89
  sentence_pairs = [[query, doc] for doc in documents]
90
 
91
+ scores = model.compute_score(sentence_pairs, max_length=1024)
92
  ```
93
 
94
  That's it! You can now use the `jina-reranker-v2-base-multilingual` model in your projects.
95
+
96
+ Note that by default, the `jina-reranker-v2-base-multilingual` model uses [flash attention](https://github.com/Dao-AILab/flash-attention), which requires certain types of GPU hardware to run. If you encounter any issues, you can try call `AutoModelForSequenceClassification.from_pretrained()` with `use_flash_attn=False`. This will use the standard attention mechanism instead of flash attention. You can also try running the model on a CPU by setting `device_map="cpu"`.
97
+
98
+
99
+ In addition to the `compute_score()` function, the `jina-reranker-v2-base-multilingual` model also provides a `model.rerank()` function that can be used to rerank documents based on a query. You can use it as follows:
100
+
101
+ ```python
102
+ result = model.rerank(
103
+ query,
104
+ documents,
105
+ max_query_length=512,
106
+ max_length=1024,
107
+ top_n=3
108
+ )
109
+ ```
110
+
111
+ Inside the `result` object, you will find the reranked documents along with their scores. You can use this information to further process the documents as needed.
112
+
113
+ What's more, the `rerank()` function will automatically chunk the input documents into smaller pieces if they exceed the model's maximum input length. This allows you to rerank long documents without running into memory issues.
114
+ Specifically, the `rerank()` function will split the documents into chunks of size `max_length` and rerank each chunk separately. The scores from all the chunks are then combined to produce the final reranking results. You can control the query length and document length in each chunk by setting the `max_query_length` and `max_length` parameters. The `rerank()` function also supports the `overlap` parameter (default is `80`) which determines how much overlap there is between adjacent chunks. This can be useful when reranking long documents to ensure that the model has enough context to make accurate predictions.