{ "cells": [ { "cell_type": "code", "execution_count": 6, "id": "7f07af8b", "metadata": {}, "outputs": [], "source": [ "import os" ] }, { "cell_type": "markdown", "id": "fabcb3ee", "metadata": {}, "source": [ "This notebook provides some utility to perform grid searches over building parameters for Seismic." ] }, { "cell_type": "markdown", "id": "a504133f", "metadata": {}, "source": [ "#### Build" ] }, { "cell_type": "markdown", "id": "51a22277", "metadata": {}, "source": [ "This section generates a `bash` script, whose name is specified by the `output_file` variable, that builds an index for every configuration of the combination of values specified in `all_n_postings`, `all_energies`, and `all_centroid_fractions`. Just execute the generated bash script to start the grid search. Don't forget to specify the `document_path`, i.e. the path to the documents in the inner format for Seismic, and the `index_dir_path`, which is where the generated indexes will be saved." ] }, { "cell_type": "code", "execution_count": 2, "id": "1249345b", "metadata": {}, "outputs": [], "source": [ "output_file = \"../grid_index.sh\"\n", "\n", "all_n_posting = [1000, 1500, 2000]\n", "all_energies = [0.1, 0.2]\n", "all_centroid_fractions = [0.05, 0.75, 0.1]\n", "\n", "\n", "\n", "executable = \"./target/release/build_inverted_index\"\n", "documents_path = \"\"\n", "index_dir_path = \"\"\n", "for n_postings in all_n_posting:\n", " for energy in all_energies:\n", " for centroid_fraction in all_centroid_fractions:\n", " name = f\"GlobalThreshold_n-postings_{n_postings}_energy_{energy}_centroid-fraction_{centroid_fraction}.seismic_index\"\n", " index_path = os.path.join(index_dir_path, name)\n", " string = f\"{executable} -i {documents_path} --centroid-fraction {centroid_fraction} -s {energy} --n-postings {n_postings} -o {index_path}\\n\"\n", " with open(output_file, \"a\") as f:\n", " f.write(string)" ] }, { "cell_type": "markdown", "id": "00a7484f", "metadata": {}, "source": [ "#### Search (MSMARCO)" ] }, { "cell_type": "markdown", "id": "5e5c736b", "metadata": {}, "source": [ "This section helps you in running the grid search, given that you have built a set of indexes using the code in the **Build** section. You shall indicate:\n", " - `queries_path`: path to the queries in the inner format.\n", " - `groundtruth_path`: path to the groundtruth file generated using the `generate_groundtruth` binary. This is needed to compute the recall over the exact search. \n", " - `index_folder`: path to the directory that contains the indexes, usually the same as `index_dir_path` above\n", " - `result_folder`: directory where the results (in the .tsv format) will be saved. The scripts generates one output file per index (with the same name of the index). You can change the name of the output file by modifying the `result_path` inside the `for` loop below.\n", "- `qrels_path`: path to the qrles file.\n", "- `original_queries_path`: path to the .tsv file containing the original queries.\n", "\n", "\n", "The qrels and the original queries file can be downloaded [here](http://hpc.isti.cnr.it/~rulli/seismic-sigir2024/aux_data/).\n", " " ] }, { "cell_type": "code", "execution_count": 2, "id": "2625a212", "metadata": {}, "outputs": [], "source": [ "base_command = \"bash scripts/grid_search.sh\" \n", "\n", "queries_path = \"\"\n", "groundtruth_path = \"\"\n", "\n", "index_folder = \"\" # Same as index_dir_path\n", "result_folder = \"\"\n", "\n", "qrels_path = \"\"\n", "original_queries_path = \"\"" ] }, { "cell_type": "code", "execution_count": 4, "id": "f5c85bd0", "metadata": {}, "outputs": [], "source": [ "# You can apply different filters based on the index name, i.e. \"4000\" in x\n", "files = filter(lambda x: x.startswith(\"Global\"), os.listdir(index_folder))" ] }, { "cell_type": "code", "execution_count": 6, "id": "28065ecd", "metadata": {}, "outputs": [], "source": [ "grid_file = \"../grid_search.sh\"" ] }, { "cell_type": "code", "execution_count": 22, "id": "ad31dc87", "metadata": {}, "outputs": [], "source": [ "for file in files:\n", " index_path = os.path.join(index_folder, file)\n", " result_path = os.path.join(result_folder, file)\n", " string = f\"{base_command} {index_path} {result_path} {queries_path} {groundtruth_path}\\n\"\n", " with open(grid_file, \"a\") as f:\n", " f.write(string)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" } }, "nbformat": 4, "nbformat_minor": 5 }