Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: Ranking value from suggestions are not properly converted from HF datasets #4629

Merged
merged 13 commits into from
Mar 6, 2024
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ These are the section headers that we use:
### Fixed

- Fixed prepare for training when passing `RankingValueSchema` instances to suggestions. ([#4628](https://github.com/argilla-io/argilla/pull/4628))
- Fixed parsing ranking values in suggestions from HF datasets. ([#4629](https://github.com/argilla-io/argilla/pull/4629))

## [1.25.0](https://github.com/argilla-io/argilla/compare/v1.24.0...v1.25.0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,11 @@ def from_huggingface(
f"{question.name}-suggestion" in hfds[index]
and hfds[index][f"{question.name}-suggestion"] is not None
):
suggestion = {
"question_name": question.name,
"value": hfds[index][f"{question.name}-suggestion"],
}
value = hfds[index][f"{question.name}-suggestion"]
if question.type == QuestionTypes.ranking:
value = [{"rank": r, "value": v} for r, v in zip(value["rank"], value["value"])]

suggestion = {"question_name": question.name, "value": value}
if hfds[index][f"{question.name}-suggestion-metadata"] is not None:
suggestion.update(hfds[index][f"{question.name}-suggestion-metadata"])
suggestions.append(suggestion)
Expand Down
2 changes: 1 addition & 1 deletion src/argilla/client/feedback/schemas/questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class RankingQuestion(QuestionSchema, LabelMappingMixin):

Examples:
>>> from argilla.client.feedback.schemas.questions import RankingQuestion
>>> RankingQuestion(name="ranking_question", title="Ranking Question", labels=["label_1", "label_2"])
>>> RankingQuestion(name="ranking_question", title="Ranking Question", values=["label_1", "label_2"])
"""

type: Literal[QuestionTypes.ranking] = Field(QuestionTypes.ranking.value, allow_mutation=False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,10 @@ def test_push_to_huggingface_and_from_huggingface(
hf_response.dict() == response.dict()
for hf_response, response in zip(hf_record.responses, record.responses)
)
assert all(
hf_suggestion.dict() == suggestion.dict()
for hf_suggestion, suggestion in zip(hf_record.suggestions, record.suggestions)
), f"{[s.dict() for s in hf_record.suggestions]} != {[s.dict() for s in record.suggestions]}"

dataset.add_records(
records=[
Expand Down
Loading