Fast English word segmentation
Project description
Instant Segment: fast English word segmentation in Rust
Instant Segment is a fast Apache-2.0 library for English word segmentation. It is based on the Python wordsegment project written by Grant Jenks, which is in turn based on code from Peter Norvig's chapter Natural Language Corpus Data from the book Beautiful Data (Segaran and Hammerbacher, 2009).
For the microbenchmark included in this repository, Instant Segment is ~100x faster than the Python implementation. The API was carefully constructed so that multiple segmentations can share the underlying state to allow parallel usage.
How it works
Instant Segment works by segmenting a string into words by selecting the splits with the highest probability given a corpus of words and their occurrences.
For instance, provided that choose
and spain
occur more frequently than
chooses
and pain
, and that the pair choose spain
occurs more frequently
than chooses pain
, Instant Segment can help identify the domain
choosespain.com
as ChooseSpain.com
which more likely matches user intent.
Read about how we built and improved Instant Segment for use in production at Instant Domain Search to help our users find relevant domains they can register.
Using the library
Python (>= 3.9)
pip install instant-segment
Rust
[dependencies]
instant-segment = "0.8.1"
Examples
The following examples expect unigrams
and bigrams
to exist. See the
examples (Rust,
Python) to see how to construct
these objects.
import instant_segment
segmenter = instant_segment.Segmenter(unigrams, bigrams)
search = instant_segment.Search()
segmenter.segment("instantdomainsearch", search)
print([word for word in search])
--> ['instant', 'domain', 'search']
use instant_segment::{Search, Segmenter};
use std::collections::HashMap;
let segmenter = Segmenter::from_maps(unigrams, bigrams);
let mut search = Search::default();
let words = segmenter
.segment("instantdomainsearch", &mut search)
.unwrap();
println!("{:?}", words.collect::<Vec<&str>>())
--> ["instant", "domain", "search"]
Check out the tests for more thorough examples: Rust, Python
Testing
To run the tests run the following:
cargo t -p instant-segment --all-features
You can also test the Python bindings with:
make test-python
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for instant_segment-0.1.4-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92a31bd32111b2a417a2d56e5f958ca81eaa7b153aea7c485a748f40bb0c23b8 |
|
MD5 | 2fd7862087d1bb1e341a847d38401ab1 |
|
BLAKE2b-256 | 1082e79fd9d6e8222977b586fcec98b8b384d19c5812c56975d51264d0bd096f |
Hashes for instant_segment-0.1.4-cp39-cp39-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb2030bd95f9b9194927c2b84ea5bfa86727ba86c80a16445b93e70d2ace75cd |
|
MD5 | 16168e8308b0f315176ee1c4826f81be |
|
BLAKE2b-256 | 77b3fb3987dee855d741fd4a392abdec67ae5ad9c9b462ca42f6d683c79b0872 |
Hashes for instant_segment-0.1.4-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2388d539a0bee623036d0b0cc6add7d9be21eacc77bbd1902359ecd5ea4fae3 |
|
MD5 | b616fe17ed2faa65d818e78f4a35e62a |
|
BLAKE2b-256 | 49263c3dee3c851f79a420742fb318ade4f894fe32bcf7e38a87b84da9a5962e |
Hashes for instant_segment-0.1.4-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae7702f8b9254811ae5849c57e1651e68240348bae1ab8a36fa827ad9f173e90 |
|
MD5 | e587abf655178f9bf3df0d08f5f15741 |
|
BLAKE2b-256 | 0240f721e597adc8027de357e5dae44db3b3bc9ba225bde10569950125340fbf |
Hashes for instant_segment-0.1.4-cp38-cp38-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df8797281a488472d0f450e88637cf403f675dc8ab125c485c8b4907552c3e2d |
|
MD5 | 767a87369874998bed8066ee5a0e6a1b |
|
BLAKE2b-256 | 53825c029a4886d8749726cc038293b16013e1570857e8c6313fec0306695d27 |
Hashes for instant_segment-0.1.4-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3ff083cd40401ab270c6f2f2d2809488e334dd5d164980579ba5378c110debc |
|
MD5 | 04870ae71b53145ccc3c56196f15cb6d |
|
BLAKE2b-256 | 9750a85eba2c2247e9eb2c4181b1544c2f8ea7c3dec77ff835d84f9a4a078c52 |
Hashes for instant_segment-0.1.4-cp37-cp37m-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19af77a5ce54b3c87e2bf66b4af4b1cdadec26e98ad734a09b97d809138b3c0b |
|
MD5 | 4d1b894101ff1760e607dd5ed1b27a0e |
|
BLAKE2b-256 | 1402cf29dde9b15ea65619a7422e444dddadc7a251790d45486445f8a885ee8c |
Hashes for instant_segment-0.1.4-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 800f6c2cb18277ab6a30e8e0228f2e38fb1d73825fe3d7d688acbec8603cc299 |
|
MD5 | 9979035fd0a26ee8077fe7f866d76993 |
|
BLAKE2b-256 | 90c0e12e25c732c7d9d7a30c71482e71970caab2f0a1862cca431e33e94cab2e |
Hashes for instant_segment-0.1.4-cp36-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1dd7d9f327496b7b7c26b656936001f8560e43cadb15accd517ba168e65e227 |
|
MD5 | c78e9d17c9c50764fcd05caf1abfdc9d |
|
BLAKE2b-256 | 42acca78f6f5e776d6d64c3c42eca2a73b0deabffa9c831082eb563bc8a18ec6 |