πŸ“„ Fin QaΒΆ

FINQA is an expert-annotated QA dataset that aims to tackle numerical reasoning over real-world financial data.

Tags: modality:table, urls:{'arxiv': 'https://www.semanticscholar.org/reader/99053e3a708fc27709c9dab33110dc98b187c158'}, languages:['english']

Note

ID: cards.fin_qa | Type: TaskCard

{
    "__description__": "FINQA is an expert-annotated QA dataset that aims to tackle numerical reasoning over real-world financial data.",
    "__tags__": {
        "languages": [
            "english"
        ],
        "modality": "table",
        "urls": {
            "arxiv": "https://www.semanticscholar.org/reader/99053e3a708fc27709c9dab33110dc98b187c158"
        }
    },
    "__type__": "task_card",
    "loader": {
        "__type__": "load_hf",
        "path": "ibm/finqa",
        "streaming": false
    },
    "preprocess_steps": [
        {
            "__type__": "filter_by_expression",
            "expression": "len(table) > 1"
        },
        {
            "__type__": "copy_fields",
            "field_to_field": [
                [
                    "pre_text/0",
                    "pre_text"
                ]
            ]
        },
        {
            "__type__": "copy_fields",
            "field_to_field": [
                [
                    "post_text/0",
                    "post_text"
                ]
            ]
        },
        {
            "__type__": "map_table_lists_to_std_table_json",
            "field_to_field": [
                [
                    "table",
                    "stdtable"
                ]
            ]
        },
        {
            "__type__": "serialize_table_as_indexed_row_major",
            "field_to_field": [
                [
                    "stdtable",
                    "serialized_table"
                ]
            ]
        }
    ],
    "task": {
        "__type__": "task",
        "augmentable_inputs": [
            "pre_text",
            "serialized_table",
            "post_text",
            "question"
        ],
        "inputs": {
            "post_text": "str",
            "pre_text": "str",
            "question": "str",
            "serialized_table": "str"
        },
        "metrics": [
            "metrics.fin_qa_metric"
        ],
        "outputs": {
            "answer": "str",
            "program_re": "str"
        },
        "prediction_type": "str"
    },
    "templates": {
        "__type__": "templates_list",
        "items": [
            {
                "__type__": "input_output_template",
                "input_format": "Presented with a financial report consisting of textual contents and a structured table, given a question, generate the reasoning program in the domain specific language (DSL) that will be executed to get the answer. \nThe DSL consists of mathematical operations and table operations as executable programs. The program consists of a sequence of operations. Each operation takes a list of arguments. \nThere are 6 mathematical operations: add, subtract, multiply, divide, greater, exp, and 4 table aggregation operations table-max, table-min, table-sum, table-average, that apply aggregation operations on table rows. The mathematical operations take arguments of either numbers from the given reports, or a numerical result from a previous step.\nThe table operations take arguments of table row names. We use the special token #n to denote the result from the nth step. \nFor example, in the example \"divide(9413, 20.01), divide(8249, 9.48), subtract(#0, #1)\", the program consists of 3 steps; The first and the second division steps take arguments from the table and the text, respectively, then the third step subtracts the results from the two previous steps.\n                Definitions of all operations:\n                [[\"Name\", \"Arguments\", \"Output\", \"Description\"],\n                [\"add\", \"number1, number2\", \"number\", \"add two numbers: number1 + number2\"],\n                [\"subtract\", \"number1, number2\", \"number\", \"subtract two numbers: number1 - number2\"],\n                [\"multiply\", \"number1, number2\", \"number\", \"multiply two numbers: number1 * number2\"],\n                [\"divide\", \"number1, number2\", \"number\", \"multiply two numbers: number1 / number2\"],\n                [\"exp\", \"number1, number2\", \"number\", \"exponential: number1 ^ number2\"],\n                [\"greater\", \"number1, number2\", \"bool\", \"comparison: number1 > number2\"],\n                [\"table-sum\", \"table header\", \"number\", \"the summation of one table row\"],\n                [\"table-average\", \"table header\", \"number\", \"the average of one table row\"],\n                [\"table-max\", \"table header\", \"number\", \"the maximum number of one table row\"],\n                [\"table-min\", \"table header\", \"number\", \"the minimum number of one table row\"]]\n                Answer with only the program, without any additional explanation.\n                Pre-table text: {pre_text}\n                Table: {serialized_table}\n                Post-table text: {post_text}\n                Question: {question}\n                Program:\n                    ",
                "output_format": "{program_re}",
                "postprocessors": []
            }
        ]
    }
}

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 FilterByExpressionΒΆ

