Skip to main content

Word segmentation models

Project description

wordseg

DOI PyPI version Supported Python versions CircleCI

wordseg is a Python package of word segmentation models.

Table of contents:

Installation

wordseg is available through pip:

pip install wordseg

To install wordseg from the GitHub source:

git clone https://github.com/jacksonllee/wordseg.git
cd wordseg
pip install -r dev-requirements.txt  # For running the linter and tests
pip install -e .

Usage

wordseg implements a word segmentation model as a Python class. An instantiated model class object has the following methods (emulating the scikit-learn-styled API for machine learning):

  • fit: Train the model with segmented sentences.
  • predict: Predict the segmented sentences from unsegmented sentences.

The implemented model classes are as follows:

  • RandomSegmenter: Segmentation is predicted at random at each potential word boundary independently for some given probability. No training is required.
  • LongestStringMatching: This model constructs predicted words by moving from left to right along an unsegmented sentence and finding the longest matching words, constrained by a maximum word length parameter.

Sample code snippet:

from wordseg import LongestStringMatching

# Initialize a model.
model = LongestStringMatching(max_word_length=4)

# Train the model.
# `fit` takes an iterable of segmented sentences (a tuple or list of strings).
model.fit(
    [
        ("this", "is", "a", "sentence"),
        ("that", "is", "not", "a", "sentence"),
    ]
)

# Make some predictions; `predict` gives a generator, which is materialized by list() here.
list(model.predict(["thatisadog", "thisisnotacat"]))
# [['that', 'is', 'a', 'd', 'o', 'g'], ['this', 'is', 'not', 'a', 'c', 'a', 't']]
# We can't get 'dog' and 'cat' because they aren't in the training data.

Citation

Lee, Jackson L. 2020. wordseg: Word segmentation models in Python. https://doi.org/10.5281/zenodo.4077433

@software{leengrams,
  author       = {Jackson L. Lee},
  title        = {wordseg: Word segmentation models in Python},
  year         = 2020,
  doi          = {10.5281/zenodo.4077433},
  url          = {https://doi.org/10.5281/zenodo.4077433}
}

License

MIT License. Please see LICENSE.txt.

Changelog

Please see CHANGELOG.md.

Project details


Download files

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

Source Distribution

wordseg-0.0.2.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

wordseg-0.0.2-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file wordseg-0.0.2.tar.gz.

File metadata

  • Download URL: wordseg-0.0.2.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0.post20201006 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

File hashes

Hashes for wordseg-0.0.2.tar.gz
Algorithm Hash digest
SHA256 0e23afad01eaa36acb85524e1469a68f65d29bd41e1114cebfe39135e9e951d9
MD5 4740fdfccdefd8377e8fc9abf5205170
BLAKE2b-256 3ea5e5948fd098b5085b14830a9586d51b0f00c44a0717f06d7a9eb05511d847

See more details on using hashes here.

Provenance

File details

Details for the file wordseg-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: wordseg-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0.post20201006 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

File hashes

Hashes for wordseg-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 488e73c193ed9e36e844fef41658217f7c10e36a1d0123304e85ff1232477235
MD5 a963814d19b7a0ba6113459d29b74e64
BLAKE2b-256 dd23ceeb960b12098d8ca9d9a246f5ac2081b135574f406bf433593b5972f0ec

See more details on using hashes here.

Provenance

Supported by

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