Update README.md
Browse files
README.md
CHANGED
@@ -91,29 +91,22 @@ How to Use Bloomz-3b-reranking
|
|
91 |
The following example utilizes the API Pipeline of the Transformers library.
|
92 |
|
93 |
```python
|
94 |
-
import numpy as np
|
95 |
from transformers import pipeline
|
96 |
-
from scipy.spatial.distance import cdist
|
97 |
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
for ii in dist.argsort(axis=-1)[:,:x]
|
113 |
-
]
|
114 |
-
|
115 |
-
# top 5 nearest contexts for each queries
|
116 |
-
top_contexts = top_k(5)
|
117 |
```
|
118 |
|
119 |
Citation
|
|
|
91 |
The following example utilizes the API Pipeline of the Transformers library.
|
92 |
|
93 |
```python
|
|
|
94 |
from transformers import pipeline
|
|
|
95 |
|
96 |
+
reranker = pipeline('feature-extraction', 'cmarkea/bloomz-3b-retriever', top_k=None)
|
97 |
+
|
98 |
+
similarity = reranker(
|
99 |
+
[dict(text=ii, text_pair=query) for ii in context_list]
|
100 |
+
)
|
101 |
+
context_reranked = sorted(
|
102 |
+
filter(lambda x: x[0]['label'] == "LABEL_1", zip(similarity, context_list)),
|
103 |
+
key=lambda x: x[0]
|
104 |
+
)
|
105 |
+
score, context_cleaned = zip(
|
106 |
+
*filter(
|
107 |
+
lambda x: x[0] >= 0.8
|
108 |
+
)
|
109 |
+
)
|
|
|
|
|
|
|
|
|
|
|
110 |
```
|
111 |
|
112 |
Citation
|