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 schema-linking #1533

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
20 changes: 20 additions & 0 deletions prepare/tasks/schema_linking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from typing import List

from unitxt.blocks import Task
from unitxt.catalog import add_to_catalog

add_to_catalog(
Task(
input_fields={
"id": str,
"utterance": str,
"hint": str,
"schema": List[str],
},
reference_fields={"linked_schema": List[str]},
prediction_type=List[str],
metrics=["metrics.f1_macro_multi_label"],
),
"tasks.schema_linking",
overwrite=True,
)
32 changes: 32 additions & 0 deletions prepare/templates/schema_linking/templates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from unitxt import add_to_catalog
from unitxt.templates import InputOutputTemplate, TemplatesList

add_to_catalog(
InputOutputTemplate(
instruction="Select the most relevant SQL columns to the given text.",
input_format="Text: {utterance}\n\nColumns:{schema}",
output_format="{linked_schema}",
postprocessors=["processors.to_list_by_comma_space"],
),
"templates.schema_linking.default",
overwrite=True,
)

add_to_catalog(
InputOutputTemplate(
instruction="Select the most relevant SQL columns to the given text. You are also given a hint.",
input_format="Text: {utterance}\n\nHint: {hint}\n\nColumns:{schema}",
output_format="{linked_schema}",
postprocessors=["processors.to_list_by_comma_space"],
),
"templates.schema_linking.with_hint",
overwrite=True,
)

add_to_catalog(
TemplatesList(
["templates.schema_linking.default", "templates.schema_linking.with_hint"]
),
"templates.schema_linking.all",
overwrite=True,
)
16 changes: 16 additions & 0 deletions src/unitxt/catalog/tasks/schema_linking.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"__type__": "task",
"input_fields": {
"id": "str",
"utterance": "str",
"hint": "str",
"schema": "List[str]"
},
"reference_fields": {
"linked_schema": "List[str]"
},
"prediction_type": "List[str]",
"metrics": [
"metrics.f1_macro_multi_label"
]
}
7 changes: 7 additions & 0 deletions src/unitxt/catalog/templates/schema_linking/all.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"__type__": "templates_list",
"items": [
"templates.schema_linking.default",
"templates.schema_linking.with_hint"
]
}
9 changes: 9 additions & 0 deletions src/unitxt/catalog/templates/schema_linking/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"__type__": "input_output_template",
"instruction": "Select the most relevant SQL columns to the given text.",
"input_format": "Text: {utterance}\n\nColumns:{schema}",
"output_format": "{linked_schema}",
"postprocessors": [
"processors.to_list_by_comma_space"
]
}
9 changes: 9 additions & 0 deletions src/unitxt/catalog/templates/schema_linking/with_hint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"__type__": "input_output_template",
"instruction": "Select the most relevant SQL columns to the given text. You are also given a hint.",
"input_format": "Text: {utterance}\n\nHint: {hint}\n\nColumns:{schema}",
"output_format": "{linked_schema}",
"postprocessors": [
"processors.to_list_by_comma_space"
]
}
Loading