Skip to content
koharu-rsPublic

About

pyvi's Vietnamese word segmenter for Koharu, with its model built in

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

pyvi

Vietnamese word segmentation for Koharu: a Rust port of pyvi's tokenizer, with its model built in. Vietnamese spaces every syllable, so a word of two or more has spaces inside it, and Koharu's line breaking asks this crate where they are.

let text = "Cảm ơn cậu nhiều lắm!";
let words: Vec<&str> = pyvi::tokenize(text).into_iter().map(|word| &text[word]).collect();
assert_eq!(words, ["Cảm ơn", "cậu", "nhiều", "lắm", "!"]);

It follows pyvi/ViTokenizer.py at e2ac2ec: sylabelize's syllables, word2features's features, the CRF's tags, and tokenize's joins. Words come back as byte ranges of the text it was given, composed or not.

Data

  • data/pyvi.crfsuite: the CRFsuite model inside pyvi's models/pyvi3.pkl, taken out byte for byte by scripts/extract_model.py, which walks the pickle's opcodes and runs none of them. crfs runs it.
  • data/words.txt: pyvi's models/words.txt, unchanged.

Checks

On 10,432 inputs, pyvi's treebank sample data/vtb.txt and manga dialogue with decomposed copies, the port's syllables, tags, and words match pyvi's exactly: 265,770 syllables in all. The tests check the dialogue in tests/inputs.txt against tests/reference.jsonl, which scripts/reference.py writes from a pyvi checkout.

To try a change in Koharu before it's merged, patch Koharu's dependency on this repository to a local checkout, and leave the patch out of Koharu's commits:

[patch."https://github.com/koharu-rs/pyvi"]
pyvi = { path = "../pyvi" }

License

MIT, as pyvi is; see LICENSE.

About

pyvi's Vietnamese word segmenter for Koharu, with its model built in

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages