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

[Fix] label_list not being set for NLP token classification training if distillation teacher and student labels do not match #1414

Merged
merged 4 commits into from
Mar 4, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/sparseml/transformers/token_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def main(**kwargs):
},
)

if teacher:
if teacher and not isinstance(teacher, str):
# check whether teacher and student have the corresponding outputs
label_to_id, label_list = _check_teacher_student_outputs(teacher, label_to_id)

Expand Down Expand Up @@ -597,6 +597,21 @@ def _check_teacher_student_outputs(
f"student labels {student_labels}. Ignore this warning "
"if this is expected behavior."
)
is_teacher_label_str = isinstance(teacher_labels[0], str)
is_student_label_str = isinstance(student_labels[0], str)

if is_teacher_label_str and not is_student_label_str:
# If the teacher labels are strings and the student labels are ints,
# we will assume that the teacher labels are the correct labels.
label_list = teacher_labels
models_labels_to_use = "teacher"
else:
label_list = student_labels
models_labels_to_use = "student"
_LOGGER.warning(
"From this point forward, the "
f"{models_labels_to_use}'s labels will be used."
)
else:
if student_ids != teacher_ids:
_LOGGER.warning(
Expand Down