22 releases

0.11.2 Jul 22, 2023
0.11.1 Mar 19, 2023
0.10.0 Oct 11, 2022
0.8.2 Jul 30, 2022
0.1.3 Feb 7, 2020

#200 in Machine learning

Download history 55/week @ 2023-12-14 14/week @ 2023-12-21 2/week @ 2023-12-28 6/week @ 2024-01-04 10/week @ 2024-01-11 13/week @ 2024-01-18 17/week @ 2024-01-25 29/week @ 2024-02-01 56/week @ 2024-02-08 140/week @ 2024-02-15 155/week @ 2024-02-22 123/week @ 2024-02-29 129/week @ 2024-03-07 90/week @ 2024-03-14 62/week @ 2024-03-21 110/week @ 2024-03-28

408 downloads per month
Used in 5 crates (2 directly)

MIT/Apache

2MB
26K SLoC

C++ 24K SLoC // 0.1% comments Rust 1K SLoC // 0.0% comments Bitbake 370 SLoC // 0.5% comments Shell 4 SLoC

sentencepiece

This Rust crate is a binding for the sentencepiece unsupervised text tokenizer. The crate documentation is available online.

libsentencepiece dependency

This crate depends on the sentencepiece C++ library. By default, this dependency is treated as follows:

  • If sentencepiece could be found with pkg-config, the crate will link against the library found through pkg-config. Warning: dynamic linking only works correctly with sentencepiece 0.1.95 or later, due to a bug in earlier versions.
  • Otherwise, the crate's build script will do a static build of the sentencepiece library. This requires that cmake is available.

If you wish to override this behavior, the sentencepiece-sys crate offers two features:

  • system: always attempt to link to the sentencepiece library found with pkg-config.
  • static: always do a static build of the sentencepiece library and link against that.

lib.rs:

This crate binds the sentencepiece library. sentencepiece is an unsupervised text tokenizer.

The main data structure of this crate is SentencePieceProcessor, which is used to tokenize sentences:

use sentencepiece::SentencePieceProcessor;

let spp = SentencePieceProcessor::open("testdata/toy.model").unwrap();
let pieces = spp.encode("I saw a girl with a telescope.").unwrap()
  .into_iter().map(|p| p.piece).collect::<Vec<_>>();
assert_eq!(pieces, vec!["▁I", "▁saw", "▁a", "▁girl", "▁with",
  "▁a", "▁t", "el", "es", "c", "o", "pe", "."]);

Dependencies