• Stars
    star
    119
  • Rank 296,207 (Top 6 %)
  • Language
    Python
  • Created almost 6 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Code for KGLM paper

Knowledge Graph Language Model

Build Status

This repo contains an implementation of the KGLM model described in "Barack's Wife Hillary: Using Knowledge Graphs for Fact-Aware Language Modeling", Robert L. Logan IV, Nelson F. Liu, Matthew E. Peters, Matt Gardner and Sameer Singh, ACL 2019 [arXiv].

Warning: To avoid confusion regarding placement of '@@END@@' tokens, we have explicitly added the '@@END@@' tokens to the Linked WikiText-2 dataset and removed preprocessing steps from the dataset reader. If you are using an old version of the dataset, you will need to download the current version here for this codebase to work.

Setup

You will need Python 3.5+. Dependencies can be installed by running:

pip install -r requirements.txt

Data

KGLM is trained on the Linked WikiText-2 dataset which can be downloaded at https://rloganiv.github.io/linked-wikitext-2.

Additionally, you will need embeddings for entities/relations in the Wikidata knowledge graph, as well as access to the knowledge graph itself (in order to look up entity aliases/related entities). For convenience, we provide pre-trained embeddings and pickled dictionaries containing the relevant portions of Wikidata here.

If you would like to apply our annotation pipeline to your own data, please refer to: https://github.com/rloganiv/kglm-data.

Training

To train the model run:

allennlp train [path to config] -s [path to save checkpoint to] --include-package kglm

example model configurations are provided in the experiments directory.

Perplexity Evaluation

To estimate perplexity of a trained model on held-out data run:

python -m kglm.run evaluate-perplexity \
    [model_archive_file] \
    [sampler_archive_file] \
    [input_file]

where:

  • model_archive_file - Trained (generative) model checkpoint. This is the model whose perplexity will be evaluated.
  • sampler_archive_file - Trained (discriminative) model checkpoint. This is the model used to create annotations during importance sampling. See Section 4 of the paper for more details about importance sampling.
  • input_file - Path to dataset to measure perplexity on.

Sentence Completion

To perform sentence completion experiments run:

python -m kglm.run predict --predictor cloze [model_archive_file] [input_file]

where

  • model_archive_file - Trained (generative) model checkpoint. This is the model whose perplexity will be evaluated.
  • input_file - Path to dataset to measure perplexity on.

More Repositories

1

kglm-data

Code used to create the Linked WikiText-2 dataset
Python
17
star
2

mae-model

Model code for 'Multimodal Attribute Extraction' paper.
Python
10
star
3

monolingual-nmt

For the ICLR Reproducibility Challenge 2017
Python
6
star
4

claimrank-allennlp

Python
5
star
5

pd-diag-net

A deep neural model for detecting Parkinsons Disease from Handwriting Samples. Final project for CS276a.
Python
5
star
6

autocli

Ceate command line interfaces for your Python code in seconds.
Python
5
star
7

mae-example

Jupyter notebook demonstrating multimodal attribute extraction models. For datalab presentation.
Jupyter Notebook
4
star
8

streaming-cdc

Code for "Benchmarking Scalable Methods for Streaming Cross Document Entity Coreference"
Python
3
star
9

linked-wikitext-2

Resources for downloading / viewing the Linked Wikitext-2 dataset.
JavaScript
3
star
10

claimrank

Code for the claim scoring subtask for post-modifier generation. Written at the TTIC 2018 CollaboWrite workshop.
Python
2
star
11

preprints

For storing preprints before they are published on arXiv.
1
star
12

py-avalanche

A Python implementation of the 'Bank Avalanche Model'.
Python
1
star
13

mae

Github pages site for the MAE dataset
CSS
1
star
14

cs271-sokoban-ai

A Sokoban implementation and problem solving agent. Final project for CS271.
C++
1
star
15

lm-acceptability

AllenNLP tools for performing acceptability judgements with language models.
Python
1
star
16

mturk-static

Mechanical Turk external question site for MAE dataset evaluation.
HTML
1
star
17

histree

Histogram + Tree
JavaScript
1
star
18

dmm

Dirichlet mixture model implementation
Python
1
star
19

description-gen

Models and evaluation code for automatic description generation.
Python
1
star
20

mturk-tools

Python
1
star
21

mae-mturk

Python
1
star
22

pcori_pytorch

Neural sequence labeling models for the PCORI project
Python
1
star
23

dgm-final-project

Final project for Deep Generative Models Spring 2019.
Python
1
star
24

rloganiv.github.io

Personal website.
HTML
1
star
25

realm-viz

A tool for visualizing annotated REALM data.
Python
1
star
26

ICML-2019-Workshop-Uncertainty-Robustness

Jupyter Notebook
1
star
27

seq-sampler

Tools for sampling sequences. Used for research with Padhraic Smyth and Efi Karra during Spring 2017.
Python
1
star