跳到内容

问题

Argilla 使用问题来收集反馈。问题将由用户或模型回答。

使用示例

要定义一个标签问题,例如,实例化 LabelQuestion 类并将其传递给 Settings 类。

label_question = rg.LabelQuestion(name="label", labels=["positive", "negative"])

settings = rg.Settings(
    fields=[
        rg.TextField(name="text"),
    ],
    questions=[
        label_question,
    ],
)

问题可以基于您想要收集的反馈类型以可扩展的方式组合。例如,您可以将标签问题与文本问题结合使用,以同时收集标签和文本响应。

label_question = rg.LabelQuestion(name="label", labels=["positive", "negative"])
text_question = rg.TextQuestion(name="response")

settings = rg.Settings(
    fields=[
        rg.TextField(name="text"),
    ],
    questions=[
        label_question,
        text_question,
    ],
)

dataset = rg.Dataset(
    name="my_dataset",
    settings=settings,
)

要添加包含问题响应的记录,请参阅 rg.Response 类文档。


LabelQuestion

基类: QuestionBase

源代码位于 src/argilla/settings/_question.py
class LabelQuestion(QuestionBase):
    def __init__(
        self,
        name: str,
        labels: Union[List[str], Dict[str, str]],
        title: Optional[str] = None,
        description: Optional[str] = None,
        required: bool = True,
        visible_labels: Optional[int] = None,
        client: Optional[Argilla] = None,
    ) -> None:
        """ Define a new label question for `Settings` of a `Dataset`. A label \
            question is a question where the user can select one label from \
            a list of available labels.

        Parameters:
            name (str): The name of the question to be used as a reference.
            labels (Union[List[str], Dict[str, str]]): The list of available labels for the question, or a
                dictionary of key-value pairs where the key is the label and the value is the label name displayed in the UI.
            title (Optional[str]): The title of the question to be shown in the UI.
            description (Optional[str]): The description of the question to be shown in the UI.
            required (bool): If the question is required for a record to be valid. At least one question must be required.
            visible_labels (Optional[int]): The number of visible labels for the question to be shown in the UI. \
                Setting it to None show all options.
        """

        super().__init__(
            name=name,
            title=title,
            required=required,
            description=description,
            settings=LabelQuestionSettings(
                options=self._render_values_as_options(labels),
                visible_options=visible_labels,
            ),
            _client=client,
        )

    ##############################
    # Public properties
    ##############################

    @property
    def labels(self) -> List[str]:
        return self._render_options_as_labels(self._model.settings.options)

    @labels.setter
    def labels(self, labels: List[str]) -> None:
        self._model.settings.options = self._render_values_as_options(labels)

    @property
    def visible_labels(self) -> Optional[int]:
        return self._model.settings.visible_options

    @visible_labels.setter
    def visible_labels(self, visible_labels: Optional[int]) -> None:
        self._model.settings.visible_options = visible_labels

    @classmethod
    def from_model(cls, model: QuestionModel) -> "Self":
        instance = cls(name=model.name, labels=cls._render_options_as_labels(model.settings.options))  # noqa
        instance._model = model

        return instance

__init__(name, labels, title=None, description=None, required=True, visible_labels=None, client=None)

DatasetSettings 定义一个新的标签问题。标签问题是一种用户可以从可用标签列表中选择一个标签的问题。

参数

名称 类型 描述 默认值
name str

问题的名称,用作参考。

required
labels Union[List[str], Dict[str, str]]

问题的可用标签列表,或键值对字典,其中键是标签,值是在 UI 中显示的标签名称。

required
title Optional[str]

要在 UI 中显示的问题标题。

None
description Optional[str]

要在 UI 中显示的问题描述。

None
required bool

如果记录要有效,此问题是否为必填项。至少一个问题必须是必填项。

True
visible_labels Optional[int]

要在 UI 中显示的问题的可见标签数量。设置为 None 将显示所有选项。

