#nlp #text #algorithm #token

tokenizations

Tokenizations alignments library

11 releases

0.4.2 Apr 1, 2021
0.4.1 Apr 1, 2021
0.4.0 Aug 4, 2020
0.3.0 May 28, 2020
0.1.4 Jan 8, 2020

#98 in #token

Download history 177/week @ 2024-07-31 200/week @ 2024-08-07 213/week @ 2024-08-14 259/week @ 2024-08-21 208/week @ 2024-08-28 141/week @ 2024-09-04 153/week @ 2024-09-11 228/week @ 2024-09-18 201/week @ 2024-09-25 399/week @ 2024-10-02 214/week @ 2024-10-09 180/week @ 2024-10-16 261/week @ 2024-10-23 212/week @ 2024-10-30 255/week @ 2024-11-06 303/week @ 2024-11-13

1,070 downloads per month
Used in textspan

MIT license

27KB
270 lines

Robust and Fast tokenizations alignment library for Rust and Python

creates.io pypi Actions Status

sample

Demo: demo
Rust document: docs.rs
Blog post: How to calculate the alignment between BERT and spaCy tokens effectively and robustly

Usage (Python)

  • Installation
$ pip install -U pip # update pip
$ pip install pytokenizations
  • Install from source

This library uses maturin to build the wheel.

$ git clone https://github.com/tamuhey/tokenizations
$ cd tokenizations/python
$ pip install maturin
$ maturin build

Now the wheel is created in python/target/wheels directory, and you can install it with pip install *whl.

get_alignments

def get_alignments(a: Sequence[str], b: Sequence[str]) -> Tuple[List[List[int]], List[List[int]]]: ...

Returns alignment mappings for two different tokenizations:

>>> tokens_a = ["å", "BC"]
>>> tokens_b = ["abc"] # the accent is dropped (å -> a) and the letters are lowercased(BC -> bc)
>>> a2b, b2a = tokenizations.get_alignments(tokens_a, tokens_b)
>>> print(a2b)
[[0], [0]]
>>> print(b2a)
[[0, 1]]

a2b[i] is a list representing the alignment from tokens_a to tokens_b.

Usage (Rust)

See here: docs.rs

Dependencies

~1MB
~35K SLoC