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 has unknown label is not always initialized #3372

Merged
merged 1 commit into from
Nov 12, 2023

Conversation

helpmefindaname
Copy link
Collaborator

fixes #3367

@alanakbik
Copy link
Collaborator

@helpmefindaname thanks for fixing this! The error seems to occur because there is no valid data point to be predicted on in the test set, and therefore the has_unknown_label is never initialized.

When testing with the example script below, this PR does indeed fix this error. However, it throws another error later when the evaluate code tries to access the classification_report_dict["accuracy"] field - since there is no valid data point to make a prediction, no accuracy can be computed.

This error can be reproduced with:

import flair
from flair.data import Corpus
from flair.datasets import ColumnCorpus, WNUT_17
from flair.embeddings import TransformerWordEmbeddings
from flair.models import SpanClassifier
from flair.trainers import ModelTrainer

flair.set_seed(123)

corpus: Corpus = WNUT_17().downsample(0.01)

label_dictionary = corpus.make_label_dictionary("ner", add_unk=True)

embeddings = TransformerWordEmbeddings(
    model="distilbert-base-uncased", layers="-1", subtoken_pooling="first", fine_tune=True, use_context=True
)

tagger = SpanClassifier(embeddings=embeddings, label_dictionary=label_dictionary)

trainer = ModelTrainer(tagger, corpus)

trainer.fine_tune(
    "./results/",
    max_epochs=1,
)

@alanakbik
Copy link
Collaborator

The second error is another issue, merging this now and opening a separate PR for the above error.

@alanakbik alanakbik merged commit f30f580 into master Nov 12, 2023
1 check passed
@helpmefindaname helpmefindaname deleted the fix_has_unknown_label branch December 4, 2023 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: UnboundLocalError: local variable 'has_unknown_label' referenced before assignment
2 participants