Spaces:
Sleeping
Sleeping
Runnies23
commited on
Commit
·
ad60ffd
1
Parent(s):
861b48c
Add application file
Browse files- inference_script.py +20 -20
inference_script.py
CHANGED
@@ -1,41 +1,41 @@
|
|
1 |
import numpy as np
|
2 |
|
3 |
def answer_question(question , model , rerankmodel , corpus_embed , corpus_list,llm_chain):
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
|
8 |
#==========================================================
|
9 |
|
10 |
-
ALL_final_ans_list_ALL = []
|
11 |
-
batch_size = 10
|
12 |
|
13 |
-
sentence_pairs = [[question, j] for j in corpus_list]
|
14 |
|
15 |
-
listofscore = []
|
16 |
-
compute_Score = range(0, len(sentence_pairs), batch_size)
|
17 |
|
18 |
-
for i in compute_Score:
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
|
25 |
-
score_ALL = []
|
26 |
|
27 |
|
28 |
-
for score_dict in listofscore:
|
29 |
|
30 |
-
|
31 |
|
32 |
-
ALL_final_ans_list_ALL.append(score_ALL)
|
33 |
|
34 |
#==========================================================
|
35 |
|
36 |
topkindex = 15
|
37 |
-
topk15scoresimilar_BGM3 = np.argsort(ALL_final_ans_list_ALL)[:,-topkindex:]
|
38 |
-
|
39 |
|
40 |
|
41 |
BGM3_1_retrieval = [corpus_list[i] for i in topk15scoresimilar_BGM3[0]]
|
|
|
1 |
import numpy as np
|
2 |
|
3 |
def answer_question(question , model , rerankmodel , corpus_embed , corpus_list,llm_chain):
|
4 |
+
embeddings_1 = model.encode(question, batch_size=16, max_length=8192 ,)['dense_vecs']
|
5 |
+
embeddings_2 = corpus_embed
|
6 |
+
BGM3similarity = embeddings_1 @ embeddings_2.T
|
7 |
|
8 |
#==========================================================
|
9 |
|
10 |
+
# ALL_final_ans_list_ALL = []
|
11 |
+
# batch_size = 10
|
12 |
|
13 |
+
# sentence_pairs = [[question, j] for j in corpus_list]
|
14 |
|
15 |
+
# listofscore = []
|
16 |
+
# compute_Score = range(0, len(sentence_pairs), batch_size)
|
17 |
|
18 |
+
# for i in compute_Score:
|
19 |
+
# batch_pairs = sentence_pairs[i:i+batch_size]
|
20 |
+
# allscore = model.compute_score(batch_pairs,
|
21 |
+
# max_passage_length=512,
|
22 |
+
# weights_for_different_modes=[0.4, 0.2, 0.4]) # sum: w[0]*dense_score + w[1]*sparse_score + w[2]*colbert_score
|
23 |
+
# listofscore.append(allscore)
|
24 |
|
25 |
+
# score_ALL = []
|
26 |
|
27 |
|
28 |
+
# for score_dict in listofscore:
|
29 |
|
30 |
+
# score_ALL.extend(score_dict['colbert+sparse+dense'])
|
31 |
|
32 |
+
# ALL_final_ans_list_ALL.append(score_ALL)
|
33 |
|
34 |
#==========================================================
|
35 |
|
36 |
topkindex = 15
|
37 |
+
# topk15scoresimilar_BGM3 = np.argsort(ALL_final_ans_list_ALL)[:,-topkindex:]
|
38 |
+
topk15scoresimilar_BGM3 = np.argsort(BGM3similarity)[-topkindex:]
|
39 |
|
40 |
|
41 |
BGM3_1_retrieval = [corpus_list[i] for i in topk15scoresimilar_BGM3[0]]
|