/BiMPM

BiMPM: Bilateral Multi-Perspective Matching for Natural Language Sentences

Primary LanguagePythonApache License 2.0Apache-2.0

BiMPM: Bilateral Multi-Perspective Matching for Natural Language Sentences

Description

This repository includes the source code for natural language sentence matching. Basically, the program will take two sentences as input, and predict a label for the two input sentences. You can use this program to deal with tasks like paraphrase identification, natural language inference, duplicate questions identification et al. More details about the underneath model can be found in our paper. Please cite our paper when you use this program! 😍

Requirements

  • python 2.7
  • tensorflow 0.12

Data format

Both the train and test set require a tab-separated format. Each line in the train (or test) file corresponds to an instance, and it should be arranged as

label sentence#1 sentence#2 other_info

For more details about the data format, you can download the Quora Question Pair dataset used in our paper.

Training

You can find the training script at BiMPM/src/SentenceMatchTrainer.py

To see all the optional arguments, just run

python BiMPM/src/SentenceMatchTrainer.py --help

Here is an example of how to train a very simple model:

python BiMPM/src/SentenceMatchTrainer.py --train_path train.tsv --dev_path dev.tsv --test_path test.tsv --word_vec_path wordvec.txt --suffix sample --fix_word_vec --model_dir models --MP_dim 20

To get a better performance on your own datasets, you need to play with other arguments. Here is one example of the command line configuration I used in my experiments.

Testing

You can find the testing script at BiMPM/src/SentenceMatchDecoder.py

To see all the optional arguments, just run

python BiMPM/src/SentenceMatchDecoder.py --help

Here is an example of how to test your model:

python BiMPM/src/SentenceMatchDecoder.py --in_path test.tsv --word_vec_path wordvec.txt --mode prediction --model_prefix models/SentenceMatch.sample --out_path test.prediction

The SentenceMatchDecoder.py can run in two modes:

  • prediction: predicting the label for each sentence pair
  • probs: outputting probabilities of all labels for each sentence pair

Reporting issues

Please let me know, if you encounter any problems.