{ "cells": [ { "cell_type": "markdown", "id": "4c02d7d9-8095-45f0-a057-daeac6b81085", "metadata": {}, "source": [ "# Data download" ] }, { "cell_type": "code", "execution_count": null, "id": "43fa33c5-070f-402e-aaf0-0be00198010f", "metadata": {}, "outputs": [], "source": [ "\n", "# If you want to create dataset from latest wiki dump, follow the steps below\n", "\n", "# Download latest wiki dump from here\n", "# downloads around 20 GB compressed file. Time taking process. took me 1 day \n", "! wget -c https://dumps.wikimedia.org/enwiki/latest/enwiki-latest-pages-articles-multistream.xml.bz2\n", "\n", "# extract files using wikiextractor (take a few hours)\n", "! python3 -m wikiextractor.WikiExtractor enwiki-latest-pages-articles-multistream.xml.bz2 --json\n", "\n", "# get cricket records in a separate file\n", "# take a few minutes\n", "! grep -hi cricket text/*/* > cricket.jsonl\n" ] }, { "cell_type": "markdown", "id": "e23e0fae-2c6e-44af-b370-88c72db1dc4a", "metadata": {}, "source": [ "# Data cleaning" ] }, { "cell_type": "code", "execution_count": null, "id": "df506da6-2989-4ca7-8a43-fd5177528a0c", "metadata": {}, "outputs": [], "source": [ "# clean data\n", "import pandas as pd\n", "df = pd.read_json(\"cricket.jsonl\", lines=True)\n", "print(len(df))\n", "# clean df rows with empty text\n", "df = df[df[\"text\"]!=\"\"]\n", "print(f\"non empty records: {len(df)}\")\n", "# clean df rows with lower case text not containing cricket\n", "df = df[~(df[\"text\"].str.lower().str.contains(\"cricket\")==False)]\n", "print(f\"cricket_records: {len(df)}\")\n", "# write df to jsonl\n", "with open(\"cricket.jsonl\", \"w\") as fp:\n", " print(df.to_json(orient='records', lines=True), file=fp)" ] } ], "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 }