mirror of
https://github.com/neuml/txtai.git
synced 2026-10-11 21:39:55 +00:00
63 KiB
63 KiB
In [1]:
%%capture
!pip install txtai pytrec_eval rank-bm25 elasticsearch
!pip uninstall -y tensorflowIn [2]:
%%capture
import os
# Get benchmarks script
os.system("wget https://raw.githubusercontent.com/neuml/txtai/master/examples/benchmarks.py")
# Create output directory
os.makedirs("beir", exist_ok=True)
# Download subset of BEIR datasets
datasets = ["nfcorpus", "fiqa", "arguana", "scidocs", "scifact"]
for dataset in datasets:
url = f"https://public.ukp.informatik.tu-darmstadt.de/thakur/BEIR/datasets/{dataset}.zip"
os.system(f"wget {url}")
os.system(f"mv {dataset}.zip beir")
os.system(f"unzip -d beir beir/{dataset}.zip")
# Remove existing benchmark data
if os.path.exists("benchmarks.json"):
os.remove("benchmarks.json")In [3]:
# Remove existing benchmark data
if os.path.exists("benchmarks.json"):
os.remove("benchmarks.json")
# Runs benchmark evaluation
def evaluate(method):
for dataset in datasets:
command = f"python benchmarks.py beir {dataset} {method}"
print(command)
os.system(command)
# Calculate benchmarks
for method in ["bm25", "embed", "hybrid"]:
evaluate(method)python benchmarks.py beir nfcorpus bm25 python benchmarks.py beir fiqa bm25 python benchmarks.py beir arguana bm25 python benchmarks.py beir scidocs bm25 python benchmarks.py beir scifact bm25 python benchmarks.py beir nfcorpus embed python benchmarks.py beir fiqa embed python benchmarks.py beir arguana embed python benchmarks.py beir scidocs embed python benchmarks.py beir scifact embed python benchmarks.py beir nfcorpus hybrid python benchmarks.py beir fiqa hybrid python benchmarks.py beir arguana hybrid python benchmarks.py beir scidocs hybrid python benchmarks.py beir scifact hybrid
In [4]:
import json
import pandas as pd
def benchmarks():
# Read JSON lines data
with open("benchmarks.json") as f:
data = f.read()
df = pd.read_json(data, lines=True).sort_values(by=["source", "ndcg_cut_10"], ascending=[True, False])
return df[["source", "method", "ndcg_cut_10", "map_cut_10", "recall_10", "P_10", "index", "search", "memory"]].reset_index(drop=True)
# Load benchmarks dataframe
df = benchmarks()In [9]:
df[df.source == "nfcorpus"].reset_index(drop=True)Out [9]:
| source | method | ndcg_cut_10 | map_cut_10 | recall_10 | P_10 | index | search | memory | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | nfcorpus | hybrid | 0.34531 | 0.13369 | 0.17437 | 0.25480 | 29.46 | 3.57 | 2900 |
| 1 | nfcorpus | embed | 0.30917 | 0.10810 | 0.15327 | 0.23591 | 33.64 | 3.33 | 2876 |
| 2 | nfcorpus | bm25 | 0.30639 | 0.11728 | 0.14891 | 0.21734 | 2.72 | 0.96 | 652 |
In [8]:
df[df.source == "fiqa"].reset_index(drop=True)Out [8]:
| source | method | ndcg_cut_10 | map_cut_10 | recall_10 | P_10 | index | search | memory | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | fiqa | hybrid | 0.36642 | 0.28846 | 0.43799 | 0.10340 | 233.90 | 68.42 | 3073 |
| 1 | fiqa | embed | 0.36071 | 0.28450 | 0.43188 | 0.10216 | 212.30 | 58.83 | 2924 |
| 2 | fiqa | bm25 | 0.23559 | 0.17619 | 0.29855 | 0.06559 | 19.78 | 12.84 | 761 |
In [10]:
df[df.source == "arguana"].reset_index(drop=True)Out [10]:
| source | method | ndcg_cut_10 | map_cut_10 | recall_10 | P_10 | index | search | memory | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | arguana | hybrid | 0.48467 | 0.40101 | 0.75320 | 0.07532 | 37.80 | 21.22 | 2924 |
| 1 | arguana | embed | 0.47781 | 0.38781 | 0.76671 | 0.07667 | 34.11 | 10.21 | 2910 |
| 2 | arguana | bm25 | 0.45713 | 0.37118 | 0.73471 | 0.07347 | 3.39 | 10.95 | 663 |
In [6]:
df[df.source == "scidocs"].reset_index(drop=True)Out [6]:
| source | method | ndcg_cut_10 | map_cut_10 | recall_10 | P_10 | index | search | memory | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | scidocs | embed | 0.21718 | 0.12982 | 0.23217 | 0.1146 | 127.63 | 4.41 | 2929 |
| 1 | scidocs | hybrid | 0.21104 | 0.12450 | 0.22938 | 0.1134 | 138.00 | 6.43 | 2999 |
| 2 | scidocs | bm25 | 0.15063 | 0.08756 | 0.15637 | 0.0772 | 13.07 | 1.42 | 722 |
In [7]:
df[df.source == "scifact"].reset_index(drop=True)Out [7]:
| source | method | ndcg_cut_10 | map_cut_10 | recall_10 | P_10 | index | search | memory | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | scifact | hybrid | 0.71305 | 0.66773 | 0.83722 | 0.09367 | 39.51 | 2.35 | 2918 |
| 1 | scifact | bm25 | 0.66324 | 0.61764 | 0.78761 | 0.08700 | 4.40 | 0.93 | 658 |
| 2 | scifact | embed | 0.65149 | 0.60193 | 0.78972 | 0.08867 | 35.15 | 1.48 | 2889 |