None
源代码位于 src/argilla/settings/_question.py
def __init__(
    self,
    name: str,
    labels: Union[List[str], Dict[str, str]],
    title: Optional[str] = None,
    description: Optional[str] = None,
    required: bool = True,
    visible_labels: Optional[int] = None,
    client: Optional[Argilla] = None,
) -> None:
    """ Define a new label question for `Settings` of a `Dataset`. A label \
        question is a question where the user can select one label from \
        a list of available labels.

    Parameters:
        name (str): The name of the question to be used as a reference.
        labels (Union[List[str], Dict[str, str]]): The list of available labels for the question, or a
            dictionary of key-value pairs where the key is the label and the value is the label name displayed in the UI.
        title (Optional[str]): The title of the question to be shown in the UI.
        description (Optional[str]): The description of the question to be shown in the UI.
        required (bool): If the question is required for a record to be valid. At least one question must be required.
        visible_labels (Optional[int]): The number of visible labels for the question to be shown in the UI. \
            Setting it to None show all options.
    """

    super().__init__(
        name=name,
        title=title,
        required=required,
        description=description,
        settings=LabelQuestionSettings(
            options=self._render_values_as_options(labels),
            visible_options=visible_labels,
        ),
        _client=client,
    )

MultiLabelQuestion

基类: LabelQuestion

源代码位于 src/argilla/settings/_question.py
class MultiLabelQuestion(LabelQuestion):
    def __init__(
        self,
        name: str,
        labels: Union[List[str], Dict[str, str]],
        visible_labels: Optional[int] = None,
        labels_order: Literal["natural", "suggestion"] = "natural",
        title: Optional[str] = None,
        description: Optional[str] = None,
        required: bool = True,
        client: Optional[Argilla] = None,
    ) -> None:
        """Create a new multi-label question for `Settings` of a `Dataset`. A \
            multi-label question is a question where the user can select multiple \
            labels from a list of available labels.

        Parameters:
            name (str): The name of the question to be used as a reference.
            labels (Union[List[str], Dict[str, str]]): The list of available labels for the question, or a \
                dictionary of key-value pairs where the key is the label and the value is the label name displayed in the UI.
            visible_labels (Optional[int]): The number of visible labels for the question to be shown in the UI. \
                Setting it to None show all options.
            labels_order (Literal["natural", "suggestion"]): The order of the labels in the UI. \
                Can be either "natural" (order in which they were specified) or "suggestion" (order prioritizing those associated with a suggestion). \
                The score of the suggestion will be taken into account for ordering if available.
            title (Optional[str]: The title of the question to be shown in the UI.
            description (Optional[str]): The description of the question to be shown in the UI.
            required (bool): If the question is required for a record to be valid. At least one question must be required.
        """
        QuestionBase.__init__(
            self,
            name=name,
            title=title,
            required=required,
            description=description,
            settings=MultiLabelQuestionSettings(
                options=self._render_values_as_options(labels),
                visible_options=visible_labels,
                options_order=labels_order,
            ),
            _client=client,
        )

    @classmethod
    def from_model(cls, model: QuestionModel) -> "Self":
        instance = cls(name=model.name, labels=cls._render_options_as_labels(model.settings.options))  # noqa
        instance._model = model

        return instance

__init__(name, labels, visible_labels=None, labels_order='natural', title=None, description=None, required=True, client=None)

DatasetSettings 创建一个新的多标签问题。多标签问题是一种用户可以从可用标签列表中选择多个标签的问题。

参数

名称 类型 描述 默认值
name str

问题的名称,用作参考。

required
labels Union[List[str], Dict[str, str]]

问题的可用标签列表,或键值对字典,其中键是标签,值是在 UI 中显示的标签名称。

required
visible_labels Optional[int]

要在 UI 中显示的问题的可见标签数量。设置为 None 将显示所有选项。

None
labels_order Literal['natural', 'suggestion']

UI 中标签的顺序。可以是 “natural”(指定的顺序)或 “suggestion”(优先考虑与建议关联的标签的顺序)。如果建议可用,则将考虑建议的分数以进行排序。

'natural'
title Optional[str]

要在 UI 中显示的问题标题。

None
description Optional[str]

要在 UI 中显示的问题描述。

