Skip to content

Conversation

TurtleOrangina
Copy link

@TurtleOrangina TurtleOrangina 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

@TurtleOrangina
Copy link
Author

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

@TurtleOrangina TurtleOrangina force-pushed the get_span_from_bio_tweak branch from 3bf3cf2 to 15e0ae1 Compare April 17, 2023 06:39
@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