Code Monkey home page Code Monkey logo

pytorch-truecaser's Introduction

Truecaser

Binder

This is a simple neural truecaser written with allennlp, and based loosely on (Susanto et al, 2016). They have an implementation here, but being written in Lua, it's a little hard to use.

We provide pre-trained models that can be used for truecasing English and German right out of the box. The English model is trained on the standard Wikipedia data split from (Coster and Kauchak, 2011), and achieves an F1 score of 93.01 on test. This is comparable to the best F1 of (Susanto et al 2016) of 93.19.

Requirements

Model

This model treats each sentence as a sequence of characters (spaces are included in the sequence). Each character takes a binary label of "U" if uppercase and "L" if lowercase. For example, the word tRuEcasIng would take the labels LULULLLULL

We encode the sequence using a bidirectional LSTM with 2 hidden layers, 50 dimensional character embeddings (input), 150 dimensional hidden size, and dropout of 0.25.

Scoring

A cautionary note is in order. The pytorch model optimizes for character level F1 score, but it is more common to measure on the word level. So, after training a model, get a comparable score using word_eval.py (which I copied from here)

For example, to score on the Wiki test data:

$ allennlp predict wiki-truecaser-model.tar.gz data/data.v1.split/normal.testing.txt --use-dataset-reader --output-file out_preds.txt --include-package mylib --predictor truecaser-predictor
$ python word_eval.py data/data.v1.split/normal.testing.txt out_preds.txt

Usage

If you just want to predict, you can run:

$ allennlp predict wiki-truecaser-model.tar.gz data/test.txt --output-file test-out.txt --include-package mylib --use-dataset-reader --predictor truecaser-predictor

Where data/test.txt is a file with one sentence per line.

See example.py for an example of how to use it programmatically.

Training

The dataset reader requires text that has one sentence per line. The model expects tokenized text. If your text is already tokenized (the Wiki data is), then you can use just_spaces as the word_splitter in the config. If you want to tokenize text first, you can use spacy.

You can get the Wikipedia data by running:

$ cd data
$ ./get_data.sh

Run:

$ allennlp train truecaser.json --include-package mylib -s /path/to/save/model/

If you have a GPU, set cuda_device to 0 in truecaser.json. This will make training much faster.

pytorch-truecaser's People

Contributors

mayhewsw avatar

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.