{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Copyright (c) Recommenders contributors.\n", "\n", "Licensed under the MIT License." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# TF-IDF Content-Based Recommendation on the COVID-19 Open Research Dataset\n", "This demonstrates a simple implementation of Term Frequency Inverse Document Frequency (TF-IDF) content-based recommendation on the [COVID-19 Open Research Dataset](https://azure.microsoft.com/en-us/services/open-datasets/catalog/covid-19-open-research/), hosted through Azure Open Datasets.\n", "\n", "In this notebook, we will create a recommender which will return the top k recommended articles similar to any article of interest (query item) in the COVID-19 Open Research Dataset." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "System version: 3.6.11 | packaged by conda-forge | (default, Nov 27 2020, 18:57:37) \n", "[GCC 9.3.0]\n" ] } ], "source": [ "import sys\n", "\n", "from recommenders.datasets import covid_utils\n", "from recommenders.models.tfidf.tfidf_utils import TfidfRecommender\n", "\n", "# Print version\n", "print(f\"System version: {sys.version}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1. Load the dataset into a dataframe\n", "Let's begin by loading the metadata file for the dataset into a Pandas dataframe. This file contains metadata about each of the scientific articles included in the full dataset." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/scgraham/miniconda3/envs/reco_base/lib/python3.6/site-packages/IPython/core/interactiveshell.py:3263: DtypeWarning: Columns (13,14) have mixed types.Specify dtype option on import or set low_memory=False.\n", " if (await self.run_code(code, result, async_=asy)):\n" ] } ], "source": [ "# Specify container and metadata filename\n", "container_name = 'covid19temp'\n", "metadata_filename = 'metadata.csv'\n", "sas_token = '' # please see Azure Open Datasets notebook for SAS token\n", "\n", "# Get metadata (may take around 1-2 min)\n", "metadata = covid_utils.load_pandas_df(container_name=container_name, metadata_filename=metadata_filename, azure_storage_sas_token=sas_token)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 2. Extract articles in the public domain\n", "The dataset contains articles using a variety of licenses. We will only be using articles that fall under the public domain ([cc0](https://creativecommons.org/publicdomain/zero/1.0/))." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAE5CAYAAACQ6Vd4AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAqaUlEQVR4nO3de7hcVX3/8feHBJC7XBKEBEmUFAooIAGiUkRSJVYRRMBQ0FTSRhAVflW52PbxgtGgRSpUsCm3gEKIoCWoqGm4WAoNHAQJ4VJSiJCCJMhFtIIEvr8/1hoyZzI5Z2bPOucMJ5/X88wzM2tmf8+amX32d++11l5bEYGZmdl6Q10BMzPrDk4IZmYGOCGYmVnmhGBmZoATgpmZZU4IZmYGOCGYrUHSn0l6YKjrYTbY5PMQbF0maRnw1xHx70NdF7Oh5iMEMzMDnBDM1iDpQEnL657vIOn7klZK+o2kf6577ThJ90l6WtJPJe1Y91pIOl7Sg/n1b0lSfm0nSTdJelbSk5KurFtuF0kLJD0l6QFJRw3WZ7d1mxOCWR8kjQB+CPwKGAeMAebm1w4DPgccDowC/gO4oiHE+4B9gD2Ao4CDc/kZwM+ALYGxwLk55ibAAuByYDRwNHCepN0G4OOZ9eKEYNa3fYHtgc9GxO8j4vmIuDm/9jHgqxFxX0SsAr4C7Fl/lADMiohnIuIR4AZgz1z+IrAjsH1DzPcByyLi4ohYFRG/AK4GjhjQT2mGE4JZf3YAfpU3+I12BL4p6RlJzwBPASIdRdT8uu7x/wGb5sen5PfeJmmJpOPqYu5Xi5njHgO8rtQHMlubkUNdAbMu9yjwekkjmySFR4GZEfHddoNGxK+BvwGQtD/w75J+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T/iONLklFeT+k72J/0+ew5dzXhzfTNWRDwtqZMdpKLT3w/Lf84ut18eV34nvLJCbDDUlaqJCmPw+1D6Wg3drPRGcmvSkN3acMfPk4Y7HkAaTdPOBeNflvSJSCe6za9Yn3pdOa15jdIEjc+Qrk1xaqy+wtkipaknhlLRnaQoPP29E8LgezF36NXG5o+i7gSw4aT0ytrlSm8kSw93XCDpM6zZSd1y84m6f1rzmg8DewHjgVOVrykREV+KNmcpHQDFd5Ki4PT3TgiD7xzSnPmj80iSI0hDxoalkitrNxrAjWTp4Y7H5Xp9vKG8ncEMAzIH/wD4Bquvg175+scDodt3ktypPAQk7UKaI0XAwk7ParWhowGc1rjwcMdm1374dkS0PXNnQ9xunNa86HXQ1yVOCGaFdelGckCu/aDuvKbHbODcKHcd9HWGm4zMyltnrv1AgRk7S5G0mHT0MxL4qKSHKHMd9HWGE4JZeV2zkaxzp6RJEfFfQMlrP3TNtOakcw6sA24yMitMBaY1LqVur3l90kR5j+TnOwL3VmlrLz1jp3UPJwSzArp1I6mBufbDOjOt+brGTUZmZZSe1riIwica1qwz05qva7ppHn6zV7M1NpIM3x2uhyR9StL6+XYSw3ha83WJE4JZGevSRvJ44G2kk/GWk65NXXkOfuseTghmZaxLG8mvA8dHxOiI2BY4kTSTqr3KDddDWrPBVttIPgOrpzUmTRkx3JSesdO6hI8QzMpYYyNJmmBtOFovJzxgeE9rvq7xj2hWxjpz7QfWrWnN1ynDdYU1G2zrzEay22fstOp8YppZIZJ2ZfVGcqE3kvZq44RgZmaAO5XNzCxzQjAzM8AJwczMMicEMzMDnBDMzCz7/8m3n1uatRdcAAAAAElFTkSuQmCC", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "# View distribution of license types in the dataset\n", "metadata['license'].value_counts().plot(kind='bar', title='License')" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# Extract metadata on public domain articles only\n", "metadata_public = metadata.loc[metadata['license']=='cc0']\n", "\n", "# Clean dataframe\n", "metadata_public = covid_utils.clean_dataframe(metadata_public)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's look at the top few rows of this dataframe which contains metadata on public domain articles." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of articles in dataset: 134206\n", "Number of articles in dataset that fall under the public domain (cc0): 274\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
cord_uidshasource_xtitledoipmcidpubmed_idlicenseabstractpublish_timeauthorsjournalmag_idwho_covidence_idarxiv_idpdf_json_filespmc_json_filesurls2_id
0ej795nksa3c3b7c38ad32e1042d78aae2027ca491e9f2197PMCUnderstanding the Spatial Clustering of Severe...10.1289/ehp.7117PMC124762015531441.0cc0We applied cartographic and geostatistical met...2004-07-27Lai, P.C.; Wong, C.M.; Hedley, A.J.; Lo, S.V.;...Environ Health PerspectNaNNaNNaNdocument_parses/pdf_json/a3c3b7c38ad32e1042d78...document_parses/pmc_json/PMC1247620.xml.jsonhttps://www.ncbi.nlm.nih.gov/pmc/articles/PMC1...NaN
19mzs5dl4c1c6a98c21304f3788b20870b34afd8a115fa38cPMCThe Application of the Haddon Matrix to Public...10.1289/ehp.7491PMC125754815866764.0cc0State and local health departments continue to...2005-02-02Barnett, Daniel J.; Balicer, Ran D.; Blodgett,...Environ Health PerspectNaNNaNNaNdocument_parses/pdf_json/c1c6a98c21304f3788b20...document_parses/pmc_json/PMC1257548.xml.jsonhttps://www.ncbi.nlm.nih.gov/pmc/articles/PMC1...NaN
2u7lz3spec56ffdaf1cfbae5a6ed0abea495eaf7fa1cbc031PMCCynomolgus Macaque as an Animal Model for Seve...10.1371/journal.pmed.0030149PMC143578816605302.0cc0BACKGROUND: The emergence of severe acute resp...2006-04-18Lawler, James V; Endy, Timothy P; Hensley, Lis...PLoS MedNaNNaNNaNdocument_parses/pdf_json/c56ffdaf1cfbae5a6ed0a...document_parses/pmc_json/PMC1435788.xml.jsonhttps://www.ncbi.nlm.nih.gov/pmc/articles/PMC1...NaN
3na7z92i8f38f3b112e4b702b60ba56be806d418bbb2b83c3PMCImmune Protection of Nonhuman Primates against...10.1371/journal.pmed.0030177PMC145948216683867.0cc0BACKGROUND: Ebola virus causes a hemorrhagic f...2006-05-16Sullivan, Nancy J; Geisbert, Thomas W; Geisber...PLoS MedNaNNaNNaNdocument_parses/pdf_json/f38f3b112e4b702b60ba5...document_parses/pmc_json/PMC1459482.xml.jsonhttps://www.ncbi.nlm.nih.gov/pmc/articles/PMC1...NaN
4j35w1vsw5dc0b8b662824323881c3a1ae3a1bae2a821484dPMCSARS: Systematic Review of Treatment Effects10.1371/journal.pmed.0030343PMC156416616968120.0cc0BACKGROUND: The SARS outbreak of 2002–2003 pre...2006-09-12Stockman, Lauren J; Bellamy, Richard; Garner, ...PLoS MedNaNNaNNaNdocument_parses/pdf_json/5dc0b8b662824323881c3...document_parses/pmc_json/PMC1564166.xml.jsonhttps://www.ncbi.nlm.nih.gov/pmc/articles/PMC1...NaN
\n", "
" ], "text/plain": [ " cord_uid sha source_x \\\n", "0 ej795nks a3c3b7c38ad32e1042d78aae2027ca491e9f2197 PMC \n", "1 9mzs5dl4 c1c6a98c21304f3788b20870b34afd8a115fa38c PMC \n", "2 u7lz3spe c56ffdaf1cfbae5a6ed0abea495eaf7fa1cbc031 PMC \n", "3 na7z92i8 f38f3b112e4b702b60ba56be806d418bbb2b83c3 PMC \n", "4 j35w1vsw 5dc0b8b662824323881c3a1ae3a1bae2a821484d PMC \n", "\n", " title \\\n", "0 Understanding the Spatial Clustering of Severe... \n", "1 The Application of the Haddon Matrix to Public... \n", "2 Cynomolgus Macaque as an Animal Model for Seve... \n", "3 Immune Protection of Nonhuman Primates against... \n", "4 SARS: Systematic Review of Treatment Effects \n", "\n", " doi pmcid pubmed_id license \\\n", "0 10.1289/ehp.7117 PMC1247620 15531441.0 cc0 \n", "1 10.1289/ehp.7491 PMC1257548 15866764.0 cc0 \n", "2 10.1371/journal.pmed.0030149 PMC1435788 16605302.0 cc0 \n", "3 10.1371/journal.pmed.0030177 PMC1459482 16683867.0 cc0 \n", "4 10.1371/journal.pmed.0030343 PMC1564166 16968120.0 cc0 \n", "\n", " abstract publish_time \\\n", "0 We applied cartographic and geostatistical met... 2004-07-27 \n", "1 State and local health departments continue to... 2005-02-02 \n", "2 BACKGROUND: The emergence of severe acute resp... 2006-04-18 \n", "3 BACKGROUND: Ebola virus causes a hemorrhagic f... 2006-05-16 \n", "4 BACKGROUND: The SARS outbreak of 2002–2003 pre... 2006-09-12 \n", "\n", " authors journal \\\n", "0 Lai, P.C.; Wong, C.M.; Hedley, A.J.; Lo, S.V.;... Environ Health Perspect \n", "1 Barnett, Daniel J.; Balicer, Ran D.; Blodgett,... Environ Health Perspect \n", "2 Lawler, James V; Endy, Timothy P; Hensley, Lis... PLoS Med \n", "3 Sullivan, Nancy J; Geisbert, Thomas W; Geisber... PLoS Med \n", "4 Stockman, Lauren J; Bellamy, Richard; Garner, ... PLoS Med \n", "\n", " mag_id who_covidence_id arxiv_id \\\n", "0 NaN NaN NaN \n", "1 NaN NaN NaN \n", "2 NaN NaN NaN \n", "3 NaN NaN NaN \n", "4 NaN NaN NaN \n", "\n", " pdf_json_files \\\n", "0 document_parses/pdf_json/a3c3b7c38ad32e1042d78... \n", "1 document_parses/pdf_json/c1c6a98c21304f3788b20... \n", "2 document_parses/pdf_json/c56ffdaf1cfbae5a6ed0a... \n", "3 document_parses/pdf_json/f38f3b112e4b702b60ba5... \n", "4 document_parses/pdf_json/5dc0b8b662824323881c3... \n", "\n", " pmc_json_files \\\n", "0 document_parses/pmc_json/PMC1247620.xml.json \n", "1 document_parses/pmc_json/PMC1257548.xml.json \n", "2 document_parses/pmc_json/PMC1435788.xml.json \n", "3 document_parses/pmc_json/PMC1459482.xml.json \n", "4 document_parses/pmc_json/PMC1564166.xml.json \n", "\n", " url s2_id \n", "0 https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1... NaN \n", "1 https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1... NaN \n", "2 https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1... NaN \n", "3 https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1... NaN \n", "4 https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1... NaN " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Preview metadata for public domain articles\n", "print('Number of articles in dataset: ' + str(len(metadata)))\n", "print('Number of articles in dataset that fall under the public domain (cc0): ' + str(len(metadata_public)))\n", "metadata_public.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 3. Retrieve full article text\n", "Now that we have the metadata for the public domain articles as its own dataframe, let's retrieve the full text for each public domain scientific article." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "# Extract text from all public domain articles (may take 2-3 min)\n", "all_text = covid_utils.get_public_domain_text(df=metadata_public, container_name=container_name, azure_storage_sas_token=sas_token)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Notice that **all_text** is the same as **metadata_public** but now has an additional column called **full_text** which contains the full text for each respective article." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
indexcord_uiddoititlepublish_timeauthorsjournalurlabstractfull_text
00ej795nks10.1289/ehp.7117Understanding the Spatial Clustering of Severe...2004-07-27Lai, P.C.; Wong, C.M.; Hedley, A.J.; Lo, S.V.;...Environ Health Perspecthttps://www.ncbi.nlm.nih.gov/pmc/articles/PMC1...We applied cartographic and geostatistical met...Since the emergence and rapid spread of the et...
119mzs5dl410.1289/ehp.7491The Application of the Haddon Matrix to Public...2005-02-02Barnett, Daniel J.; Balicer, Ran D.; Blodgett,...Environ Health Perspecthttps://www.ncbi.nlm.nih.gov/pmc/articles/PMC1...State and local health departments continue to...sudden fever and dry cough, along with chills ...
22u7lz3spe10.1371/journal.pmed.0030149Cynomolgus Macaque as an Animal Model for Seve...2006-04-18Lawler, James V; Endy, Timothy P; Hensley, Lis...PLoS Medhttps://www.ncbi.nlm.nih.gov/pmc/articles/PMC1...BACKGROUND: The emergence of severe acute resp...The emergence of severe acute respiratory synd...
33na7z92i810.1371/journal.pmed.0030177Immune Protection of Nonhuman Primates against...2006-05-16Sullivan, Nancy J; Geisbert, Thomas W; Geisber...PLoS Medhttps://www.ncbi.nlm.nih.gov/pmc/articles/PMC1...BACKGROUND: Ebola virus causes a hemorrhagic f...Background Ebola virus causes a hemorrhagic fe...
44j35w1vsw10.1371/journal.pmed.0030343SARS: Systematic Review of Treatment Effects2006-09-12Stockman, Lauren J; Bellamy, Richard; Garner, ...PLoS Medhttps://www.ncbi.nlm.nih.gov/pmc/articles/PMC1...BACKGROUND: The SARS outbreak of 2002–2003 pre...The SARS outbreak of 2002-2003 presented clini...
\n", "
" ], "text/plain": [ " index cord_uid doi \\\n", "0 0 ej795nks 10.1289/ehp.7117 \n", "1 1 9mzs5dl4 10.1289/ehp.7491 \n", "2 2 u7lz3spe 10.1371/journal.pmed.0030149 \n", "3 3 na7z92i8 10.1371/journal.pmed.0030177 \n", "4 4 j35w1vsw 10.1371/journal.pmed.0030343 \n", "\n", " title publish_time \\\n", "0 Understanding the Spatial Clustering of Severe... 2004-07-27 \n", "1 The Application of the Haddon Matrix to Public... 2005-02-02 \n", "2 Cynomolgus Macaque as an Animal Model for Seve... 2006-04-18 \n", "3 Immune Protection of Nonhuman Primates against... 2006-05-16 \n", "4 SARS: Systematic Review of Treatment Effects 2006-09-12 \n", "\n", " authors journal \\\n", "0 Lai, P.C.; Wong, C.M.; Hedley, A.J.; Lo, S.V.;... Environ Health Perspect \n", "1 Barnett, Daniel J.; Balicer, Ran D.; Blodgett,... Environ Health Perspect \n", "2 Lawler, James V; Endy, Timothy P; Hensley, Lis... PLoS Med \n", "3 Sullivan, Nancy J; Geisbert, Thomas W; Geisber... PLoS Med \n", "4 Stockman, Lauren J; Bellamy, Richard; Garner, ... PLoS Med \n", "\n", " url \\\n", "0 https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1... \n", "1 https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1... \n", "2 https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1... \n", "3 https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1... \n", "4 https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1... \n", "\n", " abstract \\\n", "0 We applied cartographic and geostatistical met... \n", "1 State and local health departments continue to... \n", "2 BACKGROUND: The emergence of severe acute resp... \n", "3 BACKGROUND: Ebola virus causes a hemorrhagic f... \n", "4 BACKGROUND: The SARS outbreak of 2002–2003 pre... \n", "\n", " full_text \n", "0 Since the emergence and rapid spread of the et... \n", "1 sudden fever and dry cough, along with chills ... \n", "2 The emergence of severe acute respiratory synd... \n", "3 Background Ebola virus causes a hemorrhagic fe... \n", "4 The SARS outbreak of 2002-2003 presented clini... " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Preview\n", "all_text.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 4. Instantiate the recommender\n", "All functions for data preparation and recommendation are contained within the **TfidfRecommender** class we have imported. Prior to running these functions, we must create an object of this class.\n", "\n", "Select one of the following tokenization methods to use in the model:\n", "\n", "| tokenization_method | Description |\n", "|:--------------------|:---------------------------------------------------------------------------------------------------------------------------------|\n", "| 'none' | No tokenization is applied. Each word is considered a token. |\n", "| 'nltk' | Simple stemming is applied using NLTK. |\n", "| 'bert' | HuggingFace BERT word tokenization ('bert-base-cased') is applied. |\n", "| 'scibert' | SciBERT word tokenization ('allenai/scibert_scivocab_cased') is applied.
This is recommended for scientific journal articles. |" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "# Create the recommender object\n", "recommender = TfidfRecommender(id_col='cord_uid', tokenization_method='scibert')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 5. Prepare text for use in the TF-IDF recommender\n", "The raw text retrieved for each article requires basic cleaning prior to being used in the TF-IDF model.\n", "\n", "Let's look at the full_text from the first article in our dataframe as an example." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Since the emergence and rapid spread of the etiologic agent of severe acute respiratory syndrome (SARS)-SARS coronavirus (SARS-CoV)-in late 2002 and during the first 6 months of 2003, great progress has been made in understanding the biology, pathogenesis, and epidemiology of both the disease and the virus (SARS-CoV). Much remains to be done, however, including the development of effective therapeutic interventions and diagnostic tools with high sensitivity and specificity soon after the onset of clinical symptoms. The evaluation of key epidemiologic parameters and the impact of different public health interventions in the various settings that experienced minor or major epidemics is also needed (Affonso et al. 2004; Cui et al. 2003; Lau et al. 2004; Leung et al., in press) . In terms of outbreak control on the population level, many questions about \"superspreading events\" (SSEs) remain to be investigated. Such an SSE was responsible for > 300 cases (out of a total of 1,755) in the Amo\n" ] } ], "source": [ "# Preview the first 1000 characters of the full scientific text from one example\n", "print(all_text['full_text'][0][:1000])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As seen above, there are some special characters (such as • ▲ ■ ≥ °) and punctuation which should be removed prior to using the text as input. Casing (capitalization) is preserved for [BERT-based tokenization methods](https://huggingface.co/transformers/model_doc/bert.html), but is removed for simple or no tokenization.\n", "\n", "Let's join together the **title**, **abstract**, and **full_text** columns and clean them for future use in the TF-IDF model." ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "# Assign columns to clean and combine\n", "cols_to_clean = ['title','abstract','full_text']\n", "clean_col = 'cleaned_text'\n", "df_clean = recommender.clean_dataframe(all_text, cols_to_clean, clean_col)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
indexcord_uiddoititlepublish_timeauthorsjournalurlabstractfull_textcleaned_text
00ej795nks10.1289/ehp.7117Understanding the Spatial Clustering of Severe...2004-07-27Lai, P.C.; Wong, C.M.; Hedley, A.J.; Lo, S.V.;...Environ Health Perspecthttps://www.ncbi.nlm.nih.gov/pmc/articles/PMC1...We applied cartographic and geostatistical met...Since the emergence and rapid spread of the et...Understanding the Spatial Clustering of Severe...
119mzs5dl410.1289/ehp.7491The Application of the Haddon Matrix to Public...2005-02-02Barnett, Daniel J.; Balicer, Ran D.; Blodgett,...Environ Health Perspecthttps://www.ncbi.nlm.nih.gov/pmc/articles/PMC1...State and local health departments continue to...sudden fever and dry cough, along with chills ...The Application of the Haddon Matrix to Public...
22u7lz3spe10.1371/journal.pmed.0030149Cynomolgus Macaque as an Animal Model for Seve...2006-04-18Lawler, James V; Endy, Timothy P; Hensley, Lis...PLoS Medhttps://www.ncbi.nlm.nih.gov/pmc/articles/PMC1...BACKGROUND: The emergence of severe acute resp...The emergence of severe acute respiratory synd...Cynomolgus Macaque as an Animal Model for Seve...
33na7z92i810.1371/journal.pmed.0030177Immune Protection of Nonhuman Primates against...2006-05-16Sullivan, Nancy J; Geisbert, Thomas W; Geisber...PLoS Medhttps://www.ncbi.nlm.nih.gov/pmc/articles/PMC1...BACKGROUND: Ebola virus causes a hemorrhagic f...Background Ebola virus causes a hemorrhagic fe...Immune Protection of Nonhuman Primates against...
44j35w1vsw10.1371/journal.pmed.0030343SARS: Systematic Review of Treatment Effects2006-09-12Stockman, Lauren J; Bellamy, Richard; Garner, ...PLoS Medhttps://www.ncbi.nlm.nih.gov/pmc/articles/PMC1...BACKGROUND: The SARS outbreak of 2002–2003 pre...The SARS outbreak of 2002-2003 presented clini...SARS Systematic Review of Treatment Effects BA...
\n", "
" ], "text/plain": [ " index cord_uid doi \\\n", "0 0 ej795nks 10.1289/ehp.7117 \n", "1 1 9mzs5dl4 10.1289/ehp.7491 \n", "2 2 u7lz3spe 10.1371/journal.pmed.0030149 \n", "3 3 na7z92i8 10.1371/journal.pmed.0030177 \n", "4 4 j35w1vsw 10.1371/journal.pmed.0030343 \n", "\n", " title publish_time \\\n", "0 Understanding the Spatial Clustering of Severe... 2004-07-27 \n", "1 The Application of the Haddon Matrix to Public... 2005-02-02 \n", "2 Cynomolgus Macaque as an Animal Model for Seve... 2006-04-18 \n", "3 Immune Protection of Nonhuman Primates against... 2006-05-16 \n", "4 SARS: Systematic Review of Treatment Effects 2006-09-12 \n", "\n", " authors journal \\\n", "0 Lai, P.C.; Wong, C.M.; Hedley, A.J.; Lo, S.V.;... Environ Health Perspect \n", "1 Barnett, Daniel J.; Balicer, Ran D.; Blodgett,... Environ Health Perspect \n", "2 Lawler, James V; Endy, Timothy P; Hensley, Lis... PLoS Med \n", "3 Sullivan, Nancy J; Geisbert, Thomas W; Geisber... PLoS Med \n", "4 Stockman, Lauren J; Bellamy, Richard; Garner, ... PLoS Med \n", "\n", " url \\\n", "0 https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1... \n", "1 https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1... \n", "2 https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1... \n", "3 https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1... \n", "4 https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1... \n", "\n", " abstract \\\n", "0 We applied cartographic and geostatistical met... \n", "1 State and local health departments continue to... \n", "2 BACKGROUND: The emergence of severe acute resp... \n", "3 BACKGROUND: Ebola virus causes a hemorrhagic f... \n", "4 BACKGROUND: The SARS outbreak of 2002–2003 pre... \n", "\n", " full_text \\\n", "0 Since the emergence and rapid spread of the et... \n", "1 sudden fever and dry cough, along with chills ... \n", "2 The emergence of severe acute respiratory synd... \n", "3 Background Ebola virus causes a hemorrhagic fe... \n", "4 The SARS outbreak of 2002-2003 presented clini... \n", "\n", " cleaned_text \n", "0 Understanding the Spatial Clustering of Severe... \n", "1 The Application of the Haddon Matrix to Public... \n", "2 Cynomolgus Macaque as an Animal Model for Seve... \n", "3 Immune Protection of Nonhuman Primates against... \n", "4 SARS Systematic Review of Treatment Effects BA... " ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Preview the dataframe with the cleaned text\n", "df_clean.head()" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Understanding the Spatial Clustering of Severe Acute Respiratory Syndrome SARS in Hong Kong We applied cartographic and geostatistical methods in analyzing the patterns of disease spread during the 2003 severe acute respiratory syndrome SARS outbreak in Hong Kong using geographic information system GIS technology We analyzed an integrated database that contained clinical and personal details on all 1755 patients confirmed to have SARS from 15 February to 22 June 2003 Elementary mapping of disease occurrences in space and time simultaneously revealed the geographic extent of spread throughout the territory Statistical surfaces created by the kernel method confirmed that SARS cases were highly clustered and identified distinct disease hot spots Contextual analysis of mean and standard deviation of different density classes indicated that the period from day 1 18 February through day 16 6 March was the prodrome of the epidemic whereas days 86 15 May to 106 4 June marked the declining phas\n" ] } ], "source": [ "# Preview the first 1000 characters of the cleaned version of the previous example\n", "print(df_clean[clean_col][0][:1000])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's also tokenize the cleaned text for use in the TF-IDF model. The tokens are stored within our TfidfRecommender object." ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "# Tokenize text with tokenization_method specified in class instantiation\n", "tf, vectors_tokenized = recommender.tokenize_text(df_clean, text_col=clean_col)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 6. Recommend articles using TF-IDF\n", "Let's now fit the recommender model to the processed data (tokens) and retrieve the top k recommended articles.\n", "\n", "When creating our object, we specified k=5 so the `recommend_top_k_items` function will return the top 5 recommendations for each public domain article." ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "scrolled": true }, "outputs": [], "source": [ "# Fit the TF-IDF vectorizer\n", "recommender.fit(tf, vectors_tokenized)\n", "\n", "# Get recommendations\n", "top_k_recommendations = recommender.recommend_top_k_items(df_clean, k=5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In our recommendation table, each row represents a single recommendation.\n", "\n", "- **cord_uid** corresponds to the article that is being used to make recommendations from.\n", "- **rec_rank** contains the recommdation's rank (e.g., rank of 1 means top recommendation).\n", "- **rec_score** is the cosine similarity score between the query article and the recommended article.\n", "- **rec_cord_uid** corresponds to the recommended article." ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
cord_uidrec_rankrec_scorerec_cord_uid
0ej795nks10.142033u7lz3spe
1ej795nks20.117743j35w1vsw
2ej795nks30.100325nt60lv2k
3ej795nks40.076779vp9d9vmp
4ej795nks50.07439205d1mhkq
...............
1280yetdnv6j10.0484999w9w0z4o
1281yetdnv6j20.0466756nas74q1
1282yetdnv6j30.0444767docv0dt
1283yetdnv6j40.040522oj60pldq
1284yetdnv6j50.039635jq1xumrh
\n", "

1285 rows × 4 columns

\n", "
" ], "text/plain": [ " cord_uid rec_rank rec_score rec_cord_uid\n", "0 ej795nks 1 0.142033 u7lz3spe\n", "1 ej795nks 2 0.117743 j35w1vsw\n", "2 ej795nks 3 0.100325 nt60lv2k\n", "3 ej795nks 4 0.076779 vp9d9vmp\n", "4 ej795nks 5 0.074392 05d1mhkq\n", "... ... ... ... ...\n", "1280 yetdnv6j 1 0.048499 9w9w0z4o\n", "1281 yetdnv6j 2 0.046675 6nas74q1\n", "1282 yetdnv6j 3 0.044476 7docv0dt\n", "1283 yetdnv6j 4 0.040522 oj60pldq\n", "1284 yetdnv6j 5 0.039635 jq1xumrh\n", "\n", "[1285 rows x 4 columns]" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Preview the recommendations\n", "top_k_recommendations" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Optionally, we can access the full recommendation dictionary, which contains full ranked lists for each public domain article." ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of recommended articles for ej795nks: 256\n" ] } ], "source": [ "# Optionally view full recommendation list\n", "full_rec_list = recommender.recommendations\n", "\n", "article_of_interest = 'ej795nks'\n", "print('Number of recommended articles for ' + article_of_interest + ': ' + str(len(full_rec_list[article_of_interest])))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Optionally, we can also view the tokens and stop words which were used in the recommender." ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['understanding', 'spatial', 'clustering', 'severe', 'acute', 'respiratory', 'syndrome', 'sa', 'rs', 'hon']\n" ] } ], "source": [ "# Optionally view tokens\n", "tokens = recommender.get_tokens()\n", "\n", "# Preview 10 tokens\n", "print(list(tokens.keys())[:10])" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['a', 'about', 'above', 'across', 'after', 'afterwards', 'again', 'against', 'all', 'almost']\n" ] } ], "source": [ "# Preview just the first 10 stop words sorted alphabetically\n", "stop_words = list(recommender.get_stop_words())\n", "stop_words.sort()\n", "print(stop_words[:10])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 7. Display top recommendations for article of interest\n", "Now that we have the recommendation table containing IDs for both query and recommended articles, we can easily return the full metadata for the top k recommendations for any given article." ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "scrolled": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
rank similarity_score title authors journal publish_time url
010.142033Cynomolgus Macaque as an Animal Model for Severe Acute Respiratory SyndromeLawler, James V; Endy, Timothy P; Hensley, Lisa E; Garrison, Aura; Fritz, Elizabeth A; Lesar, May; Baric, Ralph S; Kulesh, David A; Norwood, David A; Wasieloski, Leonard P; Ulrich, Melanie P; Slezak, Tom R; Vitalis, Elizabeth; Huggins, John W; Jahrling, Peter B; Paragas, JasonPLoS Med2006-04-18https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1435788/
120.117743SARS: Systematic Review of Treatment EffectsStockman, Lauren J; Bellamy, Richard; Garner, PaulPLoS Med2006-09-12https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1564166/
230.100325A Network Integration Approach to Predict Conserved Regulators Related to Pathogenicity of Influenza and SARS-CoV Respiratory VirusesMitchell, Hugh D.; Eisfeld, Amie J.; Sims, Amy C.; McDermott, Jason E.; Matzke, Melissa M.; Webb-Robertson, Bobbi-Jo M.; Tilton, Susan C.; Tchitchek, Nicolas; Josset, Laurence; Li, Chengjun; Ellis, Amy L.; Chang, Jean H.; Heegel, Robert A.; Luna, Maria L.; Schepmoes, Athena A.; Shukla, Anil K.; Metz, Thomas O.; Neumann, Gabriele; Benecke, Arndt G.; Smith, Richard D.; Baric, Ralph S.; Kawaoka, Yoshihiro; Katze, Michael G.; Waters, Katrina M.PLoS One2013-07-25https://doi.org/10.1371/journal.pone.0069374; https://www.ncbi.nlm.nih.gov/pubmed/23935999/
340.076779Genome Wide Identification of SARS-CoV Susceptibility Loci Using the Collaborative CrossGralinski, Lisa E.; Ferris, Martin T.; Aylor, David L.; Whitmore, Alan C.; Green, Richard; Frieman, Matthew B.; Deming, Damon; Menachery, Vineet D.; Miller, Darla R.; Buus, Ryan J.; Bell, Timothy A.; Churchill, Gary A.; Threadgill, David W.; Katze, Michael G.; McMillan, Leonard; Valdar, William; Heise, Mark T.; Pardo-Manuel de Villena, Fernando; Baric, Ralph S.PLoS Genet2015-10-09https://doi.org/10.1371/journal.pgen.1005504; https://www.ncbi.nlm.nih.gov/pubmed/26452100/
450.074392A Porcine Epidemic Diarrhea Virus Outbreak in One Geographic Region of the United States: Descriptive Epidemiology and Investigation of the Possibility of Airborne Virus SpreadBeam, Andrea; Goede, Dane; Fox, Andrew; McCool, Mary Jane; Wall, Goldlin; Haley, Charles; Morrison, RobertPLoS One2015-12-28https://doi.org/10.1371/journal.pone.0144818; https://www.ncbi.nlm.nih.gov/pubmed/26709512/
" ], "text/plain": [ "" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cols_to_keep = ['title','authors','journal','publish_time','url']\n", "recommender.get_top_k_recommendations(metadata_public,article_of_interest,cols_to_keep)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Conclusion\n", "In this notebook, we have demonstrated how to create a TF-IDF recommender to recommend the top k (in this case 5) articles similar in content to an article of interest (in this example, article with `cord_uid='ej795nks'`)." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.6.11" } }, "nbformat": 4, "nbformat_minor": 2 }