You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/sections/how_to_guides/basic/task/index.md
+69Lines changed: 69 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,6 +57,75 @@ As shown above, the [`TextGeneration`][distilabel.steps.tasks.TextGeneration] ta
57
57
)
58
58
```
59
59
60
+
### Task.print
61
+
62
+
!!! Info
63
+
New since version `1.4.0`, [`Task.print`][distilabel.steps.tasks.base._Task.print]`Task.print` method.
64
+
65
+
The `Tasks` include a handy method to show what the prompt formatted for an `LLM` would look like, let's see an example with [`UltraFeedback`][distilabel.steps.tasks.ultrafeedback.UltraFeedback], but it applies to any other `Task`.
66
+
67
+
```python
68
+
from distilabel.steps.tasks import UltraFeedback
69
+
from distilabel.llms.huggingface import InferenceEndpointsLLM
The result will be a rendered prompt, with the System prompt (if contained for the task) and the User prompt, rendered with rich (it will show exactly the same in a jupyter notebook).
In case you want to test with a custom input, you can pass an example to the tasks``format_input` method (or generate it on your own depending on the task), and pass it to the print method so that it shows your example:
In case you don't want to load an LLM to render the template, you can create a dummy one like the ones we could use for testing.
96
+
97
+
```python
98
+
from distilabel.llms.base import LLM
99
+
from distilabel.llms.mixins.magpie import MagpieChatTemplateMixin
100
+
101
+
class DummyLLM(AsyncLLM, MagpieChatTemplateMixin):
102
+
structured_output: Any = None
103
+
magpie_pre_query_template: str = "llama3"
104
+
105
+
def load(self) -> None:
106
+
pass
107
+
108
+
@property
109
+
def model_name(self) -> str:
110
+
return "test"
111
+
112
+
def generate(
113
+
self, input: "FormattedInput", num_generations: int = 1
114
+
) -> "GenerateOutput":
115
+
return ["output" for _ in range(num_generations)]
116
+
```
117
+
118
+
You can use this `LLM` just as any of the other ones to `load` your task and call `print`:
119
+
120
+
```python
121
+
uf = UltraFeedback(llm=DummyLLM())
122
+
uf.load()
123
+
uf.print()
124
+
```
125
+
126
+
!!! Note
127
+
When creating a custom task, the `print` method will be available by default, but it is limited to the most common scenarios for the inputs. If you test your new task and find it's not working as expected (for example, if your task contains one input consisting of a list of texts instead of a single one), you should override the `_sample_input` method. You can inspect the [`UltraFeedback`][distilabel.steps.tasks.ultrafeedback.UltraFeedback] source code for this.
128
+
60
129
## Specifying the number of generations and grouping generations
61
130
62
131
All the `Task`s have a `num_generations` attribute that allows defining the number of generations that we want to have per input. We can update the example above to generate 3 completions per input:
0 commit comments