None
required bool

如果记录要有效,此问题是否为必填项。至少一个问题必须是必填项。

True
源代码位于 src/argilla/settings/_question.py
def __init__(
    self,
    name: str,
    labels: Union[List[str], Dict[str, str]],
    visible_labels: Optional[int] = None,
    labels_order: Literal["natural", "suggestion"] = "natural",
    title: Optional[str] = None,
    description: Optional[str] = None,
    required: bool = True,
    client: Optional[Argilla] = None,
) -> None:
    """Create a new multi-label question for `Settings` of a `Dataset`. A \
        multi-label question is a question where the user can select multiple \
        labels from a list of available labels.

    Parameters:
        name (str): The name of the question to be used as a reference.
        labels (Union[List[str], Dict[str, str]]): The list of available labels for the question, or a \
            dictionary of key-value pairs where the key is the label and the value is the label name displayed in the UI.
        visible_labels (Optional[int]): The number of visible labels for the question to be shown in the UI. \
            Setting it to None show all options.
        labels_order (Literal["natural", "suggestion"]): The order of the labels in the UI. \
            Can be either "natural" (order in which they were specified) or "suggestion" (order prioritizing those associated with a suggestion). \
            The score of the suggestion will be taken into account for ordering if available.
        title (Optional[str]: The title of the question to be shown in the UI.
        description (Optional[str]): The description of the question to be shown in the UI.
        required (bool): If the question is required for a record to be valid. At least one question must be required.
    """
    QuestionBase.__init__(
        self,
        name=name,
        title=title,
        required=required,
        description=description,
        settings=MultiLabelQuestionSettings(
            options=self._render_values_as_options(labels),
            visible_options=visible_labels,
            options_order=labels_order,
        ),
        _client=client,
    )

RankingQuestion

基类: QuestionBase

源代码位于 src/argilla/settings/_question.py
class RankingQuestion(QuestionBase):
    def __init__(
        self,
        name: str,
        values: Union[List[str], Dict[str, str]],
        title: Optional[str] = None,
        description: Optional[str] = None,
        required: bool = True,
        client: Optional[Argilla] = None,
    ) -> None:
        """Create a new ranking question for `Settings` of a `Dataset`. A ranking question \
            is a question where the user can rank a list of options.

        Parameters:
            name (str): The name of the question to be used as a reference.
            values (Union[List[str], Dict[str, str]]): The list of options to be ranked, or a \
                dictionary of key-value pairs where the key is the label and the value is the label name displayed in the UI.
            title (Optional[str]:) The title of the question to be shown in the UI.
            description (Optional[str]): The description of the question to be shown in the UI.
            required (bool): If the question is required for a record to be valid. At least one question must be required.
        """
        super().__init__(
            name=name,
            title=title,
            required=required,
            description=description,
            settings=RankingQuestionSettings(options=self._render_values_as_options(values)),
            _client=client,
        )

    @property
    def values(self) -> List[str]:
        return self._render_options_as_labels(self._model.settings.options)

    @values.setter
    def values(self, values: List[int]) -> None:
        self._model.settings.options = self._render_values_as_options(values)

    @classmethod
    def from_model(cls, model: QuestionModel) -> "Self":
        instance = cls(name=model.name, values=cls._render_options_as_labels(model.settings.options))  # noqa
        instance._model = model

        return instance

__init__(name, values, title=None, description=None, required=True, client=None)

DatasetSettings 创建一个新的排序问题。排序问题是一种用户可以对选项列表进行排序的问题。

参数

名称 类型 描述 默认值
name str

问题的名称,用作参考。

required
values Union[List[str], Dict[str, str]]

要排序的选项列表,或键值对字典,其中键是标签,值是在 UI 中显示的标签名称。

required
title Optional[str]

) 要在 UI 中显示的问题标题。

None
description Optional[str]

要在 UI 中显示的问题描述。

None
required bool

如果记录要有效,此问题是否为必填项。至少一个问题必须是必填项。

