SpanBasedNERBase<T>
Base Classes · AiDotNet.NER.SpanBased
Base class for span-based NER models (SpERT, BiaffineNER, PURE).
Inheritance: NeuralNetworkBase<T> → NERNeuralNetworkBase<T> → SequenceLabelingNERBase<T> → SpanBasedNERBase<T>
Implements: INERModel<T>
Known derived types: BiaffineNER<T>, PURENER<T>, PyramidNER<T>, SpERTNER<T>, TriaffineNER<T>, W2NER<T>
How It Works
Span-based NER models enumerate candidate entity spans (contiguous subsequences) and classify each span as an entity type or non-entity. This approach differs fundamentally from sequence labeling (BIO tagging):
Sequence Labeling (BiLSTM-CRF): Labels each token independently: [B-PER, I-PER, O, O, B-ORG, I-ORG] Cannot naturally handle nested entities (e.g., “New York” inside “New York University”)
Span-Based (SpERT, BiaffineNER, PURE): Enumerates spans: (0,1)=“Barack”, (0,2)=“Barack Obama”, (2,3)=“was”, … Classifies each span: (0,2)=PER, (4,6)=LOC, (0,6)=non-entity, … Naturally handles nested entities because different spans can have different labels
Architecture:
The span representation combines boundary tokens, span content, and span width features into a fixed-size vector for classification.
Properties
| Property | Summary |
|---|---|
int[] ExpectedInputShape { get; } |
Methods
| Method | Summary |
|---|---|
IReadOnlyList<NamedEntitySpan> PredictSpans(Tensor<T> tokenEmbeddings) |
The entities the model’s own head finds, nested and overlapping ones included: every scored span whose most likely category is not the non-entity class (0), with its probability. |
ModelMetadata<T> GetModelMetadata() |
|
Tensor<T> PredictLabels(Tensor<T> tokenEmbeddings) |
|
void Train(Tensor<T> input, Tensor<T> expected) |
|
void TrainWithSpanTargets(Tensor<T> tokenEmbeddings, Tensor<T> spanTargets) |
Trains on span-level supervision: a category per candidate span, which is the annotation form these architectures are actually defined over. |