Skip to content

Commit

Permalink
add deprecation for old recipes, and update docs
Browse files Browse the repository at this point in the history
Signed-off-by: dafnapension <[email protected]>
  • Loading branch information
dafnapension committed Dec 24, 2024
1 parent d071d86 commit 8d5c8d4
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/blog/vision_robustness_blog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Here’s the code used to set up our tests. This example uses Unitxt to create s
for card in ["cards.seed_bench", "cards.ai2d"]:
for enumerator in ["capitals", "lowercase"]:
for augmentor in [None, "augmentors.image.white_noise"]:
subsets[f"{card} {enumerator} {augmentor}"] = StandardRecipe(
subsets[f"{card} {enumerator} {augmentor}"] = DatasetRecipe(
card=card,
template=f"templates.qa.multiple_choice.with_context.lmms_eval[enumerator={enumerator}]",
loader_limit=100,
Expand Down
20 changes: 10 additions & 10 deletions docs/docs/benchmark.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,21 @@ We can compile them together using Unitxt Benchmark:
.. code-block:: python
from unitxt.benchmark import Benchmark
from unitxt.standard import StandardRecipe
from unitxt.standard import DatasetRecipe
benchmark = Benchmark(
format="formats.user_agent",
max_samples_per_subset=5,
loader_limit=300,
subsets={
"cola": StandardRecipe(card="cards.cola", template="templates.classification.multi_class.instruction"),
"mnli": StandardRecipe(card="cards.mnli", template="templates.classification.multi_class.relation.default"),
"mrpc": StandardRecipe(card="cards.mrpc", template="templates.classification.multi_class.relation.default"),
"qnli": StandardRecipe(card="cards.qnli", template="templates.classification.multi_class.relation.default"),
"rte": StandardRecipe(card="cards.rte", template="templates.classification.multi_class.relation.default"),
"sst2": StandardRecipe(card="cards.sst2", template="templates.classification.multi_class.title"),
"stsb": StandardRecipe(card="cards.stsb", template="templates.regression.two_texts.title"),
"wnli": StandardRecipe(card="cards.wnli", template="templates.classification.multi_class.relation.default"),
"cola": DatasetRecipe(card="cards.cola", template="templates.classification.multi_class.instruction"),
"mnli": DatasetRecipe(card="cards.mnli", template="templates.classification.multi_class.relation.default"),
"mrpc": DatasetRecipe(card="cards.mrpc", template="templates.classification.multi_class.relation.default"),
"qnli": DatasetRecipe(card="cards.qnli", template="templates.classification.multi_class.relation.default"),
"rte": DatasetRecipe(card="cards.rte", template="templates.classification.multi_class.relation.default"),
"sst2": DatasetRecipe(card="cards.sst2", template="templates.classification.multi_class.title"),
"stsb": DatasetRecipe(card="cards.stsb", template="templates.regression.two_texts.title"),
"wnli": DatasetRecipe(card="cards.wnli", template="templates.classification.multi_class.relation.default"),
},
)
Expand Down Expand Up @@ -128,7 +128,7 @@ If you want to explore different templates, you can do so by defining a list of

.. code-block:: python
StandardRecipe(
DatasetRecipe(
card="cards.cola",
template=[
"templates.classification.multi_class.instruction",
Expand Down
1 change: 0 additions & 1 deletion examples/evaluate_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
CrossProviderInferenceEngine,
)
from unitxt.standard import DatasetRecipe
from unitxt.text_utils import print_dict

benchmark = Benchmark(
format="formats.user_agent",
Expand Down
3 changes: 2 additions & 1 deletion src/unitxt/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from .schema import UNITXT_DATASET_SCHEMA, loads_instance
from .settings_utils import get_constants, get_settings
from .standard import DatasetRecipe
from .task import Task

logger = get_logger()
constants = get_constants()
Expand Down Expand Up @@ -47,7 +48,7 @@ def _get_recipe_from_dict(dataset_params: Dict[str, Any]) -> DatasetRecipe:
recipe_attributes = list(DatasetRecipe.__dict__["__fields__"].keys())
for param in dataset_params.keys():
assert param in recipe_attributes, (
f"The parameter '{param}' is not an attribute of the 'StandardRecipe' class. "
f"The parameter '{param}' is not an attribute of the 'DatasetRecipe' class. "
f"Please check if the name is correct. The available attributes are: '{recipe_attributes}'."
)
return DatasetRecipe(**dataset_params)
Expand Down
16 changes: 16 additions & 0 deletions src/unitxt/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .card import TaskCard
from .collections_operators import GetLength
from .dataclass import Field, InternalField, NonPositionalField, OptionalField
from .deprecation_utils import deprecation
from .error_utils import UnitxtError
from .formats import Format, SystemFormat
from .generator_utils import ReusableGenerator
Expand Down Expand Up @@ -680,3 +681,18 @@ def prepare(self):
if isinstance(self.template, TemplatesList):
self.template = self.template.items
self.reset_pipeline()


@deprecation(version="2.0.0", alternative=DatasetRecipe)
class BaseRecipe(DatasetRecipe):
pass


@deprecation(version="2.0.0", alternative=DatasetRecipe)
class StandardRecipeWithIndexes(BaseRecipe):
pass


@deprecation(version="2.0.0", alternative=DatasetRecipe)
class StandardRecipe(StandardRecipeWithIndexes):
pass
2 changes: 1 addition & 1 deletion src/unitxt/test_utils/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ..metric import _compute
from ..settings_utils import get_settings
from ..standard import DatasetRecipe
from ..text_utils import construct_dict_str
from ..text_utils import to_pretty_string
from ..utils import deep_copy

logger = get_logger()
Expand Down

0 comments on commit 8d5c8d4

Please sign in to comment.