Skip to main content

seqlabel: Flexible Rule-based Text Labeling

CI badge Open In Colab

seqlabel is a rule-based text labeling framework aiming at flexibility.

Installation

To install seqlabel:

pip install seqlabel

Requirements

  • Python 3.8+

Usage

For a normal text

First, import some classes.

from seqlabel import Text
from seqlabel.matchers import DictionaryMatcher
from seqlabel.entity_filters import LongestMatchFilter, MaximizedMatchFilter
from seqlabel.serializers import IOB2Serializer

Initialize Text by giving it a text you want to label over.

text = Text("Tokyo is the capital of Japan.")

Prepare matcher matching supplied patterns. You can supply patterns via Hash Map mapping string sequences to the corresponding labels. You can define your own matcher by inheriting seqlabel.matchers.Matcher.

Then, apply matcher.match to text.

# Preparing Matcher
matcher = DictionaryMatcher()
# Adding patterns
matcher.add({"Tokyo": "LOC", "Japan": "LOC"})
# Matching
entities = matcher.match(text)

Filter unwanted entities. LongestMatchFilter removes overlapping entities and leaves longer entity. MaximizedMatchFilter removes overlapping entities and leaves as many entities as possible. You can define your own filter by inheriting seqlabel.entity_filters.EntityFilter.

filter_a = LongestMatchFilter()
filtered_entities_a = filter_a(entities)

filter_b = MaximizedMatchFilter()
filtered_entities_b = filter_b(entities)

Convert entities to IOB2 format after matching and filtering. Check seqlabel.serializers out if you want to use other formats.

serializer = IOB2Serializer()
serializer.save(text, filtered_entities_a)

For a tokenized text

If you want to process a tokenized text, you need to use TokenizedText instead of Text. You could import it as follows:

from seqlabel import TokenizedText

Initialize TokenizedText by giving it tokens and space_after you want to label over. tokens is a list of strings and space_after is a list of boolean indicating whether each token has a subsequent space.

tokenized_text = TokenizedText(
  ["Tokyo", "is", "the", "captial", "of", "Japan", "."],
  [True, True, True, True, True, False, False]
)

You can use matcher, filter, and serializer just like a normal text, as shown above.

# Mathcing
entities = matcher.match(tokenized_text)
# Filtering
filtered_entities = filter_a(entities)
# Serializing
serializer.save(tokenized_text, filtered_entities)

Metadata

Release files for seqlabel 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for seqlabel 0.2.4
File Size Uploaded Provenance Actions
seqlabel-0.2.4.tar.gz 6.1 kB Without provenance Details for seqlabel-0.2.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for seqlabel 0.2.4
File Interpreter ABI Platform Actions
seqlabel-0.2.4-py3-none-any.whl Python 3 none any Details for seqlabel-0.2.4-py3-none-any.whl

Total release size: 12.9 kB

Release files / seqlabel-0.2.4.tar.gz

Download URL seqlabel-0.2.4.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
33fd50599a55c4fa3b369f9e6866192f880ee61d14e48bb0a5274911ea8f74d0
BLAKE2b-256 checksum
How to use checksums
36272eba515cebd939849f2c93b75433925c7abb074abe4da0769d80da1bfbbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.10 CPython/3.9.7 Linux/5.8.0-1042-azure

Release files / seqlabel-0.2.4-py3-none-any.whl

Download URL seqlabel-0.2.4-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f247c54343a22f550e463c176a6861aada737f58f4bc2c7205b0b3a878084c31
BLAKE2b-256 checksum
How to use checksums
6038af516f7eae5e6d39df6078f35f01ccbf61c65654f236480982b66e5f26ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.10 CPython/3.9.7 Linux/5.8.0-1042-azure

Security for seqlabel 0.2.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page