Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[semantic_indexing] fix bug of evaluate.py #7843

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions examples/semantic_indexing/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,23 @@
import numpy as np

parser = argparse.ArgumentParser()
parser.add_argument("--similar_text_pair", type=str, default="", help="The full path of similat pair file")
parser.add_argument("--recall_result_file", type=str, default="", help="The full path of recall result file")
parser.add_argument(
"--recall_num", type=int, default=10, help="Most similair number of doc recalled from corpus per query"
"--similar_text_pair",
type=str,
default="",
help="The full path of similat pair file",
)
parser.add_argument(
"--recall_result_file",
type=str,
default="",
help="The full path of recall result file",
)
parser.add_argument(
"--recall_num",
type=int,
default=10,
help="Most similair number of doc recalled from corpus per query",
)
args = parser.parse_args()

Expand Down Expand Up @@ -57,11 +70,6 @@ def recall(rs, N=10):
with open(args.recall_result_file, "r", encoding="utf-8") as f:
relevance_labels = []
for index, line in enumerate(f):

if index % args.recall_num == 0 and index != 0:
rs.append(relevance_labels)
relevance_labels = []

text, recalled_text, cosine_sim = line.rstrip().split("\t")
if text == recalled_text:
continue
Expand All @@ -70,6 +78,10 @@ def recall(rs, N=10):
else:
relevance_labels.append(0)

if (index + 1) % args.recall_num == 0:
rs.append(relevance_labels)
relevance_labels = []

recall_N = []
for topN in (10, 50):
R = round(100 * recall(rs, N=topN), 3)
Expand Down