Skip to content

Commit

Permalink
Add ability to run without template for simpler api
Browse files Browse the repository at this point in the history
Signed-off-by: elronbandel <elronbandel@gmail.com>
  • Loading branch information
elronbandel committed Nov 14, 2024
1 parent b93819e commit 5f2501c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/unitxt/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def verify(self):

if self.template is None:
raise ValueError(
"You must set in the recipe either `template`, `template_card_index` or `templates`."
"You must set in the recipe either `template`, `template_card_index`."
)

if isinstance(self.template, list):
Expand Down Expand Up @@ -411,9 +411,13 @@ def prepare(self):
assert (
self.template_card_index is None or self.template is None
), f"Specify either template ({self.template}) or template_card_index ({self.template_card_index}) but not both"
assert not (
self.template_card_index is None and self.template is None
), "Specify either template or template_card_index in card"

if self.template_card_index is None and self.template is None:
self.template_card_index = 0
logger.warning(
"Template was not specified in recipe, using template_card_index=0 by default."
)

if self.template_card_index is not None:
try:
self.template = self.card.templates[self.template_card_index]
Expand Down
6 changes: 6 additions & 0 deletions tests/library/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
class TestAPI(UnitxtTestCase):
maxDiff = None

def test_load_dataset_without_template(self):
dataset = load_dataset(
"card=cards.stsb",
)
self.assertEqual(len(dataset["train"]), 282)

def test_load_dataset(self):
dataset = load_dataset(
"card=cards.stsb,template=templates.regression.two_texts.simple,max_train_instances=5,max_validation_instances=5,max_test_instances=5",
Expand Down

0 comments on commit 5f2501c

Please sign in to comment.