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 all 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
12 changes: 8 additions & 4 deletions src/sparseml/transformers/token_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,11 @@ 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)
label_to_id, label_list = _check_teacher_student_outputs(
teacher, label_to_id, label_list
)

tokenizer_src = (
model_args.tokenizer_name
Expand Down Expand Up @@ -580,7 +582,7 @@ def compute_metrics(p):


def _check_teacher_student_outputs(
teacher: Module, label_to_id: Dict[str, int]
teacher: Module, label_to_id: Dict[str, int], label_list: List[str]
) -> Tuple[Dict[str, int], List[str]]:
# Check that the teacher and student have the same labels and if they do,
# check that the mapping between labels and ids is the same.
Expand Down Expand Up @@ -765,7 +767,9 @@ def _get_tokenized_dataset(
# Map that sends B-Xxx label to its I-Xxx counterpart
b_to_i_label = []
for idx, label in enumerate(label_list):
if label.startswith("B-") and label.replace("B-", "I-") in label_list:
if isinstance(label, str) and (
label.startswith("B-") and label.replace("B-", "I-") in label_list
):
b_to_i_label.append(label_list.index(label.replace("B-", "I-")))
else:
b_to_i_label.append(idx)
Expand Down