π 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=LoadJsonFile(
files={
"train": "https://raw.githubusercontent.com/czyssrs/FinQA/0f16e2867befa6840783e58be38c9efb9229d742/dataset/train.json",
"validation": "https://raw.githubusercontent.com/czyssrs/FinQA/0f16e2867befa6840783e58be38c9efb9229d742/dataset/dev.json",
"test": "https://raw.githubusercontent.com/czyssrs/FinQA/0f16e2867befa6840783e58be38c9efb9229d742/dataset/test.json",
},
data_classification_policy=[
"public",
],
),
preprocess_steps=[
Copy(
field="qa/question",
to_field="question",
),
Copy(
field="qa/answer",
to_field="answer",
),
Cast(
field="qa/program",
to="str",
to_field="program_re",
),
Copy(
field="pre_text/0",
to_field="pre_text",
),
GetLength(
field="table",
to_field="table_length",
),
FilterByCondition(
values={
"table_length": 1,
},
condition="gt",
),
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 LoadJsonFile
from unitxt.operators import Cast, 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 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β
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 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> 4FilterByCondition(values = {"a":4}, condition = "le")will yield only instances where"a"<=4FilterByCondition(values = {"a":[4,8]}, condition = "in")will yield only instances where"a"is4or8FilterByCondition(values = {"a":[4,8]}, condition = "not in")will yield only instances where"a"is different from4or8FilterByCondition(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 neither4nor8FilterByCondition(values = {"a[2]":4}, condition = "le")will yield only instances where βaβ is a list whose 3-rd element is<= 4FilterByCondition(values = {"a":False}, condition = "exists")will yield only instances which do not contain a field named"a"FilterByCondition(values = {"a/b":True}, condition = "exists")will yield only instances which contain a field named"a"whose value is a dict containing, in turn, a field named"b"
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 CastΒΆ
Casts specified fields to specified types.
- Args:
default (object): A dictionary mapping field names to default values for cases of casting failure. process_every_value (bool): If true, all fields involved must contain lists, and each value in the list is then casted. Defaults to False.
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 LoadJsonFileΒΆ
Loads data from JSON files.
Supports streaming and can handle large files by loading them in chunks.
- Args:
files (Dict[str, str]): A dictionary mapping names to file paths. chunksize : Size of the chunks to load at a time. loader_limit: Optional integer to specify a limit on the number of records to load. streaming: Bool indicating if streaming should be used. lines: Bool indicate if it is json lines file structure. Otherwise, assumes a single json object in the file. data_field: optional field within the json object, that contains the list of instances.
- Example:
Loading json lines
load_csv = LoadJsonFile(files={'train': 'path/to/train.jsonl'}, line=True, chunksize=100)
References: processors.take_first_non_empty_line, metrics.fin_qa_metric
Read more about catalog usage here.