Skip to main content

OpenNMT tokenization library

Project description

Build Status PyPI version

Tokenizer

Tokenizer is a fast, generic, and customizable text tokenization library for C++ and Python with minimal dependencies.

Overview

By default, the Tokenizer applies a simple tokenization based on Unicode types. It can be customized in several ways:

  • Reversible tokenization
    Marking joints or spaces by annotating tokens or injecting modifier characters.
  • Subword tokenization
    Support for training and using BPE and SentencePiece models.
  • Advanced text segmentation
    Split digits, segment on case or alphabet change, segment each character of selected alphabets, etc.
  • Case management
    Lowercase text and return case information as a separate feature or inject case modifier tokens.
  • Protected sequences
    Sequences can be protected against tokenization with the special characters "⦅" and "⦆".

See the available options for an overview of supported features.

Using

The Tokenizer can be used in Python, C++, or command line. Each mode exposes the same set of options.

Python API

pip install pyonmttok
>>> import pyonmttok
>>> tokenizer = pyonmttok.Tokenizer("conservative", joiner_annotate=True)
>>> tokens, _ = tokenizer.tokenize("Hello World!")
>>> tokens
['Hello', 'World', '■!']
>>> tokenizer.detokenize(tokens)
'Hello World!'

See the Python API description for more details.

C++ API

#include <onmt/Tokenizer.h>

using namespace onmt;

int main() {
  Tokenizer tokenizer(Tokenizer::Mode::Conservative, Tokenizer::Flags::JoinerAnnotate);
  std::vector<std::string> tokens;
  tokenizer.tokenize("Hello World!", tokens);
}

See the Tokenizer class for more details.

Command line clients

$ echo "Hello World!" | cli/tokenize --mode conservative --joiner_annotate
Hello World ■!
$ echo "Hello World!" | cli/tokenize --mode conservative --joiner_annotate | cli/detokenize
Hello World!

See the -h flag to list the available options.

Development

Dependencies

Compiling

CMake and a compiler that supports the C++11 standard are required to compile the project.

git submodule update --init
mkdir build
cd build
cmake ..
make

It will produce the dynamic library libOpenNMTTokenizer and tokenization clients in cli/.

  • To compile only the library, use the -DLIB_ONLY=ON flag.

Testing

The tests are using Google Test which is included as a Git submodule. Run the tests with:

mkdir build
cd build
cmake -DBUILD_TESTS=ON ..
make
test/onmt_tokenizer_test ../test/data

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyonmttok-1.21.0-cp39-cp39-manylinux1_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.9

pyonmttok-1.21.0-cp38-cp38-manylinux1_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.8

pyonmttok-1.21.0-cp37-cp37m-manylinux1_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.7m

pyonmttok-1.21.0-cp36-cp36m-manylinux1_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.6m

pyonmttok-1.21.0-cp35-cp35m-manylinux1_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.5m

pyonmttok-1.21.0-cp27-cp27mu-manylinux1_x86_64.whl (2.6 MB view details)

Uploaded CPython 2.7mu

pyonmttok-1.21.0-cp27-cp27m-manylinux1_x86_64.whl (2.6 MB view details)

Uploaded CPython 2.7m

File details

Details for the file pyonmttok-1.21.0-cp39-cp39-manylinux1_x86_64.whl.

File metadata

  • Download URL: pyonmttok-1.21.0-cp39-cp39-manylinux1_x86_64.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: CPython 3.9
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.6.10

File hashes

Hashes for pyonmttok-1.21.0-cp39-cp39-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 0995c6ffe499886b4d0ac7c96ee1f44ee34603e0c63c523fcc79a1982d3aa38e
MD5 58452715212a6bb570fd7ccba9a9ad11
BLAKE2b-256 7aaf971bca978b74e55c16828c4f7f50a5db4cdb8e5caa61837e971dffae4217

See more details on using hashes here.

File details

Details for the file pyonmttok-1.21.0-cp38-cp38-manylinux1_x86_64.whl.

File metadata

  • Download URL: pyonmttok-1.21.0-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.6.10

File hashes

Hashes for pyonmttok-1.21.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 5d24dba4eb4f2e8c46964cad777ca1c44f012d761d48dd301feb61fae86cabb5
MD5 5663edcb096b03396d8fb0a631fe5b78
BLAKE2b-256 e374dd792d8623e9560e0d3f835d91b9b66db7780dfca5a5220ecb8817fe4f3c

See more details on using hashes here.

File details

Details for the file pyonmttok-1.21.0-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pyonmttok-1.21.0-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.6.10

File hashes

Hashes for pyonmttok-1.21.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 ee61dc03da2cfcda28463529e8a99a851c2dabf75e93598061c714bbafb57b8e
MD5 a770daa2f77eb024a37b1d19f82c20ec
BLAKE2b-256 533e51a6cdb26f977796ef8cdde62c7ab69169cfbc1a97c21cf4ca5f808c3e69

See more details on using hashes here.

File details

Details for the file pyonmttok-1.21.0-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pyonmttok-1.21.0-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.6.10

File hashes

Hashes for pyonmttok-1.21.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 e4399a50426b0c8a152b7d9e1d2ef6ff0731becc04786ea75b174098315317a9
MD5 11a4b3079498b5a5303c6383569bc63c
BLAKE2b-256 17e5d4544b969d863aed692f6d551010bd5988dfce4f53e1d7dd332702586c41

See more details on using hashes here.

File details

Details for the file pyonmttok-1.21.0-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pyonmttok-1.21.0-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.6.10

File hashes

Hashes for pyonmttok-1.21.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 14e0f3f1c43b34f715d1f659c68d94b69ac7f72b207962501b8e35fd6ab6fabf
MD5 f07a809647dde004a362b4c4b5b0558b
BLAKE2b-256 dbc2f855d73475df9aa7813e2202019ec9984b622fa4514f0e75fcc0a7b58e0e

See more details on using hashes here.

File details

Details for the file pyonmttok-1.21.0-cp27-cp27mu-manylinux1_x86_64.whl.

File metadata

  • Download URL: pyonmttok-1.21.0-cp27-cp27mu-manylinux1_x86_64.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: CPython 2.7mu
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.6.10

File hashes

Hashes for pyonmttok-1.21.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 ae3aabfcf2c6a0c69bd87b8348331815f21ad40288f710a0db6a12076cf01087
MD5 5695c1f8929bbfafa93c66392302fcca
BLAKE2b-256 d5475a5d4114a96a8534dc7c902a044235f241b82dd4c154f7bb1c79c71eabe7

See more details on using hashes here.

File details

Details for the file pyonmttok-1.21.0-cp27-cp27m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pyonmttok-1.21.0-cp27-cp27m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: CPython 2.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.6.10

File hashes

Hashes for pyonmttok-1.21.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 afeead41fabb730f6930949819593bfb49a9107931748ea0118d29baaa577b44
MD5 92f84ee8f870ab5f16c9fed8c5612624
BLAKE2b-256 db519783614e6e29ae53add9b2b6f92734e0748a6116837977c97ddfc64a0ae2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page