Update app.py
Browse files
app.py
CHANGED
@@ -17,7 +17,7 @@ def get_model(base_name='intfloat/e5-large-v2'):
|
|
17 |
# get normalized scores on input_texts, the final scores are
|
18 |
# reported without queries, and the number of queries should
|
19 |
# be denoted as in how_many_q
|
20 |
-
def get_scores(model, tokenizer, input_texts, max_length=512, how_many_q=1):
|
21 |
# Tokenize the input texts
|
22 |
batch_dict = tokenizer(
|
23 |
input_texts,
|
@@ -33,9 +33,10 @@ def get_scores(model, tokenizer, input_texts, max_length=512, how_many_q=1):
|
|
33 |
)
|
34 |
|
35 |
# (Optionally) normalize embeddings
|
36 |
-
|
|
|
|
|
37 |
scores = (embeddings[:how_many_q] @ embeddings[how_many_q:].T) * 100
|
38 |
-
|
39 |
return scores
|
40 |
|
41 |
# get top n results out of the scores. This
|
@@ -107,15 +108,15 @@ tokenizer, model = get_model('intfloat/e5-large-v2')
|
|
107 |
with gr.Blocks() as demo:
|
108 |
gr.Markdown("# E5 Large V2 Demo")
|
109 |
|
110 |
-
q_txt = gr.Textbox(placeholder="Enter your query",
|
111 |
|
112 |
-
p_txt1 = gr.Textbox(placeholder="Enter passage 1",
|
113 |
-
p_txt2 = gr.Textbox(placeholder="Enter passage 2",
|
114 |
-
p_txt3 = gr.Textbox(placeholder="Enter passage 3",
|
115 |
-
p_txt4 = gr.Textbox(placeholder="Enter passage 4",
|
116 |
-
p_txt5 = gr.Textbox(placeholder="Enter passage 5",
|
117 |
submit = gr.Button("Submit")
|
118 |
-
o_txt = gr.Textbox(placeholder="Output", lines=10, interactive=False)
|
119 |
|
120 |
gr.Examples(
|
121 |
[
|
|
|
17 |
# get normalized scores on input_texts, the final scores are
|
18 |
# reported without queries, and the number of queries should
|
19 |
# be denoted as in how_many_q
|
20 |
+
def get_scores(model, tokenizer, input_texts, max_length=512, how_many_q=1, normalize=False):
|
21 |
# Tokenize the input texts
|
22 |
batch_dict = tokenizer(
|
23 |
input_texts,
|
|
|
33 |
)
|
34 |
|
35 |
# (Optionally) normalize embeddings
|
36 |
+
if normalize:
|
37 |
+
embeddings = F.normalize(embeddings, p=2, dim=1)
|
38 |
+
|
39 |
scores = (embeddings[:how_many_q] @ embeddings[how_many_q:].T) * 100
|
|
|
40 |
return scores
|
41 |
|
42 |
# get top n results out of the scores. This
|
|
|
108 |
with gr.Blocks() as demo:
|
109 |
gr.Markdown("# E5 Large V2 Demo")
|
110 |
|
111 |
+
q_txt = gr.Textbox(placeholder="Enter your query", label="Query")
|
112 |
|
113 |
+
p_txt1 = gr.Textbox(placeholder="Enter passage 1", label="Passage 1")
|
114 |
+
p_txt2 = gr.Textbox(placeholder="Enter passage 2", label="Passage 2")
|
115 |
+
p_txt3 = gr.Textbox(placeholder="Enter passage 3", label="Passage 3")
|
116 |
+
p_txt4 = gr.Textbox(placeholder="Enter passage 4", label="Passage 4")
|
117 |
+
p_txt5 = gr.Textbox(placeholder="Enter passage 5", label="Passage 5")
|
118 |
submit = gr.Button("Submit")
|
119 |
+
o_txt = gr.Textbox(placeholder="Output", lines=10, interactive=False, label="Output")
|
120 |
|
121 |
gr.Examples(
|
122 |
[
|