True
源代码位于 src/argilla/settings/_question.py
def __init__(
    self,
    name: str,
    values: Union[List[str], Dict[str, str]],
    title: Optional[str] = None,
    description: Optional[str] = None,
    required: bool = True,
    client: Optional[Argilla] = None,
) -> None:
    """Create a new ranking question for `Settings` of a `Dataset`. A ranking question \
        is a question where the user can rank a list of options.

    Parameters:
        name (str): The name of the question to be used as a reference.
        values (Union[List[str], Dict[str, str]]): The list of options to be ranked, or a \
            dictionary of key-value pairs where the key is the label and the value is the label name displayed in the UI.
        title (Optional[str]:) The title of the question to be shown in the UI.
        description (Optional[str]): The description of the question to be shown in the UI.
        required (bool): If the question is required for a record to be valid. At least one question must be required.
    """
    super().__init__(
        name=name,
        title=title,
        required=required,
        description=description,
        settings=RankingQuestionSettings(options=self._render_values_as_options(values)),
        _client=client,
    )

TextQuestion

基类: QuestionBase

源代码位于 src/argilla/settings/_question.py
class TextQuestion(QuestionBase):
    def __init__(
        self,
        name: str,
        title: Optional[str] = None,
        description: Optional[str] = None,
        required: bool = True,
        use_markdown: bool = False,
        client: Optional[Argilla] = None,
    ) -> None:
        """Create a new text question for `Settings` of a `Dataset`. A text question \
            is a question where the user can input text.

        Parameters:
            name (str): The name of the question to be used as a reference.
            title (Optional[str]): The title of the question to be shown in the UI.
            description (Optional[str]): The description of the question to be shown in the UI.
            required (bool): If the question is required for a record to be valid. At least one question must be required.
            use_markdown (Optional[bool]): Whether to render the markdown in the UI. When True, you will be able \
                to use all the Markdown features for text formatting, including LaTex formulas and embedding multimedia content and PDFs.
        """
        super().__init__(
            name=name,
            title=title,
            required=required,
            description=description,
            settings=TextQuestionSettings(use_markdown=use_markdown),
            _client=client,
        )

    @property
    def use_markdown(self) -> bool:
        return self._model.settings.use_markdown

    @use_markdown.setter
    def use_markdown(self, use_markdown: bool) -> None:
        self._model.settings.use_markdown = use_markdown

__init__(name, title=None, description=None, required=True, use_markdown=False, client=None)

DatasetSettings 创建一个新的文本问题。文本问题是一种用户可以输入文本的问题。

参数

名称 类型 描述 默认值
name str

问题的名称,用作参考。

required
title Optional[str]

要在 UI 中显示的问题标题。

None
description Optional[str]

要在 UI 中显示的问题描述。

None
required bool

如果记录要有效,此问题是否为必填项。至少一个问题必须是必填项。

True
use_markdown Optional[bool]

是否在 UI 中渲染 markdown。当为 True 时,您将能够使用所有 Markdown 功能进行文本格式设置,包括 LaTex 公式和嵌入多媒体内容和 PDF。

False
源代码位于 src/argilla/settings/_question.py
def __init__(
    self,
    name: str,
    title: Optional[str] = None,
    description: Optional[str] = None,
    required: bool = True,
    use_markdown: bool = False,
    client: Optional[Argilla] = None,
) -> None:
    """Create a new text question for `Settings` of a `Dataset`. A text question \
        is a question where the user can input text.

    Parameters:
        name (str): The name of the question to be used as a reference.
        title (Optional[str]): The title of the question to be shown in the UI.
        description (Optional[str]): The description of the question to be shown in the UI.
        required (bool): If the question is required for a record to be valid. At least one question must be required.
        use_markdown (Optional[bool]): Whether to render the markdown in the UI. When True, you will be able \
            to use all the Markdown features for text formatting, including LaTex formulas and embedding multimedia content and PDFs.
    """
    super().__init__(
        name=name,
        title=title,
        required=required,
        description=description,
        settings=TextQuestionSettings(use_markdown=use_markdown),
        _client=client,
    )

RatingQuestion

基类: QuestionBase

