πŸ“„ coedit_gecΒΆ

Note

ID: cards.coedit_gec | Type: TaskCard

{
    "loader": {
        "path": "grammarly/coedit",
        "streaming": true,
        "type": "load_hf"
    },
    "preprocess_steps": [
        {
            "condition": "eq",
            "type": "filter_by_condition",
            "values": {
                "task": "gec"
            }
        },
        "splitters.small_no_test",
        {
            "expression": "': '.join(src.split(': ')[1:])",
            "to_field": "src",
            "type": "execute_expression"
        },
        {
            "field_to_field": {
                "src": "original_text"
            },
            "type": "rename_fields"
        },
        {
            "fields": [
                "tgt"
            ],
            "to_field": "corrected_texts",
            "type": "list_field_values"
        }
    ],
    "task": "tasks.grammatical_error_correction",
    "templates": [
        "templates.grammatical_error_correction.simple"
    ],
    "type": "task_card"
}

Explanation about TaskCardΒΆ

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

Attributes:

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 a 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 RenameFieldsΒΆ

Renames fields.

Move value from one field to another, potentially, if β€˜use_query’=True, from one branch into another. Remove the from field, potentially part of it in case of use_query.

Examples:

RenameFields(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}]

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

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

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

Explanation about ExecuteExpressionΒΆ

Compute an expression, specified as a string to be eval-uated, over the instance’s fields, and store the result in field to_field.

Raises an error if a field mentioned in the query is missing from the instance.

Args:

expression (str): an expression to be evaluated over the fields of the instance to_field (str): the field where the result is to be stored into imports_list (List[str]): names of imports needed for the eval of the query (e.g. β€˜re’, β€˜json’)

Examples:

When instance {β€œa”: 2, β€œb”: 3} is process-ed by operator ExecuteExpression(expression=”a+b”, to_field = β€œc”) the result is {β€œa”: 2, β€œb”: 3, β€œc”: 5}

When instance {β€œa”: β€œhello”, β€œb”: β€œworld”} is process-ed by operator ExecuteExpression(expression = β€œa+’ β€˜+b”, to_field = β€œc”) the result is {β€œa”: β€œhello”, β€œb”: β€œworld”, β€œc”: β€œhello world”}

Explanation about ListFieldValuesΒΆ

Concatenates values of multiple fields into a list, and assigns it to a new field.

Explanation about FilterByConditionΒΆ

Filters a stream, yielding only instances for which the required values follows the required condition operator.

Raises an error if a required key is missing.

Args:

values (Dict[str, Any]): Values that instances must match using the condition to be included in the output. condition: the name of the desired condition operator between the key and the value in values (β€œgt”, β€œge”, β€œlt”, β€œle”, β€œne”, β€œeq”) error_on_filtered_all (bool, optional): If True, raises an error if all instances are filtered out. Defaults to True.

Examples:

FilterByCondition(values = {β€œa”:4}, condition = β€œgt”) will yield only instances where β€œa”>4 FilterByCondition(values = {β€œa”:4}, condition = β€œle”) will yield only instances where β€œa”<=4 FilterByCondition(values = {β€œa”:[4,8]}, condition = β€œin”) will yield only instances where β€œa” is 4 or 8 FilterByCondition(values = {β€œa”:[4,8]}, condition = β€œnot in”) will yield only instances where β€œa” different from 4 or 8

References: tasks.grammatical_error_correction, templates.grammatical_error_correction.simple, splitters.small_no_test

Read more about catalog usage here.