Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -66,7 +66,7 @@ def search():
|
|
| 66 |
|
| 67 |
##### Re-Ranking #####
|
| 68 |
# Now, score all retrieved passages with the cross_encoder
|
| 69 |
-
cross_inp = [[query, dataset[
|
| 70 |
cross_scores = cross_encoder.predict(cross_inp)
|
| 71 |
|
| 72 |
# Sort results by the cross-encoder scores
|
|
@@ -79,13 +79,30 @@ def search():
|
|
| 79 |
print("\n-------------------------\n")
|
| 80 |
print("Top-3 Cross-Encoder Re-ranker hits")
|
| 81 |
st.subheader("Top-3 Search results")
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
|
| 89 |
# search button
|
| 90 |
st_search_button = st.button('Search', on_click=search)
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
##### Re-Ranking #####
|
| 68 |
# Now, score all retrieved passages with the cross_encoder
|
| 69 |
+
cross_inp = [[query, dataset[hit['corpus_id']]["text"]] for hit in hits]
|
| 70 |
cross_scores = cross_encoder.predict(cross_inp)
|
| 71 |
|
| 72 |
# Sort results by the cross-encoder scores
|
|
|
|
| 79 |
print("\n-------------------------\n")
|
| 80 |
print("Top-3 Cross-Encoder Re-ranker hits")
|
| 81 |
st.subheader("Top-3 Search results")
|
| 82 |
+
results: dict[str, dict] = {}
|
| 83 |
+
for i, hit in enumerate(hits[:3]):
|
| 84 |
+
results[i] = {
|
| 85 |
+
"score": round(hit['cross-score'], 3),
|
| 86 |
+
"title": dataset[hit['corpus_id']]["title"],
|
| 87 |
+
"abstract": dataset[hit['corpus_id']]["text"].replace("\n", " "),
|
| 88 |
+
"link": dataset[hit['corpus_id']]["url"]
|
| 89 |
+
}
|
| 90 |
+
st.session_state.results = results
|
| 91 |
|
| 92 |
|
| 93 |
# search button
|
| 94 |
st_search_button = st.button('Search', on_click=search)
|
| 95 |
|
| 96 |
+
if 'results' not in st.session_state:
|
| 97 |
+
st.session_state.results = {}
|
| 98 |
+
|
| 99 |
+
if len(st.session_state.results) > 0:
|
| 100 |
+
with st.container():
|
| 101 |
+
st.subheader("Search results")
|
| 102 |
+
for result in st.session_state.questions:
|
| 103 |
+
for k,v in result.items():
|
| 104 |
+
st.markdown("score: " + results["score"])
|
| 105 |
+
st.markdown("title: " + results["title"])
|
| 106 |
+
st.markdown("abstract: " + results["abstract"])
|
| 107 |
+
st.markdown("link: " + results["link"])
|
| 108 |
+
st.text("")
|