Upload common.py with huggingface_hub
Browse files
common.py
CHANGED
@@ -5,7 +5,7 @@ from .collections import ItemPicker, RandomPicker
|
|
5 |
from .operator import SourceOperator
|
6 |
from .recipe import Recipe, SequentialRecipe
|
7 |
from .schema import ToUnitxtGroup
|
8 |
-
from .splitters import RandomSampler, SliceSplit, SpreadSplit
|
9 |
from .stream import MultiStream
|
10 |
from .templates import RenderTemplatedICL
|
11 |
|
@@ -13,6 +13,7 @@ from .templates import RenderTemplatedICL
|
|
13 |
class CommonRecipe(Recipe, SourceOperator):
|
14 |
card: TaskCard
|
15 |
demos_pool_name: str = "demos_pool"
|
|
|
16 |
demos_pool_size: int = None
|
17 |
demos_field: str = "demos"
|
18 |
num_demos: int = None
|
@@ -21,7 +22,7 @@ class CommonRecipe(Recipe, SourceOperator):
|
|
21 |
template_item: Union[str, int] = None
|
22 |
|
23 |
def verify(self):
|
24 |
-
self.sampler_type in ["random"]
|
25 |
|
26 |
def prepare(self):
|
27 |
steps = [
|
@@ -35,13 +36,10 @@ class CommonRecipe(Recipe, SourceOperator):
|
|
35 |
|
36 |
if self.demos_pool_size is not None:
|
37 |
steps.append(
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
"validation": "validation",
|
43 |
-
"test": "test",
|
44 |
-
}
|
45 |
)
|
46 |
)
|
47 |
|
@@ -58,8 +56,8 @@ class CommonRecipe(Recipe, SourceOperator):
|
|
58 |
)
|
59 |
|
60 |
if self.card.instructions is not None:
|
61 |
-
if self.instruction_item is None:
|
62 |
-
picker = ItemPicker(self.instruction_item)
|
63 |
else:
|
64 |
picker = RandomPicker()
|
65 |
instruction = picker(self.card.instructions)
|
@@ -68,9 +66,9 @@ class CommonRecipe(Recipe, SourceOperator):
|
|
68 |
|
69 |
if self.card.templates is not None:
|
70 |
if self.template_item is None:
|
71 |
-
picker = ItemPicker(self.template_item)
|
72 |
-
else:
|
73 |
picker = RandomPicker()
|
|
|
|
|
74 |
template = picker(self.card.templates)
|
75 |
else:
|
76 |
template = None
|
|
|
5 |
from .operator import SourceOperator
|
6 |
from .recipe import Recipe, SequentialRecipe
|
7 |
from .schema import ToUnitxtGroup
|
8 |
+
from .splitters import RandomSampler, SeparateSplit, SliceSplit, SpreadSplit
|
9 |
from .stream import MultiStream
|
10 |
from .templates import RenderTemplatedICL
|
11 |
|
|
|
13 |
class CommonRecipe(Recipe, SourceOperator):
|
14 |
card: TaskCard
|
15 |
demos_pool_name: str = "demos_pool"
|
16 |
+
demos_taken_from: str = "train"
|
17 |
demos_pool_size: int = None
|
18 |
demos_field: str = "demos"
|
19 |
num_demos: int = None
|
|
|
22 |
template_item: Union[str, int] = None
|
23 |
|
24 |
def verify(self):
|
25 |
+
assert self.sampler_type in ["random"], f"Uknown sampler type {self.sampler_type}"
|
26 |
|
27 |
def prepare(self):
|
28 |
steps = [
|
|
|
36 |
|
37 |
if self.demos_pool_size is not None:
|
38 |
steps.append(
|
39 |
+
SeparateSplit(
|
40 |
+
from_split=self.demos_taken_from,
|
41 |
+
to_split_names=[self.demos_pool_name, self.demos_taken_from],
|
42 |
+
to_split_sizes=[int(self.demos_pool_size)],
|
|
|
|
|
|
|
43 |
)
|
44 |
)
|
45 |
|
|
|
56 |
)
|
57 |
|
58 |
if self.card.instructions is not None:
|
59 |
+
if not self.instruction_item is None:
|
60 |
+
picker = ItemPicker(int(self.instruction_item))
|
61 |
else:
|
62 |
picker = RandomPicker()
|
63 |
instruction = picker(self.card.instructions)
|
|
|
66 |
|
67 |
if self.card.templates is not None:
|
68 |
if self.template_item is None:
|
|
|
|
|
69 |
picker = RandomPicker()
|
70 |
+
else:
|
71 |
+
picker = ItemPicker(self.template_item)
|
72 |
template = picker(self.card.templates)
|
73 |
else:
|
74 |
template = None
|