Cyrile commited on
Commit
babbc6b
·
verified ·
1 Parent(s): f93ddb0

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +14 -21
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
- retriever = pipeline('feature-extraction', 'cmarkea/bloomz-3b-retriever')
99
-
100
- # Inportant: take only last token!
101
- infer = lambda x: [ii[0][-1] for ii in retriever(x)]
102
-
103
- list_of_contexts = [...]
104
- emb_contexts = np.concatenate(infer(list_of_contexts), axis=0)
105
- list_of_queries = [...]
106
- emb_queries = np.concatenate(infer(list_of_queries), axis=0)
107
-
108
- # Important: take l2 distance!
109
- dist = cdist(emb_queries, emb_contexts, 'euclidean')
110
- top_k = lambda x: [
111
- [list_of_contexts[qq] for qq in ii]
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