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

Ensambles to subclasses of IRSystemBase #18

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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: 7 additions & 21 deletions notebooks/tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -694,14 +694,15 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"id": "TMXk4vYEVRfH"
},
"source": [
"# Ensembling Algorithms\n",
"\n",
"The `ensembles` module provides functions for ensambling of IR systems. These included methods based on:\n",
"The `ensembles` module provides classes (subclasses of IRSystem) for ensambling of IR systems. These included methods based on:\n",
"- inverse mean rank\n",
"- inverse median rank\n",
"- reciprocal rank fusion\n",
Expand All @@ -728,7 +729,7 @@
"outputs": [],
"source": [
"# importing an ensamble algorithm\n",
"from pv211_utils.ensembles import inverse_mean_rank\n",
"from pv211_utils.systems.ensembles import InverseMeanRank\n",
"# other imports\n",
"from pv211_utils.systems import BM25PlusSystem, TfidfSystem\n",
"from pv211_utils.datasets import CranfieldDataset\n",
Expand All @@ -741,16 +742,8 @@
"system_1 = BM25PlusSystem(data.load_documents(), NoneDocPreprocessing())\n",
"system_2 = TfidfSystem(data.load_documents(), NoneDocPreprocessing())\n",
"\n",
"# Create ensamble IR system\n",
"class EnsambleSystem(IRSystemBase):\n",
" def __init__(self, systems):\n",
" self.systems = systems\n",
"\n",
" def search(self, query):\n",
" return inverse_mean_rank(query, self.systems)\n",
"\n",
"# Ensambling the system_1 and system_2\n",
"ens_system = EnsambleSystem([system_1, system_2])\n",
"# Create ensamble IR system, ensambling system_1 and system_2\n",
"ens_system = InverseMeanRank([system_1, system_2])\n",
"\n",
"# We can evaluate its MAP score and compare it to individual systems' scores\n",
"print(f\"BM25 system's MAP: {mean_average_precision(system_1, data.load_test_queries(), data.load_test_judgements(), 10, 4)}\")\n",
Expand Down Expand Up @@ -863,7 +856,7 @@
"outputs": [],
"source": [
"# Import the rbc class.\n",
"from pv211_utils.ensembles import Rbc\n",
"from pv211_utils.systems.ensembles import Rbc\n",
"# Other imports.\n",
"from pv211_utils.systems import BM25PlusSystem, TfidfSystem\n",
"from pv211_utils.datasets import CranfieldDataset \n",
Expand All @@ -886,13 +879,6 @@
"print(f\"TF-IDF system's MAP: {mean_average_precision(system_2, data.load_test_queries(), data.load_test_judgements(), 10, 4)}\")\n",
"print(f\"RBC ensamble system's MAP: {mean_average_precision(rbc_ens, data.load_test_queries(), data.load_test_judgements(), 10, 4)}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -918,7 +904,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.9.14"
},
"vscode": {
"interpreter": {
Expand Down
Loading