Pytorch implementation of the paper: SpanPredict: Extraction of Predictive Document Spans with Neural Attention
I'm implementing the architecture described in the paper as an educational exercise, to make sure I understand it. I'm making the code available as I could only find two implementations that were publicly available so far. One was in Tensorflow and the other was in Pytorch.
There is a lot of data wrangling and pretrained model code in the repo so far. I think if someone was interested in re-using this code they would just be interested in:
code/span_predict.py- For theSpanPredictmodulecode/jsd.py- For the JSD losscode/imdb_model.py- To see how to use theSpanPredictmodule
Parts of code/main.py might be useful to reference, to see how to handle training.
I've reproduced the CNN baseline model and SpanPredict models and trained them both against the IMDB dataset. I haven't gotten very far into inspecting the resulting spans, but the performance numbers closely match those from the paper. I'm updating this as I have time as a side project.
You'll need to:
- download the IMDB dataset
- download the glove embeddings
- Install python requirements from
requirements.txt
Steps:
- run the
code/prep_data.pyscript to generateimdb_train_test.csvfrom the IMDB dataset. - run
code/main.pyto train a model.- The boolean
SPAN_MODELsetting at the top of the script can be used to switch between the baseline CNN model (False) or SpanPredict model (True) - TODO: the new latter half of
code/main.pymay not work yet with the baseline CNN model
- The boolean
- TODO: I'm still working on this step
- The beginning of this is
code/inspect_model.py
- I currently use the entire ~400k GloVe vocabulary (I'm not computing token frequency to allow for token prioritization yet.)
- The learning settings (JSD ramp-up and epoch length) may be currently adjusted for faster training in an IMDB dataset-specific way.
- I'm experimenting with which weights to freeze (embedding weights, conv layers, etc.) and when in the training process