πŸ“„ PudΒΆ

Universal Named Entity Recognition (UNER) aims to fill a gap in multilingual NLP: high quality NER datasets in many languages with a shared tagset. UNER is modeled after the Universal Dependencies project, in that it is intended to be a large community annotation effort with language-universal guidelines. Further, we use the same text corpora as Universal Dependencies… See the full description on the dataset page: https://huggingface.co/datasets/universalner/universal_ner

Tags: arxiv:2311.09122, language:['ceb', 'da', 'de', 'en', 'hr', 'pt', 'ru', 'sk', 'sr', 'sv', 'tl', 'zh'], license:cc-by-sa-4.0, region:us, task_categories:token-classification, category:dataset

cards.universal_ner.pt.pud

TaskCard(
    loader=LoadIOB(
        files={
            "test": "https://raw.githubusercontent.com/UniversalNER/UNER_Portuguese-PUD/master/pt_pud-ud-test.iob2",
        },
        data_classification_policy=[
            "public",
        ],
    ),
    preprocess_steps=[
        Shuffle(
            page_size=9223372036854775807,
        ),
        Rename(
            field_to_field={
                "ner_tags": "labels",
            },
        ),
        IobExtractor(
            labels=[
                "Person",
                "Organization",
                "Location",
            ],
            begin_labels=[
                "B-PER",
                "B-ORG",
                "B-LOC",
            ],
            inside_labels=[
                "I-PER",
                "I-ORG",
                "I-LOC",
            ],
            outside_label="O",
        ),
        Copy(
            field_to_field={
                "spans/*/start": "spans_starts",
                "spans/*/end": "spans_ends",
                "spans/*/label": "labels",
            },
            get_default=[],
            not_exist_ok=True,
        ),
        Set(
            fields={
                "entity_types": [
                    "Person",
                    "Organization",
                    "Location",
                ],
            },
        ),
    ],
    task="tasks.span_labeling.extraction",
    templates="templates.span_labeling.extraction.all",
)
[source]

from unitxt.loaders import LoadIOB
from unitxt.operators import Copy, Rename, Set, Shuffle
from unitxt.span_lableing_operators import IobExtractor

Explanation about TaskCardΒΆ

TaskCard delineates the phases in transforming the source dataset into model input, and specifies the metrics for evaluation of model output.

Args:
loader:

specifies the source address and the loading operator that can access that source and transform it into a unitxt multistream.

preprocess_steps:

list of unitxt operators to process the data source into model input.

task:

specifies the fields (of the already (pre)processed instance) making the inputs, the fields making the outputs, and the metrics to be used for evaluating the model output.

templates:

format strings to be applied on the input fields (specified by the task) and the output fields. The template also carries the instructions and the list of postprocessing steps, to be applied to the model output.

Explanation about SetΒΆ

Sets specified fields in each instance, in a given stream or all streams (default), with specified values. If fields exist, updates them, if do not exist – adds them.

Args:

fields (Dict[str, object]): The fields to add to each instance. Use β€˜/’ to access inner fields

use_deepcopy (bool) : Deep copy the input value to avoid later modifications

Examples:

# Set a value of a list consisting of β€œpositive” and β€œnegative” do field β€œclasses” to each and every instance of all streams Set(fields={"classes": ["positive","negatives"]})

# In each and every instance of all streams, field β€œspan” is to become a dictionary containing a field β€œstart”, in which the value 0 is to be set Set(fields={"span/start": 0}

# In all instances of stream β€œtrain” only, Set field β€œclasses” to have the value of a list consisting of β€œpositive” and β€œnegative” Set(fields={"classes": ["positive","negatives"], apply_to_stream=["train"]})

# Set field β€œclasses” to have the value of a given list, preventing modification of original list from changing the instance. Set(fields={"classes": alist}), use_deepcopy=True) if now alist is modified, still the instances remain intact.

Explanation about IobExtractorΒΆ

A class designed to extract entities from sequences of text using the Inside-Outside-Beginning (IOB) tagging convention. It identifies entities based on IOB tags and categorizes them into predefined labels such as Person, Organization, and Location.

Args:
labels (List[str]):

A list of entity type labels, e.g., [β€œPerson”, β€œOrganization”, β€œLocation”].

begin_labels (List[str]):

A list of labels indicating the beginning of an entity, e.g., [β€œB-PER”, β€œB-ORG”, β€œB-LOC”].

inside_labels (List[str]):

