-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Refactor span extractors and unify forward. #5160
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This personally looks great to me! Thanks for refactoring. I'm adding @dirkgr to look it over as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to keep SpanExtractor
as a purely abstract base class, just in case someone wants to build a totally different span extractor. But it makes sense to have a SpanExtractorWithSpanWidthEmbedding
class that's basically the class you wrote, and have all the concrete implementations derive from that (the way you already have it). Does that make sense?
Thanks for finding and fixing this!
) | ||
if self._span_width_embedding is not None: | ||
# width = end_index - start_index + 1 since `SpanField` use inclusive indices. | ||
# But here we do not add 1 beacuse we offen initiate the span width |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed offen
to often
. 🤣
Yeah, I totally agree with you! It's going to be flexible for future developments. |
@izhx Thanks for your great work! The changes look fine to me. I would edit the description of the PR to reflect what you reverted. Also, as a heads up, @dirkgr is out the rest of this week, so please give us a week to get back to you. |
Thank you! 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
* Refactor span extractors * add SpanExtractorWithSpanWidthEmbedding * update changelog * fix blank lines Co-authored-by: Dirk Groeneveld <[email protected]>
Fixes #5145. Thanks! @dirkgr
Changes proposed in this pull request:
SpanExtractorWithSpanWidthEmbedding
class with__init__
,forward
andget_input_dim
methods, putting specific span embedding computations into the abstract mehtod_embed_spans
.added the__init__
method toSpanExtractor
for initiatingspan_width_embedding
and other attributes.added theforward
method toSpanExtractor
to unifyforward
arguments of all extractors.added comments forwidth = span_end - span_start
.added an_embed_spans
method, which need to be implemented to compute span embeddings in different ways, toSpanExtractor
.EndpointSpanExtractor
,SelfAttentiveSpanExtractor
andBidirectionalEndpointSpanExtractor
accordingly (changeforward
to_embed_spans
, Inherit fromSpanExtractorWithSpanWidthEmbedding
).Now,
SelfAttentiveSpanExtractor
can also embed span widths.