pub struct HandshakingMatrix {
pub cells: Vec<HandshakingCell>,
pub seq_len: usize,
pub num_labels: usize,
}Expand description
Handshaking matrix for joint entity-relation extraction.
§Research Alignment (W2NER, AAAI 2022)
From the W2NER paper (arXiv:2112.10070):
“We present a novel alternative by modeling the unified NER as word-word relation classification, namely W2NER. The architecture resolves the kernel bottleneck of unified NER by effectively modeling the neighboring relations between entity words with Next-Neighboring-Word (NNW) and Tail-Head-Word- (THW-*)* relations.”
In TPLinker/W2NER, we don’t just tag tokens - we tag token PAIRS. The matrix M[i,j] contains the label for the span (i, j).
§Key Relations
| Relation | Description | Purpose |
|---|---|---|
| NNW | Next-Neighboring-Word | Links adjacent tokens within entity |
| THW-* | Tail-Head-Word | Links end of one entity to start of next |
§Benefits
- Overlapping entities (same token in multiple spans)
- Joint entity-relation extraction in one pass
- Explicit boundary modeling
- Handles flat, nested, AND discontinuous NER in one model
Fields§
§cells: Vec<HandshakingCell>Non-zero cells (sparse representation)
seq_len: usizeSequence length
num_labels: usizeNumber of labels
Implementations§
Source§impl HandshakingMatrix
impl HandshakingMatrix
Sourcepub fn from_dense(
scores: &[f32],
seq_len: usize,
num_labels: usize,
threshold: f32,
) -> Self
pub fn from_dense( scores: &[f32], seq_len: usize, num_labels: usize, threshold: f32, ) -> Self
Create from dense scores with thresholding.
§Arguments
scores- Dense [seq_len, seq_len, num_labels] scoresthreshold- Minimum score to keep
Sourcepub fn decode_entities<'a>(
&self,
registry: &'a SemanticRegistry,
) -> Vec<(SpanCandidate, &'a LabelDefinition, f32)>
pub fn decode_entities<'a>( &self, registry: &'a SemanticRegistry, ) -> Vec<(SpanCandidate, &'a LabelDefinition, f32)>
Decode entities from handshaking matrix.
In W2NER convention, cell (i, j) represents a span where:
- j is the start token index
- i is the end token index (inclusive, so we add 1 for exclusive end)
Auto Trait Implementations§
impl Freeze for HandshakingMatrix
impl RefUnwindSafe for HandshakingMatrix
impl Send for HandshakingMatrix
impl Sync for HandshakingMatrix
impl Unpin for HandshakingMatrix
impl UnsafeUnpin for HandshakingMatrix
impl UnwindSafe for HandshakingMatrix
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more