Skip to content

Commit 8953336

Browse files
authored
Merge pull request #1 from Bycarkos/patch-1
Modify retrieve_page_true_relevant_documents function
2 parents 6629ab6 + 6ee2698 commit 8953336

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

anyscript.eval/evaluation_functions.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,10 @@ def get_book_id_from_filename(filename):
6969
return filename.split('_')[0]
7070

7171

72-
def retrieve_page_true_relevant_documents(query_filename:str):
72+
def retrieve_page_true_relevant_documents(query_filename:str, book_to_pages_map:dict):
7373
book_id = get_book_id_from_filename(query_filename)
74-
path = Path(f"/data/123-1/datasets/AnyScriptFiltered/binarized/{book_id}")
75-
relevant_documents = (path.glob("*.png"))
76-
77-
return list(relevant_documents)
78-
74+
relevant_pages = book_to_pages_map[book_id]
75+
return relevant_pages
7976

8077
def retrieve_book_true_relevant_documents(query_filename:str, book_to_author_map:dict, book_to_pages_map:dict):
8178
book_id = get_book_id_from_filename(query_filename)
@@ -101,12 +98,12 @@ def compute_map_recall_at_k(response: pd.DataFrame, k:int=100, queries_map=None,
10198

10299
## Extract relevant Documents
103100
if evaluate_page:
104-
relevant_documents = retrieve_page_true_relevant_documents(query_img)
101+
relevant_documents = retrieve_page_true_relevant_documents(query_img, book_to_pages_map)
105102
else:
106103
assert book_to_author_map is not None, "book_to_author_map must be provided for book-level evaluation"
107104
relevant_documents = retrieve_book_true_relevant_documents(query_img, book_to_author_map, book_to_pages_map)
108105

109-
num_relevant_documents = len(relevant_documents)+1
106+
num_relevant_documents = len(relevant_documents)
110107

111108
# SORT and FILTER predictions based in K
112109
filtered_response_sorted = filtered_response.sort_values("similarity", ascending=False).head(k)
@@ -137,7 +134,7 @@ def compute_relevance_gt(query_page,
137134
date_query = int(lut_full_catalog[query_book]["date"][0])
138135
date_candidate = int(lut_full_catalog[candidate_book]["date"][0])
139136

140-
epoch_score = max(0.0, 20 - abs(date_query - date_candidate) / 20)
137+
epoch_score = max(0.0, (20 - abs(date_query - date_candidate)) / 20)
141138
except:
142139
epoch_score = 0
143140

0 commit comments

Comments
 (0)