πŸ“„ 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']

cards.fin_qa

type: TaskCard
loader: 
  type: LoadHF
  path: ibm/finqa
  streaming: False
preprocess_steps: 
  - type: FilterByExpression
    expression: len(table) > 1
  - type: Copy
    field: pre_text/0
    to_field: pre_text
  - type: Copy
    field: post_text/0
    to_field: post_text
  - type: MapTableListsToStdTableJSON
    field: table
task: 
  type: Task
  inputs: 
    pre_text: str
    table: Table
    post_text: str
    question: str
  outputs: 
    program_re: str
    answer: str
  prediction_type: str
  metrics: 
    - metrics.fin_qa_metric
  augmentable_inputs: 
    - pre_text
    - table
    - post_text
    - question
templates: 
  - type: InputOutputTemplate
    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: {table}\n                    Post-table text: {post_text}\n                    Question: {question}\n                    Program:\n                        "
    output_format: {program_re}
    postprocessors: []
[source]

Explanation about TaskCardΒΆ

TaskCard delineates the phases in transforming the source dataset into 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 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 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. 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: 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 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’).

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 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: metrics.fin_qa_metric

Read more about catalog usage here.