源代码位于 src/argilla/settings/_question.py
class RatingQuestion(QuestionBase):
    def __init__(
        self,
        name: str,
        values: List[int],
        title: Optional[str] = None,
        description: Optional[str] = None,
        required: bool = True,
        client: Optional[Argilla] = None,
    ) -> None:
        """Create a new rating question for `Settings` of a `Dataset`. A rating question \
            is a question where the user can select a value from a sequential list of options.

        Parameters:
            name (str): The name of the question to be used as a reference.
            values (List[int]): The list of selectable values. It should be defined in the range [0, 10].
            title (Optional[str]:) The title of the question to be shown in the UI.
            description (Optional[str]): The description of the question to be shown in the UI.
            required (bool): If the question is required for a record to be valid. At least one question must be required.
        """

        super().__init__(
            name=name,
            title=title,
            required=required,
            description=description,
            settings=RatingQuestionSettings(options=self._render_values_as_options(values)),
            _client=client,
        )

    @property
    def values(self) -> List[int]:
        return self._render_options_as_labels(self._model.settings.options)  # noqa

    @values.setter
    def values(self, values: List[int]) -> None:
        self._model.values = self._render_values_as_options(values)

    @classmethod
    def from_model(cls, model: QuestionModel) -> "Self":
        instance = cls(name=model.name, values=cls._render_options_as_labels(model.settings.options))  # noqa
        instance._model = model

        return instance

__init__(name, values, title=None, description=None, required=True, client=None)

DatasetSettings 创建一个新的评分问题。评分问题是一种用户可以从顺序选项列表中选择一个值的问题。

参数

名称 类型 描述 默认值
name str

问题的名称,用作参考。

required
values List[int]

可选择值的列表。应在 [0, 10] 范围内定义。

required
title Optional[str]

) 要在 UI 中显示的问题标题。

None
description Optional[str]

要在 UI 中显示的问题描述。

None
required bool

如果记录要有效,此问题是否为必填项。至少一个问题必须是必填项。

True
源代码位于 src/argilla/settings/_question.py
def __init__(
    self,
    name: str,
    values: List[int],
    title: Optional[str] = None,
    description: Optional[str] = None,
    required: bool = True,
    client: Optional[Argilla] = None,
) -> None:
    """Create a new rating question for `Settings` of a `Dataset`. A rating question \
        is a question where the user can select a value from a sequential list of options.

    Parameters:
        name (str): The name of the question to be used as a reference.
        values (List[int]): The list of selectable values. It should be defined in the range [0, 10].
        title (Optional[str]:) The title of the question to be shown in the UI.
        description (Optional[str]): The description of the question to be shown in the UI.
        required (bool): If the question is required for a record to be valid. At least one question must be required.
    """

    super().__init__(
        name=name,
        title=title,
        required=required,
        description=description,
        settings=RatingQuestionSettings(options=self._render_values_as_options(values)),
        _client=client,
    )

SpanQuestion

基类: QuestionBase

