With the recent confusion in the United States Supreme Court, due to the ongoing health concerns of Justice Ruth Bader Ginsburg and the sudden death of Justice Antonin Scalia in 2016, I explored the idea of immortalizing their unique perspectives through data science and text generation.
Using a semantic-based word-level long short term memory ('LSTM') deep recurrent neural network ('RNN'), based on Gensim's Word2Vec library and documents written by each of the two justices, I generated brief simulated opinions. The goal was to generate sentence-like structures while tying pre-trained Word2Vec semantics to each of the words.
For an overview, please see the presentation for this model.
- Amazon Web Services
- BeautifulSoup
- MongoDB
- Pymongo
- Keras
- Gensim
Data was scraped using BeautifulSoup from Legal Information Institute hosted by Cornell Law School, specifically court opinions written by Justice Ruth Bader Ginsburg and Justice Antonin Scalia. Further details of all cases were acquired from Washington University Law's Supreme Court Database.
- Clean and explore the data, stored in MongoDB.
- Cleaned using Pymongo in Jupyter Notebook.
- Explored and selected areas of law that I wanted to focus on.
- Exported selection of case opinions into text files.
- Pre-processed text files using Python's regular expressions.
- Tokenized the sentences into individual words.
- Vectorized the words mapping each word to vectors in Gensim's Word2Vec library.
- In a GPU on an AWS instance, built and trained a 4 stacked LSTM RNN model. I do not recommend running this model on a CPU.
See Mongo_Cleaner.ipynb.
The LSTM RNN model is particularly useful to process sequences of words. The model is trained through iterations. Each iteration, the model trains on my text data for a set number of epochs. After each epoch, if the loss improves, the model overwrites and saves a newer version of itself. At the end of each iteration, the model takes in a seed sentence and generates text. All text generations are saved to a text file. And the iteration will restart.
See SUPREMES_BOT.ipynb.
The generations require some interpretation. Using Gensim's most_similar() function, I explored words that were in close proximity (using cosine distance) within the vectorspace of each word generated. For example, the word 'justice', was in the proximity to 'Constitution', 'rule', and 'law'.
I fed the following sentence regarding affirmative to the Ruth Bader GinsBot model:
"use of race discrimination in university admissions policy is lawful to achieve critical mass student body diversity"
"the utterly_contemptuous this Predatory_lending_practices Prudence_dictates Prudence_dictates intend Knee_Jerk_reactions"
Predatory lending practices has been linked by the U.S. Supreme Court to the discrimination of minorities. "Prudence_dictates intend Knee_jerk_reactions” implies a need for action. The generation captures Justice Ginsburg's consistent viewpoint that she disapproves of discrimination against minorities and that race-based government action to correct the effects of discrimination is lawful.

