Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Language Model Zoo

zoo-logo

CircleCI

This folder contains scripts for obtaining surprisals from the following pre-trained language models:

  1. GRNN
  2. JRNN
  3. RNNG
  4. Transformer-XL
  5. Tiny LSTM
  6. 5-gram with Kneser-Ney smoothing
  7. coming soon: BERT

models

The models use the following tokenizers:

Model Tokenizer
GRNN TreeTagger
JRNN WMT11 tokenizer
RNNG PTB tokenizer
Tiny PTB tokenizer
Trans Moses (one implementation)
ngram TreeTagger

The parameters are taken from the standard published version of each model unless stated otherwise.

Scripts

Surprisals can be obtained from each model using the script eval_<MODEL>.sh in the scripts folder. Each script expects two arguments: $1 is the input file containing the sentences, and $2 is the output file to save the surprisals.

Input file format

The input file should have each sentence on a new line, and each sentence should be tokenized.

There are also some model-specific constraints, although I may try to streamline these later:

  • For every model except RNNG and Tiny LSTM, the sentence should end with an <eos> token.
  • The n-gram model is uncased, so you'll have to convert your input file to lowercase to avoid getting unks. I am working on adding a script to do this.
  • For RNNG and Tiny LSTM, the input must be unkified. An unkify function is provided in rnng-incremental/get_raw.py, which can be used in the following way:
python2 get_raw.py train.02-21 \
    RAW.txt > UNKIFIED.txt

Output file format

The output file will have the following format:

token1 0.0
token2 ...
.      ...
<eos>  0.0

where the second column (separated by \t) gives the surprisal in bits of the token.

When you run eval_ngram.sh, you will also get an extra .raw output file that has the raw SRILM output with details about word probabilities and backoff.

Dependencies

LSTMs and Transformers

The GRNN, JRNN, Transformer-XL, and Tiny LSTM models require pytorch and other dependencies that can be found in their source folders. If you don't feel like creating your own environments, feel free to "steal" mine: /om2/user/jennhu/conda/envs/neural-nlp (credit to Martin Schrimpf) works for GRNN, JRNN, and Tiny LSTM, and /om2/user/jennhu/conda/envs/transXL was custom-built for Transformer-XL.

RNNG

The dependencies for RNNG should already be set in the source code. If problems arise, I may make a Singularity image available with the relevant C++ libraries.

n-gram

The dependencies for n-gram (SRILM) are also set in a Singularity image called in the script. However, by default, you will also need numpy to convert the raw SRILM output to the standard format. If you don't already have an active conda environment (which has numpy), simply use the command module add openmind/anaconda before running the n-gram script.

Note that I did not add this line to the top of the eval_ngram.sh file because users may want to run the n-gram model in their own preferred environments.

Other tips

When submitting jobs to SLURM, keep in mind that different models have different memory/time requirements. The following settings have worked for me in the past:

Model Suggested memory Speed GPU
GRNN 5G Medium Yes
JRNN 20G Medium No
RNNG 12G Slow No
Tiny 5G Fast No
Trans 5G Fast Yes
ngram 5G Fast No

The speed is relative to the other models; for reference, Tiny LSTM takes under 1 minute to calculate surprisal for 900 simple sentences (~7 words each), while RNNG takes several hours.

If using GPU, remember to request the appropriate resources in your sbatch call.

I may also add sample SLURM scripts if that would be helpful.

TODO

Adding models

Improving existing models

  • add GPU functionality

Ease of use

  • add README to each model folder with hyperparameters, etc.
  • add script for converting file to lowercase (for n-gram)
  • add script for tokenization
  • add SLURM script to submit all models as job array
  • add environments to shared folder

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lm-zoo-0.1rc0.tar.gz (6.2 kB view details)

Uploaded Source

File details

Details for the file lm-zoo-0.1rc0.tar.gz.

File metadata

  • Download URL: lm-zoo-0.1rc0.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.9

File hashes

Hashes for lm-zoo-0.1rc0.tar.gz
Algorithm Hash digest
SHA256 05e6e7bd92977e729787128fd494e5c976da06b1fb77a496db29b553b6f168aa
MD5 7e6c109739088f23c2efd764644561d4
BLAKE2b-256 01570c9d18bb301c09e9aae7efcffbd03717d9970671b56dbf6459453989953f

See more details on using hashes here.

Release history Release notifications | RSS feed

1.3

1 file

1.2.3

1 file

1.2.2

1 file

1.2.1

1 file

1.2

1 file

1.1.1

1 file

1.1

1 file

1.0.0

1 file

This release

0.1rc0 This release

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page