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

get_spans_from_bio: Start new span for previous S- if class also changed #3195

Merged
merged 2 commits into from
Apr 19, 2023

Conversation

Lingepumpe
Copy link
Contributor

@Lingepumpe Lingepumpe commented Apr 16, 2023

In previous flair versions (e.g. 0.10) get_span_from_bio would start a new span if the previous tag was a "S-" token of a different class than the current token, see:
https://github.com/flairNLP/flair/blob/v0.10/flair/data.py#L698

It happens that our production model semi-frequently produces these kinds of (invalid BIOES) prediction, and that the new span extraction performs worse on our data.
This adds back this special check for previous tag "S-", making span calculation more similar to what it was in 0.10, and remaining the same for all 100% valid BIOES tagging.

Also included are some minor code tweaks to the function to make it prettier.

@alanakbik
Copy link
Collaborator

alanakbik commented Apr 16, 2023

Hello @Lingepumpe thanks for fixing this.

Reviewing the code I think the line

        if bioes_tag[0:2] == "S-" and previous_tag[2:] != bioes_tag[2:]:
            starts_new_span = True

can be removed altogether, since before this, we already check for S- alone:

        # begin and single tags start new spans
        if bioes_tag[0:2] in {"B-", "S-"}:
            starts_new_span = True

@Lingepumpe
Copy link
Contributor Author

Removed the unnecessary if, also wrote the whole "starts_new_span = True" conditions a bit more compactly

@alanakbik
Copy link
Collaborator

Thanks @Lingepumpe, looks great!

@alanakbik alanakbik merged commit 3bc7736 into flairNLP:master Apr 19, 2023
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.

2 participants