源代码位于 src/argilla/settings/_question.py
class SpanQuestion(QuestionBase):
    def __init__(
        self,
        name: str,
        field: str,
        labels: Union[List[str], Dict[str, str]],
        allow_overlapping: bool = False,
        visible_labels: Optional[int] = None,
        title: Optional[str] = None,
        description: Optional[str] = None,
        required: bool = True,
        client: Optional[Argilla] = None,
    ):
        """ Create a new span question for `Settings` of a `Dataset`. A span question \
            is a question where the user can select a section of text within a text field \
            and assign it a label.

            Parameters:
                name (str): The name of the question to be used as a reference.
                field (str): The name of the text field where the span question will be applied.
                labels (Union[List[str], Dict[str, str]]): The list of available labels for the question, or a \
                    dictionary of key-value pairs where the key is the label and the value is the label name displayed in the UI.
                allow_overlapping (bool): This value specifies whether overlapped spans are allowed or not.
                visible_labels (Optional[int]): The number of visible labels for the question to be shown in the UI. \
                    Setting it to None show all options.
                title (Optional[str]:) The title of the question to be shown in the UI.
                description (Optional[str]): The description of the question to be shown in the UI.
                required (bool): If the question is required for a record to be valid. At least one question must be required.
            """
        super().__init__(
            name=name,
            title=title,
            required=required,
            description=description,
            settings=SpanQuestionSettings(
                field=field,
                allow_overlapping=allow_overlapping,
                visible_options=visible_labels,
                options=self._render_values_as_options(labels),
            ),
            _client=client,
        )

    @property
    def field(self):
        return self._model.settings.field

    @field.setter
    def field(self, field: str):
        self._model.settings.field = field

    @property
    def allow_overlapping(self):
        return self._model.settings.allow_overlapping

    @allow_overlapping.setter
    def allow_overlapping(self, allow_overlapping: bool):
        self._model.settings.allow_overlapping = allow_overlapping

    @property
    def visible_labels(self) -> Optional[int]:
        return self._model.settings.visible_options

    @visible_labels.setter
    def visible_labels(self, visible_labels: Optional[int]) -> None:
        self._model.settings.visible_options = visible_labels

    @property
    def labels(self) -> List[str]:
        return self._render_options_as_labels(self._model.settings.options)

    @labels.setter
    def labels(self, labels: List[str]) -> None:
        self._model.settings.options = self._render_values_as_options(labels)

    @classmethod
    def from_model(cls, model: QuestionModel) -> "Self":
        instance = cls(
            name=model.name,
            field=model.settings.field,
            labels=cls._render_options_as_labels(model.settings.options),
        )  # noqa
        instance._model = model

        return instance

__init__(name, field, labels, allow_overlapping=False, visible_labels=None, title=None, description=None, required=True, client=None)

DatasetSettings 创建一个新的 Span 问题。Span 问题是一种用户可以在文本字段中选择一段文本并为其分配标签的问题。

参数

名称 类型 描述 默认值
name str

问题的名称,用作参考。

required
field str

将应用 Span 问题的文本字段的名称。

required
labels Union[List[str], Dict[str, str]]

问题的可用标签列表,或键值对字典,其中键是标签,值是在 UI 中显示的标签名称。

required
allow_overlapping bool

此值指定是否允许重叠的 Span。

False
visible_labels Optional[int]

要在 UI 中显示的问题的可见标签数量。设置为 None 将显示所有选项。

None
title Optional[str]

) 要在 UI 中显示的问题标题。

None
description Optional[str]

要在 UI 中显示的问题描述。

None
required bool

如果记录要有效,此问题是否为必填项。至少一个问题必须是必填项。

True
源代码位于 src/argilla/settings/_question.py
def __init__(
    self,
    name: str,
    field: str,
    labels: Union[List[str], Dict[str, str]],
    allow_overlapping: bool = False,
    visible_labels: Optional[int] = None,
    title: Optional[str] = None,
    description: Optional[str] = None,
    required: bool = True,
    client: Optional[Argilla] = None,
):
    """ Create a new span question for `Settings` of a `Dataset`. A span question \
        is a question where the user can select a section of text within a text field \
        and assign it a label.

        Parameters:
            name (str): The name of the question to be used as a reference.
            field (str): The name of the text field where the span question will be applied.
            labels (Union[List[str], Dict[str, str]]): The list of available labels for the question, or a \
                dictionary of key-value pairs where the key is the label and the value is the label name displayed in the UI.
            allow_overlapping (bool): This value specifies whether overlapped spans are allowed or not.
            visible_labels (Optional[int]): The number of visible labels for the question to be shown in the UI. \
                Setting it to None show all options.
            title (Optional[str]:) The title of the question to be shown in the UI.
            description (Optional[str]): The description of the question to be shown in the UI.
            required (bool): If the question is required for a record to be valid. At least one question must be required.
        """
    super().__init__(
        name=name,
        title=title,
        required=required,
        description=description,
        settings=SpanQuestionSettings(
            field=field,
            allow_overlapping=allow_overlapping,
            visible_options=visible_labels,
            options=self._render_values_as_options(labels),
        ),
        _client=client,
    )