Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a filter to wikitq #1547

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion prepare/cards/wikitq.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
TaskCard,
)
from unitxt.catalog import add_to_catalog
from unitxt.operators import Copy, Set
from unitxt.operators import Copy, FilterByCondition, Set
from unitxt.struct_data_operators import GetNumOfTableCells
from unitxt.templates import MultiReferenceTemplate
from unitxt.test_utils.card import test_card

Expand All @@ -14,6 +15,10 @@
),
preprocess_steps=[
Set({"context_type": "table"}),
GetNumOfTableCells(field="table", to_field="table_cell_size"),
FilterByCondition(
values={"table_cell_size": 200}, condition="le"
), # filter out tables with more than 200 cells
Copy(field="table", to_field="context"),
# TruncateTableRows(field="table", to_field="context"),
],
Expand Down
12 changes: 12 additions & 0 deletions src/unitxt/catalog/cards/wikitq.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@
"context_type": "table"
}
},
{
"__type__": "get_num_of_table_cells",
"field": "table",
"to_field": "table_cell_size"
},
{
"__type__": "filter_by_condition",
"values": {
"table_cell_size": 200
},
"condition": "le"
},
{
"__type__": "copy",
"field": "table",
Expand Down
9 changes: 9 additions & 0 deletions src/unitxt/struct_data_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,15 @@ def truncate_table_rows(self, table_content: Dict):
return table_content


class GetNumOfTableCells(FieldOperator):
"""Get the number of cells in the given table."""

def process_value(self, table: Any) -> Any:
num_of_rows = len(table.get("rows"))
num_of_cols = len(table.get("header"))
return num_of_rows * num_of_cols


class SerializeTableRowAsText(InstanceOperator):
"""Serializes a table row as text.

Expand Down
Loading