π 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']
, category:dataset
cards.fin_qa
TaskCard
(
loader=LoadHF
(
path="ibm/finqa",
streaming=False,
),
preprocess_steps=[
GetLength
(
field="table",
to_field="table_length",
),
FilterByCondition
(
values={
"table_length": 1,
},
condition="gt",
),
Copy
(
field="pre_text/0",
to_field="pre_text",
),
Copy
(
field="post_text/0",
to_field="post_text",
),
MapTableListsToStdTableJSON
(
field="table",
),
],
task=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=[
InputOutputTemplate
(
instruction="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.
The 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.
There 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.
The table operations take arguments of table row names. We use the special token #n to denote the result from the nth step.
For 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.
Definitions of all operations:
[["Name", "Arguments", "Output", "Description"],
["add", "number1, number2", "number", "add two numbers: number1 + number2"],
["subtract", "number1, number2", "number", "subtract two numbers: number1 - number2"],
["multiply", "number1, number2", "number", "multiply two numbers: number1 * number2"],
["divide", "number1, number2", "number", "multiply two numbers: number1 / number2"],
["exp", "number1, number2", "number", "exponential: number1 ^ number2"],
["greater", "number1, number2", "bool", "comparison: number1 > number2"],
["table-sum", "table header", "number", "the summation of one table row"],
["table-average", "table header", "number", "the average of one table row"],
["table-max", "table header", "number", "the maximum number of one table row"],
["table-min", "table header", "number", "the minimum number of one table row"]]
Answer with only the program, without any additional explanation or introductory text.
Here are some input-output examples. Read the examples carefully to figure out the mapping. The output of the last example is not given, and your job is to figure out what it is.
",
input_format="Pre-table text: {pre_text}
Table: {table}
Post-table text: {post_text}
Question: {question}
Program:
",
output_format="{program_re}",
postprocessors=[
"processors.take_first_non_empty_line",
],
),
],
)
[source]from unitxt.collections_operators import GetLength
from unitxt.loaders import LoadHF
from unitxt.operators import Copy, FilterByCondition
from unitxt.struct_data_operators import MapTableListsToStdTableJSON
from unitxt.task import Task
from unitxt.templates import InputOutputTemplate
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 FilterByConditionΒΆ
Filters a stream, yielding only instances in which the values in required fields follow the required condition operator.
Raises an error if a required field name is missing from the input instance.
- Args:
values (Dict[str, Any]): Field names and respective Values that instances must match according the condition, to be included in the output.
condition: the name of the desired condition operator between the specified (sub) fieldβs value and the provided constant value. Supported conditions are (βgtβ, βgeβ, βltβ, βleβ, βneβ, βeqβ, βinβ,βnot inβ)
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 field"a"
contains a value> 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"
is4
or8
FilterByCondition(values = {"a":[4,8]}, condition = "not in")
will yield only instances where"a"
is different from4
or8
FilterByCondition(values = {"a/b":[4,8]}, condition = "not in")
will yield only instances where"a"
is a dict in which key"b"
is mapped to a value that is neither4
nor8
FilterByCondition(values = {"a[2]":4}, condition = "le")
will yield only instances where βaβ is a list whose 3-rd element is<= 4
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 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 MapTableListsToStdTableJSONΒΆ
Converts lists table format to the basic one (JSON).
JSON format:
{ "header": ["col1", "col2"], "rows": [["row11", "row12"], ["row21", "row22"], ["row31", "row32"]] }
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 TaskΒΆ
Task packs the different instance fields into dictionaries by their roles in the task.
- Args:
- 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β
References: processors.take_first_non_empty_line, metrics.fin_qa_metric
Read more about catalog usage here.