πŸ“„ AtisΒΆ

Tags: region:us, category:dataset

cards.atis

TaskCard(
    loader=LoadHF(
        path="tuetschek/atis",
    ),
    preprocess_steps=[
        SplitStrip(
            delimiter=" ",
            field_to_field={
                "slots": "labels",
                "text": "tokens",
            },
        ),
        IobExtractor(
            labels=[
                "aircraft_code",
                "airline_code",
                "airline_name",
                "airport_code",
                "airport_name",
                "arrive_date.date_relative",
                "arrive_date.day_name",
                "arrive_date.day_number",
                "arrive_date.month_name",
                "arrive_date.today_relative",
                "arrive_time.end_time",
                "arrive_time.period_mod",
                "arrive_time.period_of_day",
                "arrive_time.start_time",
                "arrive_time.time",
                "arrive_time.time_relative",
                "city_name",
                "class_type",
                "connect",
                "cost_relative",
                "day_name",
                "day_number",
                "days_code",
                "depart_date.date_relative",
                "depart_date.day_name",
                "depart_date.day_number",
                "depart_date.month_name",
                "depart_date.today_relative",
                "depart_date.year",
                "depart_time.end_time",
                "depart_time.period_mod",
                "depart_time.period_of_day",
                "depart_time.start_time",
                "depart_time.time",
                "depart_time.time_relative",
                "economy",
                "fare_amount",
                "fare_basis_code",
                "flight_days",
                "flight_mod",
                "flight_number",
                "flight_stop",
                "flight_time",
                "fromloc.airport_code",
                "fromloc.airport_name",
                "fromloc.city_name",
                "fromloc.state_code",
                "fromloc.state_name",
                "meal",
                "meal_code",
                "meal_description",
                "mod",
                "month_name",
                "or",
                "period_of_day",
                "restriction_code",
                "return_date.date_relative",
                "return_date.day_name",
                "return_date.day_number",
                "return_date.month_name",
                "return_date.today_relative",
                "return_time.period_mod",
                "return_time.period_of_day",
                "round_trip",
                "state_code",
                "state_name",
                "stoploc.airport_name",
                "stoploc.city_name",
                "stoploc.state_code",
                "time",
                "time_relative",
                "today_relative",
                "toloc.airport_code",
                "toloc.airport_name",
                "toloc.city_name",
                "toloc.country_name",
                "toloc.state_code",
                "toloc.state_name",
                "transport_type",
            ],
            begin_labels=[
                "B-aircraft_code",
                "B-airline_code",
                "B-airline_name",
                "B-airport_code",
                "B-airport_name",
                "B-arrive_date.date_relative",
                "B-arrive_date.day_name",
                "B-arrive_date.day_number",
                "B-arrive_date.month_name",
                "B-arrive_date.today_relative",
                "B-arrive_time.end_time",
                "B-arrive_time.period_mod",
                "B-arrive_time.period_of_day",
                "B-arrive_time.start_time",
                "B-arrive_time.time",
                "B-arrive_time.time_relative",
                "B-city_name",
                "B-class_type",
                "B-connect",
                "B-cost_relative",
                "B-day_name",
                "B-day_number",
                "B-days_code",
                "B-depart_date.date_relative",
                "B-depart_date.day_name",
                "B-depart_date.day_number",
                "B-depart_date.month_name",
                "B-depart_date.today_relative",
                "B-depart_date.year",
                "B-depart_time.end_time",
                "B-depart_time.period_mod",
                "B-depart_time.period_of_day",
                "B-depart_time.start_time",
                "B-depart_time.time",
                "B-depart_time.time_relative",
                "B-economy",
                "B-fare_amount",
                "B-fare_basis_code",
                "B-flight_days",
                "B-flight_mod",
                "B-flight_number",
                "B-flight_stop",
                "B-flight_time",
                "B-fromloc.airport_code",
                "B-fromloc.airport_name",
                "B-fromloc.city_name",
                "B-fromloc.state_code",
                "B-fromloc.state_name",
                "B-meal",
                "B-meal_code",
                "B-meal_description",
                "B-mod",
                "B-month_name",
                "B-or",
                "B-period_of_day",
                "B-restriction_code",
                "B-return_date.date_relative",
                "B-return_date.day_name",
                "B-return_date.day_number",
                "B-return_date.month_name",
                "B-return_date.today_relative",
                "B-return_time.period_mod",
                "B-return_time.period_of_day",
                "B-round_trip",
                "B-state_code",
                "B-state_name",
                "B-stoploc.airport_name",
                "B-stoploc.city_name",
                "B-stoploc.state_code",
                "B-time",
                "B-time_relative",
                "B-today_relative",
                "B-toloc.airport_code",
                "B-toloc.airport_name",
                "B-toloc.city_name",
                "B-toloc.country_name",
                "B-toloc.state_code",
                "B-toloc.state_name",
                "B-transport_type",
            ],
            inside_labels=[
                "I-aircraft_code",
                "I-airline_code",
                "I-airline_name",
                "I-airport_code",
                "I-airport_name",
                "I-arrive_date.date_relative",
                "I-arrive_date.day_name",
                "I-arrive_date.day_number",
                "I-arrive_date.month_name",
                "I-arrive_date.today_relative",
                "I-arrive_time.end_time",
                "I-arrive_time.period_mod",
                "I-arrive_time.period_of_day",
                "I-arrive_time.start_time",
                "I-arrive_time.time",
                "I-arrive_time.time_relative",
                "I-city_name",
                "I-class_type",
                "I-connect",
                "I-cost_relative",
                "I-day_name",
                "I-day_number",
                "I-days_code",
                "I-depart_date.date_relative",
                "I-depart_date.day_name",
                "I-depart_date.day_number",
                "I-depart_date.month_name",
                "I-depart_date.today_relative",
                "I-depart_date.year",
                "I-depart_time.end_time",
                "I-depart_time.period_mod",
                "I-depart_time.period_of_day",
                "I-depart_time.start_time",
                "I-depart_time.time",
                "I-depart_time.time_relative",
                "I-economy",
                "I-fare_amount",
                "I-fare_basis_code",
                "I-flight_days",
                "I-flight_mod",
                "I-flight_number",
                "I-flight_stop",
                "I-flight_time",
                "I-fromloc.airport_code",
                "I-fromloc.airport_name",
                "I-fromloc.city_name",
                "I-fromloc.state_code",
                "I-fromloc.state_name",
                "I-meal",
                "I-meal_code",
                "I-meal_description",
                "I-mod",
                "I-month_name",
                "I-or",
                "I-period_of_day",
                "I-restriction_code",
                "I-return_date.date_relative",
                "I-return_date.day_name",
                "I-return_date.day_number",
                "I-return_date.month_name",
                "I-return_date.today_relative",
                "I-return_time.period_mod",
                "I-return_time.period_of_day",
                "I-round_trip",
                "I-state_code",
                "I-state_name",
                "I-stoploc.airport_name",
                "I-stoploc.city_name",
                "I-stoploc.state_code",
                "I-time",
                "I-time_relative",
                "I-today_relative",
                "I-toloc.airport_code",
                "I-toloc.airport_name",
                "I-toloc.city_name",
                "I-toloc.country_name",
                "I-toloc.state_code",
                "I-toloc.state_name",
                "I-transport_type",
            ],
            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": [
                    "aircraft_code",
                    "airline_code",
                    "airline_name",
                    "airport_code",
                    "airport_name",
                    "arrive_date.date_relative",
                    "arrive_date.day_name",
                    "arrive_date.day_number",
                    "arrive_date.month_name",
                    "arrive_date.today_relative",
                    "arrive_time.end_time",
                    "arrive_time.period_mod",
                    "arrive_time.period_of_day",
                    "arrive_time.start_time",
                    "arrive_time.time",
                    "arrive_time.time_relative",
                    "city_name",
                    "class_type",
                    "connect",
                    "cost_relative",
                    "day_name",
                    "day_number",
                    "days_code",
                    "depart_date.date_relative",
                    "depart_date.day_name",
                    "depart_date.day_number",
                    "depart_date.month_name",
                    "depart_date.today_relative",
                    "depart_date.year",
                    "depart_time.end_time",
                    "depart_time.period_mod",
                    "depart_time.period_of_day",
                    "depart_time.start_time",
                    "depart_time.time",
                    "depart_time.time_relative",
                    "economy",
                    "fare_amount",
                    "fare_basis_code",
                    "flight_days",
                    "flight_mod",
                    "flight_number",
                    "flight_stop",
                    "flight_time",
                    "fromloc.airport_code",
                    "fromloc.airport_name",
                    "fromloc.city_name",
                    "fromloc.state_code",
                    "fromloc.state_name",
                    "meal",
                    "meal_code",
                    "meal_description",
                    "mod",
                    "month_name",
                    "or",
                    "period_of_day",
                    "restriction_code",
                    "return_date.date_relative",
                    "return_date.day_name",
                    "return_date.day_number",
                    "return_date.month_name",
                    "return_date.today_relative",
                    "return_time.period_mod",
                    "return_time.period_of_day",
                    "round_trip",
                    "state_code",
                    "state_name",
                    "stoploc.airport_name",
                    "stoploc.city_name",
                    "stoploc.state_code",
                    "time",
                    "time_relative",
                    "today_relative",
                    "toloc.airport_code",
                    "toloc.airport_name",
                    "toloc.city_name",
                    "toloc.country_name",
                    "toloc.state_code",
                    "toloc.state_name",
                    "transport_type",
                ],
            },
        ),
    ],
    task="tasks.span_labeling.extraction",
    templates="templates.span_labeling.extraction.all",
)
[source]

from unitxt.loaders import LoadHF
from unitxt.operators import Copy, Set
from unitxt.processors import SplitStrip
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 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}

Explanation about LoadHFΒΆ

Loads datasets from the HuggingFace Hub.

It supports loading with or without streaming, and it can filter datasets upon loading.

Args:
path:

The path or identifier of the dataset on the HuggingFace Hub.

name:

An optional dataset name.

data_dir:

Optional directory to store downloaded data.

split:

Optional specification of which split to load.

data_files:

Optional specification of particular data files to load. When you provide a list of data_files to Hugging Face’s load_dataset function without explicitly specifying the split argument, these files are automatically placed into the train split.

revision:

Optional. The revision of the dataset. Often the commit id. Use in case you want to set the dataset version.

streaming (bool):

indicating if streaming should be used.

filtering_lambda (str, optional):

A lambda function for filtering the data after loading.

num_proc (int, optional):

Specifies the number of processes to use for parallel dataset loading.

Example:

Loading glue’s mrpc dataset

load_hf = LoadHF(path='glue', name='mrpc')

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)

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

Read more about catalog usage here.