跳到内容

PreferenceToArgilla

在 Argilla 中创建偏好数据集。

在加载阶段在 Argilla 中创建数据集的步骤,然后将输入批次作为记录推送到其中。此数据集是一个偏好数据集,其中一个字段用于指令,每个记录中每个生成内容都有一个额外的字段,然后每个生成字段都有一个评分问题。评分问题要求注释者为每个提供的生成内容设置 1 到 5 的评分。

注意

此步骤旨在与 UltraFeedback 步骤或任何其他为给定指令和给定指令的生成内容生成评分和响应的步骤结合使用。但或者,它也可以与任何其他仅生成 instructiongenerations 的任务或步骤一起使用,因为 ratingsrationales 是可选的。

属性

  • num_generations: 要包含在数据集中的生成数量。

  • dataset_name: Argilla 中数据集的名称。

  • dataset_workspace: 在 Argilla 中创建数据集的工作区。默认为 None,表示将在默认工作区中创建。

  • api_url: Argilla API 的 URL。默认为 None,表示将从 ARGILLA_API_URL 环境变量中读取。

  • api_key: 用于向 Argilla 验证身份的 API 密钥。默认为 None,表示将从 ARGILLA_API_KEY 环境变量中读取。

运行时参数

  • api_url: 用于 Argilla API 请求的基本 URL。

  • api_key: 用于验证对 Argilla API 的请求的 API 密钥。

输入 & 输出列

graph TD
    subgraph Dataset
        subgraph Columns
            ICOL0[instruction]
            ICOL1[generations]
            ICOL2[ratings]
            ICOL3[rationales]
        end
    end

    subgraph PreferenceToArgilla
        StepInput[Input Columns: instruction, generations, ratings, rationales]
    end

    ICOL0 --> StepInput
    ICOL1 --> StepInput
    ICOL2 --> StepInput
    ICOL3 --> StepInput

输入

  • instruction (str): 用于生成完成的指令。

  • generations (List[str]): 基于输入指令生成的完成。

  • 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']
#     }
# ]