Git Product home page Git Product logo

rosita's Introduction

A fork of the AllenNLP research library with extensions for training polyglot models.

Overview

  • bilm-tf: based on the bilm-tf library, for training multilingual LMs
  • allennlp: based on the allennlp library, for using contextual word embeddings from multilingual LMs.

Installation

bilm-tf and allennlp have different requirements. You will need a python 3.5 environment with tensorflow version 1.2 and h5py to use bilm-tf to train multilingual language models. You will need a python 3.6 environment with PyTorch version >=0.4.1 to use the multilingual language models for contextual embeddings in AllenNLP models. See the original bilm-tf README and the original allennlp README (install from source) for installation details.

Training language models with Rosita

You can train a polyglot language model with the following command (in the python 3.5 + tensorflow environment):

python bilm-tf/bin/train_elmo_poly.py --save_dir [path/to/model/dir] --vocab_file [path/to/vocab.txt] --train_paths [multiple/paths/to/files_*.txt]

You can either pass --n_train_tokens [X] or edit the default value for n_train_tokens in bilm-tf/bin/train_elmo_poly.py to reflect the number of tokens in your corpus.

Optionally, you can specify a gpu to train with using the flag --gpu k.

The vocabulary file should have one word per line, starting with the special tokens <S>, </S> and <UNK> and sorted by descending frequency. Non-special words should be prefixed with a language code, e.g. eng:example. You can produce a vocab file from your training data with the build_vocab.py script:

python bilm-tf/build_vocab.py [/path/to/corpus.txt] [paths/to/additional/textfiles]

Dumping weights

Once you have trained a LM, you can save its parameters as an HDF5 file to be read by AllenNLP.

python bilm-tf/bin/dump_weights.py --save_dir [path/to/training/output] --outfile [path to save weights, e.g. save_dir/weights.hdf5] --gpu [id]

Running with AllenNLP

Once you've installed our edited AllenNLP from source, you can run the command-line interface with bin/allennlp (in the python 3.6 + PyTorch environment).

An example training configuration is provided for a Universal Dependencies syntactic parser. Once you have an Arabic-English LM, the parser can be trained with the command:

allennlp train training_config/ud-ara-eng_elmo-ara-eng.json --serialization-dir models/rosita-test-ara-eng

Citing

If you use our method, please cite the paper Polyglot Contextual Representations Improve Crosslingual Transfer.

@inproceedings{Mulcaire2019Polyglot,
  title={Polyglot Contextual Representations Improve Crosslingual Transfer},
  author={Phoebe Mulcaire and Jungo Kasai and Noah A. Smith},
  booktitle={Proc.\ of NAACL-HLT},
  year={2019},
  Eprint = {arXiv:1902.09697},
}

You should also cite AllenNLP: A Deep Semantic Natural Language Processing Platform.

@inproceedings{Gardner2017AllenNLP,
  title={AllenNLP: A Deep Semantic Natural Language Processing Platform},
  author={Matt Gardner and Joel Grus and Mark Neumann and Oyvind Tafjord
    and Pradeep Dasigi and Nelson F. Liu and Matthew Peters and
    Michael Schmitz and Luke S. Zettlemoyer},
  year={2017},
  Eprint = {arXiv:1803.07640},
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.