retrieval_correction
This commit is contained in:
parent
f0f78e8d17
commit
011a1f99cc
@ -8,15 +8,10 @@ from pathlib import Path
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
PROJECT_ROOT = Path(
|
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
||||||
__file__
|
|
||||||
).resolve().parents[1]
|
|
||||||
|
|
||||||
if str(PROJECT_ROOT) not in sys.path:
|
if str(PROJECT_ROOT) not in sys.path:
|
||||||
sys.path.insert(
|
sys.path.insert(0, str(PROJECT_ROOT))
|
||||||
0,
|
|
||||||
str(PROJECT_ROOT),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
from evaluation.metrics import (
|
from evaluation.metrics import (
|
||||||
@ -37,11 +32,15 @@ from evaluation.retrieval_runner import (
|
|||||||
from scripts.common import DB_FILE
|
from scripts.common import DB_FILE
|
||||||
|
|
||||||
|
|
||||||
|
EVALUATION_DIR = PROJECT_ROOT / "evaluation"
|
||||||
|
JSON_FILES_DIR = EVALUATION_DIR / "json_files"
|
||||||
|
|
||||||
|
QUESTIONS_PATH = JSON_FILES_DIR / "questions.json"
|
||||||
|
RESULTS_DIR = EVALUATION_DIR / "results"
|
||||||
|
|
||||||
|
|
||||||
def print_summary(
|
def print_summary(
|
||||||
summary: dict[
|
summary: dict[str, dict[str, Any]],
|
||||||
str,
|
|
||||||
dict[str, Any],
|
|
||||||
],
|
|
||||||
*,
|
*,
|
||||||
split: str,
|
split: str,
|
||||||
selected_count: int,
|
selected_count: int,
|
||||||
@ -51,6 +50,7 @@ def print_summary(
|
|||||||
print(
|
print(
|
||||||
"Retrieval evaluation"
|
"Retrieval evaluation"
|
||||||
)
|
)
|
||||||
|
|
||||||
print(
|
print(
|
||||||
"=" * 78
|
"=" * 78
|
||||||
)
|
)
|
||||||
@ -104,6 +104,7 @@ def print_summary(
|
|||||||
print(
|
print(
|
||||||
"=" * 78
|
"=" * 78
|
||||||
)
|
)
|
||||||
|
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
|
||||||
@ -134,9 +135,7 @@ def save_json_results(
|
|||||||
|
|
||||||
def save_csv_results(
|
def save_csv_results(
|
||||||
path: Path,
|
path: Path,
|
||||||
rows: list[
|
rows: list[dict[str, Any]],
|
||||||
dict[str, Any]
|
|
||||||
],
|
|
||||||
) -> None:
|
) -> None:
|
||||||
path.parent.mkdir(
|
path.parent.mkdir(
|
||||||
parents=True,
|
parents=True,
|
||||||
@ -216,36 +215,22 @@ def parse_args() -> argparse.Namespace:
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--questions",
|
"--questions",
|
||||||
type=Path,
|
type=Path,
|
||||||
default=(
|
default=QUESTIONS_PATH,
|
||||||
PROJECT_ROOT
|
help="Cesta k questions.json",
|
||||||
/ "evaluation"
|
|
||||||
/ "questions.json"
|
|
||||||
),
|
|
||||||
help=(
|
|
||||||
"Cesta k questions.json"
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--db",
|
"--db",
|
||||||
type=Path,
|
type=Path,
|
||||||
default=DB_FILE,
|
default=DB_FILE,
|
||||||
help=(
|
help="Cesta k SQLite indexu",
|
||||||
"Cesta k SQLite indexu"
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--output-dir",
|
"--output-dir",
|
||||||
type=Path,
|
type=Path,
|
||||||
default=(
|
default=RESULTS_DIR,
|
||||||
PROJECT_ROOT
|
help="Adresár pre výsledky",
|
||||||
/ "evaluation"
|
|
||||||
/ "results"
|
|
||||||
),
|
|
||||||
help=(
|
|
||||||
"Adresár pre výsledky"
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@ -329,11 +314,9 @@ def main() -> None:
|
|||||||
all_questions
|
all_questions
|
||||||
)
|
)
|
||||||
|
|
||||||
questions = (
|
questions = filter_questions_by_split(
|
||||||
filter_questions_by_split(
|
all_questions,
|
||||||
all_questions,
|
args.split,
|
||||||
args.split,
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if not questions:
|
if not questions:
|
||||||
@ -346,33 +329,45 @@ def main() -> None:
|
|||||||
print(
|
print(
|
||||||
"Dataset"
|
"Dataset"
|
||||||
)
|
)
|
||||||
|
|
||||||
print(
|
print(
|
||||||
"=" * 60
|
"=" * 60
|
||||||
)
|
)
|
||||||
|
|
||||||
print(
|
print(
|
||||||
f"Total: {len(all_questions)}"
|
f"Questions file: "
|
||||||
|
f"{args.questions}"
|
||||||
)
|
)
|
||||||
|
|
||||||
print(
|
print(
|
||||||
f"Dev: {split_counts['dev']}"
|
f"Total: "
|
||||||
|
f"{len(all_questions)}"
|
||||||
)
|
)
|
||||||
|
|
||||||
print(
|
print(
|
||||||
f"Test: {split_counts['test']}"
|
f"Dev: "
|
||||||
|
f"{split_counts['dev']}"
|
||||||
)
|
)
|
||||||
|
|
||||||
print(
|
print(
|
||||||
f"Selected split: {args.split}"
|
f"Test: "
|
||||||
|
f"{split_counts['test']}"
|
||||||
)
|
)
|
||||||
|
|
||||||
print(
|
print(
|
||||||
f"Selected questions: {len(questions)}"
|
f"Selected split: "
|
||||||
|
f"{args.split}"
|
||||||
|
)
|
||||||
|
|
||||||
|
print(
|
||||||
|
f"Selected questions: "
|
||||||
|
f"{len(questions)}"
|
||||||
)
|
)
|
||||||
|
|
||||||
print(
|
print(
|
||||||
"=" * 60
|
"=" * 60
|
||||||
)
|
)
|
||||||
|
|
||||||
print()
|
print()
|
||||||
|
|
||||||
indexed_documents = (
|
indexed_documents = (
|
||||||
@ -427,20 +422,18 @@ def main() -> None:
|
|||||||
f"{question['question']}"
|
f"{question['question']}"
|
||||||
)
|
)
|
||||||
|
|
||||||
mode_results = (
|
mode_results = retrieve_all_modes(
|
||||||
retrieve_all_modes(
|
args.db,
|
||||||
args.db,
|
question[
|
||||||
question[
|
"question"
|
||||||
"question"
|
],
|
||||||
],
|
limit=args.limit,
|
||||||
limit=args.limit,
|
published_only=(
|
||||||
published_only=(
|
args.published_only
|
||||||
args.published_only
|
),
|
||||||
),
|
max_per_document=(
|
||||||
max_per_document=(
|
args.max_per_document
|
||||||
args.max_per_document
|
),
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
for mode in EVALUATION_MODES:
|
for mode in EVALUATION_MODES:
|
||||||
@ -510,9 +503,7 @@ def main() -> None:
|
|||||||
"database": str(
|
"database": str(
|
||||||
args.db
|
args.db
|
||||||
),
|
),
|
||||||
"split": (
|
"split": args.split,
|
||||||
args.split
|
|
||||||
),
|
|
||||||
"dataset_question_count": len(
|
"dataset_question_count": len(
|
||||||
all_questions
|
all_questions
|
||||||
),
|
),
|
||||||
@ -559,34 +550,24 @@ def main() -> None:
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
"summary": summary,
|
"summary": summary,
|
||||||
"by_category": (
|
"by_category": by_category,
|
||||||
by_category
|
"by_difficulty": by_difficulty,
|
||||||
),
|
"questions": evaluation_rows,
|
||||||
"by_difficulty": (
|
|
||||||
by_difficulty
|
|
||||||
),
|
|
||||||
"questions": (
|
|
||||||
evaluation_rows
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
filename_suffix = (
|
|
||||||
args.split
|
|
||||||
)
|
|
||||||
|
|
||||||
json_path = (
|
json_path = (
|
||||||
args.output_dir
|
args.output_dir
|
||||||
/ (
|
/ (
|
||||||
"retrieval_results_"
|
f"retrieval_results_"
|
||||||
f"{filename_suffix}.json"
|
f"{args.split}.json"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
csv_path = (
|
csv_path = (
|
||||||
args.output_dir
|
args.output_dir
|
||||||
/ (
|
/ (
|
||||||
"retrieval_results_"
|
f"retrieval_results_"
|
||||||
f"{filename_suffix}.csv"
|
f"{args.split}.csv"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -616,11 +597,13 @@ def main() -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
print(
|
print(
|
||||||
f" JSON: {json_path}"
|
f" JSON: "
|
||||||
|
f"{json_path}"
|
||||||
)
|
)
|
||||||
|
|
||||||
print(
|
print(
|
||||||
f" CSV: {csv_path}"
|
f" CSV: "
|
||||||
|
f"{csv_path}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if missing_expected:
|
if missing_expected:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user