Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
419 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,40 @@ | ||
# Mimick | ||
Code for [Mimicking Word Embeddings using Subword RNNs](https://arxiv.org/abs/1707.06961) (EMNLP 2017) | ||
Code for [Mimicking Word Embeddings using Subword RNNs](http://www.aclweb.org/anthology/D17-1010) (EMNLP 2017) and subsequent experiments. | ||
|
||
I'm adding details to this documentation as I go. When I'm through, this comment will be gone. | ||
|
||
## tl;dr | ||
Given a word embedding dictionary (with vectors from, e.g. FastText or Polyglot or GloVe), Mimick trains a character-level neural net that learns to approximate the embeddings. It can then be applied to infer embeddings in the same space for words that were not available in the original set (i.e. OOVs - Out Of Vocabulary). | ||
|
||
## Dependencies | ||
The main dependency for this project is DyNet. Get it [here](http://dynet.readthedocs.io/en/latest/python.html). Their 2.0 version has just been released, and I hope to upgrade this project and models to that version at some point. | ||
The main dependency for this project is DyNet. Get it [here](http://dynet.readthedocs.io/en/latest/python.html). As of November 22, 2017, the code complies with Dynet 2.0. You may access the 1.0 version code via the commit log. | ||
|
||
## Create Mimick models | ||
The [mimick](mimick) directory contains scripts relevant to the Mimick model: dataset creation, model creation, intrinsic analysis. The [models](mimick/models) directory within contains models trained for all 23 languages mentioned in the paper. If you're using the pre-trained models, you don't need anything else from the [mimick](mimick) directory in order to run the tagging model. If you train new models, please add them here via pull request! | ||
The [mimick](mimick) directory contains scripts relevant to the Mimick model: dataset creation, model creation, intrinsic analysis (see readme within). The [models](mimick/models) directory within contains models trained for all 23 languages mentioned in the paper. If you're using the pre-trained models, you don't need anything else from the [mimick](mimick) directory in order to run the tagging model. If you train new models, please add them here via pull request! | ||
|
||
* November 22, 2017 note: the pre-trained models were saved in DyNet 1.0 format. It is still possible to load them using the `old_load()` function in `mimick/model.py`, but it could be somewhat of a pain. Another option is to use DyNet 1.0 and an old version of this codebase. | ||
I will be re-training and saving models in the new format, but don't expect it too soon. | ||
|
||
### CNN Version (November 2017) | ||
|
||
As of the November 22 [PR](https://github.com/yuvalpinter/Mimick/pull/2), there is a CNN version of Mimick available for training. It is currently a single-layer convolutional net (conv -> max-k-pool -> fully-connected -> tanh -> fully-connected) that performs the same function as the LSTM version. What is it good for? Wait for the paper 😎 | ||
|
||
## Tag parts-of-speech and morphosyntactic attributes using trained models | ||
The root directory of this repository contains the code required to perform extrinsic analysis on Universal Dependencies data. Vocabulary files are supplied in the [vocabs](vocabs) directory. | ||
|
||
The entry point is [model.py](model.py), which can use tagging datasets created using the [make_dataset.py](make_dataset.py) script. | ||
Note that `model.py` accepts pre-trained Word Embedding models via **text files** with no header. For Mimick models, this exact format is output into the path in [mimick/model.py](mimick/model.py) script's `--output` argument. For Word2Vec, FastText, or Polyglot models, one can create such a file using the [scripts/output_word_vectors.py](scripts/output_word_vectors.py) script that accepts a model (.pkl or .bin) and the desired output vocabulary (.txt). | ||
|
||
## Citation | ||
|
||
Please cite our paper if you use this code. | ||
|
||
```latex | ||
@inproceedings{pinter2017mimicking, | ||
title={Mimicking Word Embeddings using Subword RNNs}, | ||
author={Pinter, Yuval and Guthrie, Robert and Eisenstein, Jacob}, | ||
booktitle={Proceedings of the 2017 Conference on Empirical Methods in Natural Language Processing}, | ||
pages={102--112}, | ||
year={2017} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Mimick modeling | ||
|
||
This directory is dedicated to the Mimick algorithm itself. | ||
Starting with an embedding dictionary and (optionally) a target vocabulary, the tools here will provide you with: | ||
1. A model that can be loaded to perform inference on new words downstream; and | ||
1. (If needed) an embedding dictionary for the target vocabulary. | ||
|
||
For help with any specific script in this directory, run it with `--help`. This will also describe the parameters. | ||
|
||
## Pipeline | ||
|
||
1. `make_dataset.py` to create a training regimen for the model. Only needs to be called once per input embeddings table. | ||
1. `model.py` to train the model, save it, and output embeddings. Default is LSTM, CNN (1 layer) available via `--use-cnn` parameter. | ||
1. If needed, `nearest_vecs.py` and `inter_nearest_vecs.py` can be used for querying the model for nearest vectors in any embeddings dictionary. `inter_` is the interactive version. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# REPRESENTATION | ||
POLYGLOT_UNK = unicode("<UNK>") | ||
PADDING_CHAR = "<*>" | ||
|
||
# MODEL PARAMS | ||
DEFAULT_CHAR_DIM = 20 | ||
DEFAULT_HIDDEN_DIM = 50 | ||
DEFAULT_WORD_DIM = 64 | ||
|
||
# LSTM | ||
DEFAULT_LSTM_LAYERS = 1 | ||
|
||
# CNN | ||
DEFAULT_WINDOW_WIDTH = 3 | ||
DEFAULT_POOLING_MAXK = 1 | ||
DEFAULT_STRIDE = 1 | ||
DEFAULT_CNN_LAYERS = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.