A fork of Andrej Karpathy's www.arxiv-sanity.com/, fairXiv provides a modern responsive UI for searching papers on arXiv with improved usability and accessibility.
fairXiv host papers with a focus on AI ethics and statistical fairness, but you can fork this repo to host any slice of arXiv you like, if you want to reproduce the interface. Live at www.fairXiv.org/ serving over 1,000 of the latest arXiv papers (cs.[CV|AI|CL|CY|LG|NE]/stat.ML AND fairness|ethics|ethical|safety).
With this code base you could replicate the website to any of your favorite subsets of Arxiv by changing the categories in
There are two large parts of the code:
Indexing code. Uses Arxiv API to download the most recent papers in any categories you like, and then downloads all papers, extracts all text, creates tfidf vectors based on the content of each paper. This code is therefore concerned with the backend scraping and computation: building up a database of arxiv papers, calculating content vectors, creating thumbnails, computing SVMs for people, etc.
User interface. Then there is a web server (based on Flask/Tornado/sqlite) that allows searching through the database and filtering papers by similarity, etc.
Several: You will need numpy, feedparser (to process xml files), scikit learn (for tfidf vectorizer, training of SVM), flask (for serving the results), flask_limiter, and tornado (if you want to run the flask server in production). Also dateutil, and scipy. And sqlite3 for database (accounts, library support, etc.). Most of these are easy to get through
$ virtualenv env # optional: use virtualenv $ source env/bin/activate # optional: use virtualenv $ pip install -r requirements.txt
The processing pipeline requires you to run a series of scripts, and at this stage I really encourage you to manually inspect each script, as they may contain various inline settings you might want to change. In order, the processing pipeline is:
fetch_papers.pyto query arxiv API and create a file
db.pthat contains all information for each paper. This script is where you would modify the query, indicating which parts of arxiv you'd like to use. Note that if you're trying to pull too many papers arxiv will start to rate limit you. You may have to run the script multiple times, and I recommend using the arg
--start-indexto restart where you left off when you were last interrupted by arxiv.
download_pdfs.py, which iterates over all papers in parsed pickle and downloads the papers into folder
parse_pdf_to_text.pyto export all text from pdfs to files in
thumb_pdf.pyto export thumbnails of all pdfs to
analyze.pyto compute tfidf vectors for all documents based on bigrams. Saves a
buildsvm.pyto train SVMs for all users (if any), exports a pickle
make_cache.pyfor various preprocessing so that server starts faster (and make sure to run
sqlite3 as.db < schema.sqlif this is the very first time ever you're starting fairXiv, which initializes an empty database).
- Start the mongodb daemon in the background. Mongodb can be installed by following the instructions here - https://docs.mongodb.com/tutorials/install-mongodb-on-ubuntu/.
- Start the mongodb server with -
sudo service mongod start.
- Verify if the server is running in the background : The last line of /var/log/mongodb/mongod.log file must be -
[initandlisten] waiting for connections on port <port>
- Run the flask server with
serve.py. Visit localhost:5000 and enjoy sane viewing of papers!
Optionally you can also run the
twitter_daemon.py in a screen session, which uses your Twitter API credentials (stored in
twitter.txt) to query Twitter periodically looking for mentions of papers in the database, and writes the results to the pickle file
I have a simple shell script that runs these commands one by one, and every day I run this script to fetch new papers, incorporate them into the database, and recompute all tfidf vectors/classifiers. More details on this process below.
protip: numpy/BLAS: The script
analyze.py does quite a lot of heavy lifting with numpy. I recommend that you carefully set up your numpy to use BLAS (e.g. OpenBLAS), otherwise the computations will take a long time. With ~25,000 papers and ~5000 users the script runs in several hours on my current machine with a BLAS-linked numpy.
To run the script which hits the arXiv API and see some results in your terminal, play around with this:
python list_papers.py --search-query="cat:cs.LG+AND+all:fair+OR+cat:cs.LG+all:ethical" | less
If you'd like to run the flask server online (e.g. AWS) run it as
python serve.py --prod.
You also want to create a
secret_key.txt file and fill it with random text (see top of
Running the site live is not currently set up for a fully automatic plug and play operation. Instead it's a bit of a manual process and I thought I should document how I'm keeping this code alive right now. I have a script that performs the following update early morning after arxiv papers come out (~midnight PST):
python fetch_papers.py python download_pdfs.py python parse_pdf_to_text.py python thumb_pdf.py python analyze.py python buildsvm.py python make_cache.py
I run the server in a screen session, so
screen -S serve to create it (or
-r to reattach to it) and run:
python serve.py --prod --port 80
The server will load the new files and begin hosting the site. Note that on some systems you can't use port 80 without
sudo. Your two options are to use
iptables to reroute ports or you can use setcap to elavate the permissions of your
python interpreter that runs
serve.py. In this case I'd recommend careful permissions and maybe virtualenv, etc.