Ankush Chander commited on
Commit
6c06aad
·
1 Parent(s): c94a739

Upload cricket_wikidata.ipynb

Browse files
Files changed (1) hide show
  1. cricket_wikidata.ipynb +85 -0
cricket_wikidata.ipynb ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "4c02d7d9-8095-45f0-a057-daeac6b81085",
6
+ "metadata": {},
7
+ "source": [
8
+ "# Data download"
9
+ ]
10
+ },
11
+ {
12
+ "cell_type": "code",
13
+ "execution_count": null,
14
+ "id": "43fa33c5-070f-402e-aaf0-0be00198010f",
15
+ "metadata": {},
16
+ "outputs": [],
17
+ "source": [
18
+ "\n",
19
+ "# If you want to create dataset from latest wiki dump, follow the steps below\n",
20
+ "\n",
21
+ "# Download latest wiki dump from here\n",
22
+ "# downloads around 20 GB compressed file. Time taking process. took me 1 day \n",
23
+ "! wget -c https://dumps.wikimedia.org/enwiki/latest/enwiki-latest-pages-articles-multistream.xml.bz2\n",
24
+ "\n",
25
+ "# extract files using wikiextractor (take a few hours)\n",
26
+ "! python3 -m wikiextractor.WikiExtractor enwiki-latest-pages-articles-multistream.xml.bz2 --json\n",
27
+ "\n",
28
+ "# get cricket records in a separate file\n",
29
+ "# take a few minutes\n",
30
+ "! grep -hi cricket text/*/* > cricket.jsonl\n"
31
+ ]
32
+ },
33
+ {
34
+ "cell_type": "markdown",
35
+ "id": "e23e0fae-2c6e-44af-b370-88c72db1dc4a",
36
+ "metadata": {},
37
+ "source": [
38
+ "# Data cleaning"
39
+ ]
40
+ },
41
+ {
42
+ "cell_type": "code",
43
+ "execution_count": null,
44
+ "id": "df506da6-2989-4ca7-8a43-fd5177528a0c",
45
+ "metadata": {},
46
+ "outputs": [],
47
+ "source": [
48
+ "# clean data\n",
49
+ "import pandas as pd\n",
50
+ "df = pd.read_json(\"cricket.jsonl\", lines=True)\n",
51
+ "print(len(df))\n",
52
+ "# clean df rows with empty text\n",
53
+ "df = df[df[\"text\"]!=\"\"]\n",
54
+ "print(f\"non empty records: {len(df)}\")\n",
55
+ "# clean df rows with lower case text not containing cricket\n",
56
+ "df = df[~(df[\"text\"].str.lower().str.contains(\"cricket\")==False)]\n",
57
+ "print(f\"cricket_records: {len(df)}\")\n",
58
+ "# write df to jsonl\n",
59
+ "with open(\"cricket.jsonl\", \"w\") as fp:\n",
60
+ " print(df.to_json(orient='records', lines=True), file=fp)"
61
+ ]
62
+ }
63
+ ],
64
+ "metadata": {
65
+ "kernelspec": {
66
+ "display_name": "Python 3 (ipykernel)",
67
+ "language": "python",
68
+ "name": "python3"
69
+ },
70
+ "language_info": {
71
+ "codemirror_mode": {
72
+ "name": "ipython",
73
+ "version": 3
74
+ },
75
+ "file_extension": ".py",
76
+ "mimetype": "text/x-python",
77
+ "name": "python",
78
+ "nbconvert_exporter": "python",
79
+ "pygments_lexer": "ipython3",
80
+ "version": "3.10.12"
81
+ }
82
+ },
83
+ "nbformat": 4,
84
+ "nbformat_minor": 5
85
+ }