Argilla¶
本节包含与 Argilla
集成的现有步骤,以便轻松将生成的数据集推送到 Argilla。
base
¶
ArgillaBase
¶
基类: Step
, ABC
抽象步骤,提供一个类以供子类化,其中包含与 Argilla 交互所需的样板代码,以及在其之上的一些额外验证。它还定义了需要实现的抽象方法,以便添加新的数据集类型作为步骤。
注意
此类不打算直接实例化,而是通过子类实例化。
属性
名称 | 类型 | 描述 |
---|---|---|
dataset_name |
RuntimeParameter[str]
|
Argilla 中数据集的名称,记录将添加到此数据集。 |
dataset_workspace |
Optional[RuntimeParameter[str]]
|
数据集将在 Argilla 中创建的工作区。默认为 |
api_url |
Optional[RuntimeParameter[str]]
|
Argilla API 的 URL。默认为 |
api_key |
Optional[RuntimeParameter[SecretStr]]
|
用于 Argilla 身份验证的 API 密钥。默认为 |
运行时参数
dataset_name
: Argilla 中数据集的名称,记录将添加到此数据集。dataset_workspace
: 数据集将在 Argilla 中创建的工作区。默认为None
,表示将在默认工作区中创建。api_url
: 用于 Argilla API 请求的基本 URL。api_key
: 用于验证对 Argilla API 请求的 API 密钥。
输入列
- 动态,基于提供的
inputs
值
源代码位于 src/distilabel/steps/argilla/base.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
outputs
property
¶
该步骤的输出是一个空列表,因为从此步骤子类化的步骤将始终是叶节点,既不会传播输入,也不会生成任何输出。
model_post_init(__context)
¶
检查是否安装了 Argilla Python SDK,然后过滤 Argilla 警告。
源代码位于 src/distilabel/steps/argilla/base.py
load()
¶
在调用 process
方法之前执行任何初始化逻辑的方法。例如,加载 LLM、建立与数据库的连接等。
源代码位于 src/distilabel/steps/argilla/base.py
preference
¶
PreferenceToArgilla
¶
基类: ArgillaBase
在 Argilla 中创建偏好数据集。
在加载阶段在 Argilla 中创建数据集的步骤,然后将输入批次作为记录推送到其中。此数据集是一个偏好数据集,其中指令有一个字段,每个生成结果在同一记录中有一个额外的字段,然后每个生成字段都有一个评分问题。评分问题要求注释者为每个提供的生成结果设置 1 到 5 的评分。
注意
此步骤旨在与 UltraFeedback
步骤结合使用,或与任何其他步骤结合使用,这些步骤为给定的指令和给定指令的生成结果生成评分和响应。但或者,它也可以与任何其他仅生成 instruction
和 generations
的任务或步骤一起使用,因为 ratings
和 rationales
是可选的。
属性
名称 | 类型 | 描述 |
---|---|---|
num_generations |
int
|
要包含在数据集中的生成结果的数量。 |
dataset_name |
RuntimeParameter[str]
|
Argilla 中数据集的名称。 |
dataset_workspace |
Optional[RuntimeParameter[str]]
|
数据集将在 Argilla 中创建的工作区。默认为 |
api_url |
Optional[RuntimeParameter[str]]
|
Argilla API 的 URL。默认为 |
api_key |
Optional[RuntimeParameter[SecretStr]]
|
用于 Argilla 身份验证的 API 密钥。默认为 |
运行时参数
api_url
: 用于 Argilla API 请求的基本 URL。api_key
: 用于验证对 Argilla API 请求的 API 密钥。
输入列
- instruction (
str
): 用于生成 completion 的指令。 - generations (
List[str]
): 基于输入指令生成的 completion。 - ratings (
List[str]
, 可选): 生成结果的评分。如果未提供,则生成的评分不会推送到 Argilla。 - rationales (
List[str]
, 可选): 评分的理由。如果未提供,则生成的理由不会推送到 Argilla。
示例
将偏好数据集推送到 Argilla 实例
from distilabel.steps import PreferenceToArgilla
to_argilla = PreferenceToArgilla(
num_generations=2,
api_url="https://dibt-demo-argilla-space.hf.space/",
api_key="api.key",
dataset_name="argilla_dataset",
dataset_workspace="my_workspace",
)
to_argilla.load()
result = next(
to_argilla.process(
[
{
"instruction": "instruction",
"generations": ["first_generation", "second_generation"],
}
],
)
)
# >>> result
# [{'instruction': 'instruction', 'generations': ['first_generation', 'second_generation']}]
它还可以包括评分和理由
result = next(
to_argilla.process(
[
{
"instruction": "instruction",
"generations": ["first_generation", "second_generation"],
"ratings": ["4", "5"],
"rationales": ["rationale for 4", "rationale for 5"],
}
],
)
)
# >>> result
# [
# {
# 'instruction': 'instruction',
# 'generations': ['first_generation', 'second_generation'],
# 'ratings': ['4', '5'],
# 'rationales': ['rationale for 4', 'rationale for 5']
# }
# ]
源代码位于 src/distilabel/steps/argilla/preference.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
|
inputs
property
¶
该步骤的输入是 instruction
和 generations
。可选地,也可以提供生成结果的 ratings
和 rationales
。
optional_inputs
property
¶
该步骤的可选输入是生成结果的 ratings
和 rationales
。
load()
¶
根据 inputs_mapping
设置 _instruction
和 _generations
属性,否则使用默认值;然后使用这些值创建一个适合文本生成场景的 FeedbackDataset
。然后将其推送到 Argilla。
源代码位于 src/distilabel/steps/argilla/preference.py
process(inputs)
¶
创建记录并将其作为 rg.Record
推送到 Argilla 数据集。
参数
名称 | 类型 | 描述 | 默认 |
---|---|---|---|
inputs
|
StepInput
|
包含任务输入的 Python 字典列表。 |
必需 |
返回值
类型 | 描述 |
---|---|
StepOutput
|
包含任务输出的 Python 字典列表。 |
源代码位于 src/distilabel/steps/argilla/preference.py
text_generation
¶
TextGenerationToArgilla
¶
基类: ArgillaBase
在 Argilla 中创建文本生成数据集。
Step
,在加载阶段在 Argilla 中创建数据集,然后将输入批次作为记录推送到其中。此数据集是一个文本生成数据集,其中每个输入有一个字段,然后是一个标签问题,用于将 completion 的质量评为差 (用 👎 表示) 或好 (用 👍 表示)。
注意
此步骤旨在与 TextGeneration
步骤结合使用,并且不需要列映射,因为它将使用 instruction
和 generation
列的默认值。
属性
名称 | 类型 | 描述 |
---|---|---|
dataset_name |
RuntimeParameter[str]
|
Argilla 中数据集的名称。 |
dataset_workspace |
Optional[RuntimeParameter[str]]
|
数据集将在 Argilla 中创建的工作区。默认为 |
api_url |
Optional[RuntimeParameter[str]]
|
Argilla API 的 URL。默认为 |
api_key |
Optional[RuntimeParameter[SecretStr]]
|
用于 Argilla 身份验证的 API 密钥。默认为 |
运行时参数
api_url
: 用于 Argilla API 请求的基本 URL。api_key
: 用于验证对 Argilla API 请求的 API 密钥。
输入列
- instruction (
str
): 用于生成 completion 的指令。 - generation (
str
或List[str]
): 基于输入指令生成的 completion。
示例
将文本生成数据集推送到 Argilla 实例
from distilabel.steps import PreferenceToArgilla
to_argilla = TextGenerationToArgilla(
num_generations=2,
api_url="https://dibt-demo-argilla-space.hf.space/",
api_key="api.key",
dataset_name="argilla_dataset",
dataset_workspace="my_workspace",
)
to_argilla.load()
result = next(
to_argilla.process(
[
{
"instruction": "instruction",
"generation": "generation",
}
],
)
)
# >>> result
# [{'instruction': 'instruction', 'generation': 'generation'}]
源代码位于 src/distilabel/steps/argilla/text_generation.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
inputs
property
¶
该步骤的输入是 instruction
和 generation
。
load()
¶
根据 inputs_mapping
设置 _instruction
和 _generation
属性,否则使用默认值;然后使用这些值创建一个适合文本生成场景的 FeedbackDataset
。然后将其推送到 Argilla。
源代码位于 src/distilabel/steps/argilla/text_generation.py
process(inputs)
¶
创建记录并将其作为 FeedbackRecords 推送到 Argilla 数据集。
参数
名称 | 类型 | 描述 | 默认 |
---|---|---|---|
inputs
|
StepInput
|
包含任务输入的 Python 字典列表。 |
必需 |
返回值
类型 | 描述 |
---|---|
StepOutput
|
包含任务输出的 Python 字典列表。 |