A list of labels indicating the continuation of an entity, e.g., [β€œI-PER”, β€œI-ORG”, β€œI-LOC”].

outside_label (str):

The label indicating tokens outside of any entity, typically β€œO”.

The extraction process identifies spans of text corresponding to entities and labels them according to their entity type. Each span is annotated with a start and end character offset, the entity text, and the corresponding label.

Example of instantiation and usage:

operator = IobExtractor(
    labels=["Person", "Organization", "Location"],
    begin_labels=["B-PER", "B-ORG", "B-LOC"],
    inside_labels=["I-PER", "I-ORG", "I-LOC"],
    outside_label="O",
)

instance = {
    "labels": ["B-PER", "I-PER", "O", "B-ORG", "I-ORG"],
    "tokens": ["John", "Doe", "works", "at", "OpenAI"]
}
processed_instance = operator.process(instance)
print(processed_instance["spans"])
# Output: [{'start': 0, 'end': 8, 'text': 'John Doe', 'label': 'Person'}, ...]

For more details on the IOB tagging convention, see: https://en.wikipedia.org/wiki/Inside-outside-beginning_(tagging)

Explanation about ShuffleΒΆ

Shuffles the order of instances in each page of a stream.

Args (of superclass):

page_size (int): The size of each page in the stream. Defaults to 1000.

Explanation about LoadIOBΒΆ

Loads data from IOB format files.

This loader can parse IOB (Inside-Outside-Begin) format files commonly used for named entity recognition tasks. It supports both local files and remote URLs, and can handle various IOB formats including CoNLL-U style files.

Args:
files (Dict[str, str]):

A dictionary mapping split names to file paths or URLs.

column_names (tuple, optional):

Column names for the IOB format. Defaults to (β€˜id’, β€˜token’, β€˜tag’, β€˜misc’, β€˜annotator’).

fix_tags (bool, optional):

Whether to apply tag fixing for OTH and B-O tags. Defaults to True.

encoding (str, optional):

File encoding. Defaults to β€˜utf-8’.

Example:

Loading IOB files

load_iob = LoadIOB(files={'train': 'path/to/train.iob2', 'test': 'path/to/test.iob2'})

Explanation about RenameΒΆ

Renames fields.

Move value from one field to another, potentially, if field name contains a /, from one branch into another. Remove the from field, potentially part of it in case of / in from_field.

Examples:

Rename(field_to_field={β€œb”: β€œc”}) will change inputs [{β€œa”: 1, β€œb”: 2}, {β€œa”: 2, β€œb”: 3}] to [{β€œa”: 1, β€œc”: 2}, {β€œa”: 2, β€œc”: 3}]

Rename(field_to_field={β€œb”: β€œc/d”}) will change inputs [{β€œa”: 1, β€œb”: 2}, {β€œa”: 2, β€œb”: 3}] to [{β€œa”: 1, β€œc”: {β€œd”: 2}}, {β€œa”: 2, β€œc”: {β€œd”: 3}}]

Rename(field_to_field={β€œb”: β€œb/d”}) will change inputs [{β€œa”: 1, β€œb”: 2}, {β€œa”: 2, β€œb”: 3}] to [{β€œa”: 1, β€œb”: {β€œd”: 2}}, {β€œa”: 2, β€œb”: {β€œd”: 3}}]

Rename(field_to_field={β€œb/c/e”: β€œb/d”}) will change inputs [{β€œa”: 1, β€œb”: {β€œc”: {β€œe”: 2, β€œf”: 20}}}] to [{β€œa”: 1, β€œb”: {β€œc”: {β€œf”: 20}, β€œd”: 2}}]

Explanation about CopyΒΆ

Copies values from specified fields to specified fields.

Args (of parent class):

field_to_field (Union[List[List], Dict[str, str]]): A list of lists, where each sublist contains the source field and the destination field, or a dictionary mapping source fields to destination fields.

Examples:

An input instance {β€œa”: 2, β€œb”: 3}, when processed by Copy(field_to_field={"a": "b"}) would yield {β€œa”: 2, β€œb”: 2}, and when processed by Copy(field_to_field={"a": "c"}) would yield {β€œa”: 2, β€œb”: 3, β€œc”: 2}

with field names containing / , we can also copy inside the field: Copy(field="a/0",to_field="a") would process instance {β€œa”: [1, 3]} into {β€œa”: 1}

References: templates.span_labeling.extraction.all, tasks.span_labeling.extraction

Read more about catalog usage here.