p2327 / pytorch-paper-classifier

A simple model for classifying papers by academic venue (AI/ML/ACL), given a title and abstract. Bare-metal PyTorch port of https://github.com/allenai/allennlp-as-a-library-example .

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pytorch-paper-classifier

This is a bare-metal PyTorch implementation of the AllenNLP academic paper classifier example, which demonstrates how to build a model with AllenNLP as a dependency. This repo is fully functional, but it's main purpose is to demonstrate AllenNLP's value prop.

It's far less extensible than the version that uses AllenNLP, and less featureful as well (e.g., there's no bucketing of batches implemented and no early stopping). In addition, this code is far more complex and lengthy than the AllenNLP example (~630 Python LOC in this repo vs 110 in the AllenNLP example).

Table of Contents

Setting Up

The code in this project was developed with Python 3.6, so we recommend using that to run it. However, it was written as much as possible with cross-version support in mind, but it's untested on other Python versions.

Conda will set up a virtual environment with the exact version of Python used for development along with all the dependencies needed to run the code.

  1. Download and install Conda.

  2. Change your directory to your clone of this repo.

    cd pytorch-paper-classifier
    
  3. Create a Conda environment with Python 3.

    conda create -n paper_classifier python=3.6
    
  4. Now activate the Conda environment. You will need to activate the Conda environment in each terminal in which you want to run code from this repo.

    source activate paper_classifier
    
  5. Install the required dependencies.

    pip install -r requirements.txt
    
  6. Install the SpaCy English model.

    python -m spacy download en
    
  7. Visit http://pytorch.org and install the relevant PyTorch 0.3.1 package (latest as of mid-March 2018).

You should now be able to test your installation with pytest -v. Congratulations!

Downloading the data

To download the papers data and a gzipped GloVe vectors file, run:

./download_data.sh

This will download training and validation data to a ./data/ subdirectory, as well as a gzipped file of GloVe pretrained word vectors. The code looks for the data in this directory by default.

Basic Usage

To train a model with the default hyperparameters, simply run:

python run_model.py --save-dir ./saved_models/test

In this case, the model is saved to a directory at ./saved_models/test/ (it will be created if it doesn't already exist).

To see a list of all the different hyperparameters you can tweak, run:

python run_model.py -h

Visualizing Results

During and after training, you can visualize your results with Tensorboard (you have to install this separately, and there are a variety of ways to do so). To run Tensorboard while / after training the model above, run:

tensorboard --logdir saved_models/

and then navigate to http://localhost:6006/ (or http://hostname:6006/ , if running on a remote machine).

About

A simple model for classifying papers by academic venue (AI/ML/ACL), given a title and abstract. Bare-metal PyTorch port of https://github.com/allenai/allennlp-as-a-library-example .

License:MIT License


Languages

Language:Python 98.9%Language:Shell 1.1%