Filters a stream, yielding only instances which fulfil a condition specified as a string to be python’s eval-uated.

Raises an error if a field participating in the specified condition is missing from the instance

Args:

expression (str): a condition over fields of the instance, to be processed by python’s eval() imports_list (List[str]): names of imports needed for the eval of the query (e.g. β€˜re’, β€˜json’) error_on_filtered_all (bool, optional): If True, raises an error if all instances are filtered out. Defaults to True.

Examples:

FilterByExpression(expression = β€œa > 4”) will yield only instances where β€œa”>4 FilterByExpression(expression = β€œa <= 4 and b > 5”) will yield only instances where the value of field β€œa” is not exceeding 4 and in field β€œb” – greater than 5 FilterByExpression(expression = β€œa in [4, 8]”) will yield only instances where β€œa” is 4 or 8 FilterByExpression(expression = β€œa not in [4, 8]”) will yield only instances where β€œa” is neither 4 nor 8 FilterByExpression(expression = β€œa[β€˜b’] not in [4, 8]”) will yield only instances where β€œa” is a dict in which key β€˜b’ is mapped to a value that is neither 4 nor 8

Explanation about LoadHFΒΆ

Loads datasets from the Huggingface Hub.

It supports loading with or without streaming, and 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. streaming: Bool indicating if streaming should be used. filtering_lambda: A lambda function for filtering the data after loading. num_proc: Optional integer to specify 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 MapTableListsToStdTableJSONΒΆ

Converts lists table format to the basic one (JSON).

JSON format {

β€œheader”: [β€œcol1”, β€œcol2”], β€œrows”: [[β€œrow11”, β€œrow12”], [β€œrow21”, β€œrow22”], [β€œrow31”, β€œrow32”]]

}

Explanation about TaskΒΆ

Task packs the different instance fields into dictionaries by their roles in the task.

Attributes:
input_fields (Union[Dict[str, str], List[str]]):

Dictionary with string names of instance input fields and types of respective values. In case a list is passed, each type will be assumed to be Any.

reference_fields (Union[Dict[str, str], List[str]]):

Dictionary with string names of instance output fields and types of respective values. In case a list is passed, each type will be assumed to be Any.

metrics (List[str]): List of names of metrics to be used in the task. prediction_type (Optional[str]):

Need to be consistent with all used metrics. Defaults to None, which means that it will be set to Any.

defaults (Optional[Dict[str, Any]]):

An optional dictionary with default values for chosen input/output keys. Needs to be consistent with names and types provided in β€˜input_fields’ and/or β€˜output_fields’ arguments. Will not overwrite values if already provided in a given instance.

The output instance contains three fields:

β€œinput_fields” whose value is a sub-dictionary of the input instance, consisting of all the fields listed in Arg β€˜input_fields’. β€œreference_fields” – for the fields listed in Arg β€œreference_fields”. β€œmetrics” – to contain the value of Arg β€˜metrics’

Explanation about SerializeTableAsIndexedRowMajorΒΆ

Indexed Row Major Table Serializer.

Commonly used row major serialization format. Format: col : col1 | col2 | col 3 row 1 : val1 | val2 | val3 | val4 row 2 : val1 | …

Explanation about InputOutputTemplateΒΆ

Generate field β€˜source’ from fields designated as input, and fields β€˜target’ and β€˜references’ from fields designated as output, of the processed instance.

Args specify the formatting strings with which to glue together the input and reference fields of the processed instance into one string (β€˜source’ and β€˜target’), and into a list of strings (β€˜references’).

References: metrics.fin_qa_metric

Read more about catalog usage here.