Relation Extraction using TensorFlow
This Relation Extraction model employs word embeddings, word positions (inside a sentence), Brown clusters, and Part of Speech tags as its inputs. It is an advanced model of the work I presented during the course, the link to which can be found below. Two separate models are provided here: a CNN model that achieves 49% F1-score, and a Bi-GRU model that achieves 51% F1-score. A Bi-LSTM was also tried, without any difference in the outcome.
This repository only contains the files that I personally worked on, as a distilled version of my contributions. It consists of the Python scripts that generate the model, and the Java classes that load and run the model. The whole thing can be found here. The presentation of the work I've done can be found here.
network.py file builds the network and trains it. The data is loaded by
loader.py. The final piece of the puzzle is
TFRelationTagger.java, which loads a frozen model generated by
network.py in Java. Again, note that since I continued the research past the project deadline, the Java file is not updated to match the new network. As such, it serves more as a non-trivial proof of concept of how to run Tensorflow models in Java. The working version can be found in the original repo.
There are 3 different ways of classification schemes (or relation type details) for relation extraction that are used here. First is the basic relation types, where only the 6 main ACE relation types are used (7 total with
other class representing no relation). Then there are the subtypes, where two relations only match if their subtypes match. There are 19 total classes in this scheme (18 +
other). The last is the subclass with ordering, where two relations only match iff their subtypes match and the relationship order is preserved. There are 37 total classes in this scheme (36 +
Choosing a type detail
For the 3 different levels of details in classification, you need to set the
relation_detail variable, with the values
subtype_with_order for 7, 19, 37 classes respectively.
Running the code
Detailed instructions are found in the original repo. Again, note that it is not the newest version of the model. If you can generate your own training data, you can also simply use the Python scripts provided here.
Make sure that you have Tensorflow installed. For Java integration, version 1.3.0 is needed. The Python scripts should work with the new releases, until there is a breaking change in the API.
Necessary Data Files
The project is missing the ACE files, which are available through LDC. It is converted to an intermediate representation by my extension of
JetLite, and is read by
loader.py. The other requirements are the GloVe pretrained word embeddings file, which can be found on the Stanford NLP's GloVe website, and Brown Clusters, which can be found here.