Skip to main content

extr-ds

Library to programmatically build labeled datasets for Named-Entity Recognition (NER) and Relation Extraction (RE) Machine Learning tasks.


Install

pip install extr-ds

Command Line

see Instructions on how to use the command line utility to manage your project.

1. Init Project

extr-ds --init

2. Split and Annotate

extr-ds --split

3.a Annotate Entities or Relations Again?

extr-ds --annotate -ents
extr-ds --annotate -rels

3.b Change Relation Extraction Label

extr-ds --relate -label NO_RELATION=5,7,9

3.b Remove Relation Extraction Instance

extr-ds --relate -delete 5,6,7

3.c Recover removed Relation Extraction Instances

extr-ds --relate -recover 5,6,7

4. Save

extr-ds --save -ents
extr-ds --save -rels

5. Reset "Gold Standard" datasets

extr-ds --reset

6. Help!?

extr-ds --help

API

Example

text = 'Ted Johnson is a pitcher.'

1. Label Entities for Named-Entity Recognition Task (NER)

from extr import RegEx, RegExLabel
from extr.entities import EntityExtactor
from extr_ds.labelers import IOB

entity_extractor = EntityExtactor([
    RegExLabel('PERSON', [
        RegEx([r'(ted\s+johnson|ted)'], re.IGNORECASE)
    ]),
    RegExLabel('POSITION', [
        RegEx([r'pitcher'], re.IGNORECASE)
    ]),
])

sentence_tokenizer = ## 3rd party tokenizer ##
label = IOB(sentence_tokenizer, entity_extractor).label(text)

## label == <Label tokens=..., labels=['B-PERSON', 'I-PERSON', 'O', 'O', 'B-POSITION', 'O']>

2. Annotate for Relation Extraction Task (RE)

from extr.entities import EntityExtractor
from extr.relations import RegExRelationLabelBuilder, \
                           RelationExtractor
from extr_ds.labelers import RelationClassification
from extr_ds.labelers.relation import RelationBuilder, BaseRelationLabeler, RuleBasedRelationLabeler


person_to_position_relationship = RegExRelationLabelBuilder('is_a') \
    .add_e1_to_e2(
        'PERSON',
        [
            r'\s+is\s+a\s+',
        ],
        'POSITION'
    ) \
    .build()

base_relation_labeler = BaseRelationLabeler(
    RelationBuilder(relation_formats=[
        ('PERSON', 'POSITION', 'NO_RELATION')
    ])
)

rule_based_relation_labeler = RuleBasedRelationLabeler(
    RelationExtractor([person_to_position_relationship])
)

labeler = RelationClassification(
    EntityExtractor([
        RegExLabel('PERSON', [
            RegEx([r'(ted johnson|bob)'], re.IGNORECASE)
        ]),
        RegExLabel('POSITION', [
            RegEx([r'pitcher'], re.IGNORECASE)
        ]),
    ]),
    base_relation_labeler,
    relation_labelers=[
        rule_based_relation_labeler
    ]
)

results = labeler.label(text)

## results.relation_labels == [
##    <RelationLabel sentence="<e1>Ted Johnson</e1> is a <e2>pitcher</e2>." label="is_a">
## ]

3. Find and define the type of difference between labels

from extr_ds.validators import check_for_differences

differences_in_labels = check_for_differences(
    ['B-PERSON', 'I-PERSON', 'O', 'O', 'B-POSITION', 'O'],
    ['B-PERSON', 'O', 'O', 'O', 'B-POSITION', 'O']
)

## differences_in_labels.has_diffs == True
## differences_in_labels.diffs_between_labels == [
##      <Difference index=1, diff_type=DifferenceTypes.S2_MISSING>
## ]

differences_in_labels = check_for_differences(
    ['B-PERSON', 'I-PERSON', 'O', 'O', 'B-POSITION', 'O'],
    ['B-PERSON', 'B-PERSON', 'O', 'O', 'B-POSITION', 'O']
)

## differences_in_labels.has_diffs == True
## differences_in_labels.diffs_between_labels == [
##      <Difference index=1, diff_type=DifferenceTypes.MISMATCH>
## ]

Metadata

Release files for extr-ds 0.0.86

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

Source distribution (sdist)

Source distribution for extr-ds 0.0.86
File Size Uploaded Provenance Actions
extr-ds-0.0.86.tar.gz 15.5 kB Without provenance Details for extr-ds-0.0.86.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for extr-ds 0.0.86
File Interpreter ABI Platform Actions
extr_ds-0.0.86-py3-none-any.whl Python 3 none any Details for extr_ds-0.0.86-py3-none-any.whl

Total release size: 37.5 kB

Release files / extr-ds-0.0.86.tar.gz

Download URL extr-ds-0.0.86.tar.gz
Size 15.5 kB
Tags Source
SHA-256 checksum
How to use checksums
4fc0b0dafccc1d34792f53ff0fdd651285e3d3817979217b0247722e9313bf37
BLAKE2b-256 checksum
How to use checksums
3667c2b7862b04645cd562b5e36cc1c659742e32f68ca48d6f08ac22dd1e6961
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.1

Release files / extr_ds-0.0.86-py3-none-any.whl

Download URL extr_ds-0.0.86-py3-none-any.whl
Size 22.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7d6ffdb11bc8e019a382ecb5bbf18e7b557e186ca443c313ca59c5befb214221
BLAKE2b-256 checksum
How to use checksums
6687cc19d9abfffc3f85da513a68ddcf875dbd3250dcc23278e8f6a57a43b7c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.1

Security for extr-ds 0.0.86

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.

Release history Release notifications | RSS feed

This release

0.0.86 This release

2 release files No provenance

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