This repository contains the jupyter notebooks and requirements used for my project on topic modeling PubMed's 9000+ articles about 'stem cell therapies'. The notebooks are numbered in the order they have been used.
I used Selenium with Chrome Driver and Beautiful Soup to scrape 1000 search result pages on PubMed for the search term 'stem cell therapy'. The resulting dataframe contained 9926 rows and 12 columns, each columns holding information about an article that a user can find in PubMed in the order of relevance (deemed by PubMed):
article_id: PubMed ID for the articletitle: article's titlepublication_type: the type of publicationabstract: the article's abstractjournal_title: the title of the journal the article was published incitation: citation keyn_authors: number of authorsaffiliations: author affiliations (universities, company, country, etc)n_affiliations: the number of affiliations associated with the articlen_citations: the number of times the publication was citedkeywords: keywords linked to publication by PubMedn_references: the number of references used in the publication
This was my first look at the dataset. I removed duplicated rows, extracted certain features, reformatted the text data, and imputed missing data. Here I took a look at the change in the number of publications and keywords throughout the years.
To further the data exploration, I decided to fit classification models to the dataset to predict the 'influence' of a publication based on the number of citations. I used Scikit-Learn's extensive library to perform multiple grid search pipelines for feature engineering, hyper parameter optimization, model selection and evaluation.
I used Scikit-Learn's Latent Dirichlet Allocation (LDA) model to begin Topic Modeling with my dataset. For this, I preprocessed the data from scratch, extracting only the titles and abstracts, transforming them into lowercase, and removing punctuations. Using TF-IDF, I vectorized the resulting text data and fitted the LDA model to generate 10 topics. Based on the results, I optimized the topic extraction by adjusting the parameters for the vectorization, adding stop words and stemming the words.
Heavily influenced by Maarten Grootendorst's work, I used BERT for my Topic Model. For this task, I used Google Colab as it allowed me to use the GPU for model fitting. I leveraged allenai-specter, a sentence transformer pre-trained on 146K Semantic Scholar query results that learned document relatedness based on citation graphs. The dimension of the resulting embeddings were reduced using UMAP and clustered by HBDSCAN into topics. Then the entire text data from each topic was vectorized to extract the top 10 most important words within the topic. The model resulted in ~50 various topics. I performed the same task in a few lines using BERTopic, Maarten Grootendorst's specialized package for Topic Modeling with BERT.
In this final notebook, I attempted to evaluate the Topic Models based on the resulting topics from LDA and BERTopic. I looked at the similartiy of documents in each topic by calculating the average number of unique keywords in a sample of 100 articles. Finally I did a manual check on the sensibility of some of the common topics from both models by looking at the top 5 most cited publications in these topics.
This file contains all of the libraries used throughout this project and can be used to create an environment using:
$ conda create --name <env> --file <this file>
All of the data files generated and used in this repository can be found here. If following this repository froms start to finish, it is not strictly necessary to download these files. However, certain files will be required if you wish to skip ahead to a specific part of the project.