{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# RTL Wiki. Preprocessing\n", "\n", "Example of a text data preprocessing before topic modeling (applied to RTL-Wiki dataset).\n", "\n", "Alternatively, you can skip this step and use our `topicnet.dataset_manager`.\n", "\n", "The dataset was introduced in [1] and later recreated in [2]. You can download it from https://hobbitdata.informatik.uni-leipzig.de/homes/mroeder/palmetto/datasets/rtl-wiki.tar.gz.\n", "\n", "References:\n", "\n", "* [1] \"Reading Tea Leaves: How Humans Interpret Topic Models\" (NIPS 2009).\n", "* [2] \"Exploring the Space of Topic Coherence Measures\" (WSDM 2015).\n", "* Related notebook (with preprocessing for other dataset): [20NG-Preprocessing.ipynb](./20NG-Preprocessing.ipynb)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Contents\n", "\n", "* [Data loading](#data-loading)\n", "* [Data filtering](#data-filtering)\n", "* [Text preprocessing (lemmatization, stopwords filtering, N-grams extraction)](#text-preprocessing)\n", "* [Vowpal Wabbit](#vowpal-wabbit)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import glob\n", "import os\n", "import re\n", "import string\n", "from collections import Counter\n", "\n", "try:\n", " from tqdm.notebook import tqdm\n", "except ModuleNotFoundError:\n", " # TODO: remove after tqdm v5.0.0 released\n", " from tqdm import tqdm_notebook as tqdm\n", "\n", "\n", "import nltk\n", "import pandas as pd\n", "from bs4 import BeautifulSoup\n", "from nltk.collocations import (\n", " BigramAssocMeasures,\n", " BigramCollocationFinder,\n", ")\n", "from nltk.corpus import (\n", " stopwords,\n", " wordnet,\n", ")\n", "from nltk.stem import WordNetLemmatizer" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Data loading\n", "\n", "