Skip to content

Commit

Permalink
add schema linking
Browse files Browse the repository at this point in the history
Signed-off-by: KyleErwin <[email protected]>
  • Loading branch information
KyleErwin committed Jan 28, 2025
1 parent fddf5e3 commit 0c4cfda
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 0 deletions.
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"
]
}

0 comments on commit 0c4cfda

Please sign in to comment.