π WikitqΒΆ
This WikiTableQuestions dataset is a large-scale dataset for the task of question answering on semi-structured tables⦠See the full description on the dataset page: https://huggingface.co/datasets/wikitablequestions
Tags: annotations_creators:crowdsourced, arxiv:1508.00305, flags:['table-question-answering'], language:en, language_creators:found, license:cc-by-4.0, multilinguality:monolingual, region:us, size_categories:10K<n<100K, source_datasets:original, task_categories:question-answering, category:dataset
cards.wikitq
TaskCard(
loader=LoadCSV(
files={
"train": "https://raw.githubusercontent.com/ppasupat/WikiTableQuestions/master/data/random-split-1-train.tsv",
"validation": "https://raw.githubusercontent.com/ppasupat/WikiTableQuestions/master/data/random-split-1-dev.tsv",
"test": "https://raw.githubusercontent.com/ppasupat/WikiTableQuestions/master/data/pristine-unseen-tables.tsv",
},
sep=" ",
data_classification_policy=[
"public",
],
),
preprocess_steps=[
Rename(
field="utterance",
to_field="question",
),
Split(
field="targetValue",
to_field="answers",
by="|",
),
Set(
fields={
"context_type": "table",
},
),
Replace(
field="context",
old=".csv",
new=".tsv",
),
FormatText(
text="https://raw.githubusercontent.com/ppasupat/WikiTableQuestions/refs/heads/master/{context}",
to_field="table_url",
),
ReadFile(
field="table_url",
to_field="table_content",
),
ParseCSV(
field="table_content",
to_field="table",
separator=" ",
dtype="str",
strip_cells=True,
),
GetNumOfTableCells(
field="table",
to_field="table_cell_size",
),
FilterByCondition(
values={
"table_cell_size": 200,
},
condition="le",
),
Copy(
field="table",
to_field="context",
),
],
task="tasks.qa.extractive[metrics=[metrics.f1_strings, metrics.unsorted_list_exact_match]]",
templates=[
MultiReferenceTemplate(
instruction="Answer the question based on the provided table. Extract and output only the final answerβthe exact phrase or data from the table that directly answers the question. Do not include any alterations, explanations, 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="
Question: {question}
Table: {context}
Answer: ",
references_field="answers",
postprocessors=[
"processors.take_first_non_empty_line",
"processors.to_list_by_comma_space",
"processors.str_to_float_format",
],
),
],
)
[source]from unitxt.loaders import LoadCSV
from unitxt.operators import Copy, FilterByCondition, ReadFile, Rename, Set
from unitxt.string_operators import FormatText, Replace, Split
from unitxt.struct_data_operators import GetNumOfTableCells, ParseCSV
from unitxt.templates import MultiReferenceTemplate
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 ReadFileΒΆ
Reads file content from local path or URL.
This operator can read files from local filesystem paths or remote URLs. The content is returned as a string.
- Args:
encoding (str): Text encoding to use when reading the file. Defaults to βutf-8β.
- Example:
Reading a local file
ReadFile(field="file_path", to_field="content")Reading from URL
ReadFile(field="url", to_field="content")
Explanation about LoadCSVΒΆ
Loads data from CSV 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. sep: String specifying the separator used in the CSV files. indirect_read: Bool indicating if to open a remote file with urllib first column_names: Optional list of column names to use instead of header row.
- Example:
Loading csv
load_csv = LoadCSV(files={'train': 'path/to/train.csv'}, chunksize=100)Loading TSV with custom column names
load_csv = LoadCSV( files={'train': 'path/to/train.tsv'}, sep='\t', column_names=['id', 'question', 'table_name', 'answer'] )
Explanation about RenameΒΆ
Renames fields.
Move value from one field to another, potentially, if field name contains a /, from one branch into another. Remove the from field, potentially part of it in case of / in from_field.
- Examples:
Rename(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}]
Rename(field_to_field={βbβ: βc/dβ}) will change inputs [{βaβ: 1, βbβ: 2}, {βaβ: 2, βbβ: 3}] to [{βaβ: 1, βcβ: {βdβ: 2}}, {βaβ: 2, βcβ: {βdβ: 3}}]
Rename(field_to_field={βbβ: βb/dβ}) will change inputs [{βaβ: 1, βbβ: 2}, {βaβ: 2, βbβ: 3}] to [{βaβ: 1, βbβ: {βdβ: 2}}, {βaβ: 2, βbβ: {βdβ: 3}}]
Rename(field_to_field={βb/c/eβ: βb/dβ}) will change inputs [{βaβ: 1, βbβ: {βcβ: {βeβ: 2, βfβ: 20}}}] to [{βaβ: 1, βbβ: {βcβ: {βfβ: 20}, βdβ: 2}}]
Explanation about ParseCSVΒΆ
Parse CSV/TSV text content into table format.
This operator converts CSV or TSV text content into the standard table format used by Unitxt with header and rows fields.
- Args:
separator (str): Field separator character. Defaults to β,β. has_header (bool): Whether the first row contains column headers. Defaults to True. skip_header (bool): Whether to skip the first row entirely. Defaults to False.
- Example:
Parsing CSV content
ParseCSV(field="csv_content", to_field="table", separator=",")Parsing TSV content
ParseCSV(field="tsv_content", to_field="table", separator="\t")
Explanation about GetNumOfTableCellsΒΆ
Get the number of cells in the given table.
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 SetΒΆ
Sets specified fields in each instance, in a given stream or all streams (default), with specified values. If fields exist, updates them, if do not exist β adds them.
- Args:
fields (Dict[str, object]): The fields to add to each instance. Use β/β to access inner fields
use_deepcopy (bool) : Deep copy the input value to avoid later modifications
- Examples:
# Set a value of a list consisting of βpositiveβ and βnegativeβ do field βclassesβ to each and every instance of all streams
Set(fields={"classes": ["positive","negatives"]})# In each and every instance of all streams, field βspanβ is to become a dictionary containing a field βstartβ, in which the value 0 is to be set
Set(fields={"span/start": 0}# In all instances of stream βtrainβ only, Set field βclassesβ to have the value of a list consisting of βpositiveβ and βnegativeβ
Set(fields={"classes": ["positive","negatives"], apply_to_stream=["train"]})# Set field βclassesβ to have the value of a given list, preventing modification of original list from changing the instance.
Set(fields={"classes": alist}), use_deepcopy=True)if now alist is modified, still the instances remain intact.
References: processors.take_first_non_empty_line, metrics.unsorted_list_exact_match, processors.to_list_by_comma_space, processors.str_to_float_format, tasks.qa.extractive, metrics.f1_strings
Read more about catalog usage here.