π 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.sv.pud
TaskCard(
loader=LoadIOB(
files={
"test": "https://raw.githubusercontent.com/UniversalNER/UNER_Swedish-PUD/master/sv_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 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 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 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 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 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 byCopy(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}
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)
References: templates.span_labeling.extraction.all, tasks.span_labeling.extraction
Read more about catalog usage here.