Skip to content

[model] Support gliner2-multi-v1 model #4

Description

@Seunghui98

What

Let's support the gliner2-multi-v2 model for Named Entity Recognition (NER).

  • This model utilizes microsoft/mdeberta-v3-base as its back-bone.
  • It introduces a specialized architecture (GLiNER) for span representation and entity counting.

How

We need to implement the DebertaV2 architecture and GLiNER-specific modules.

1. DebertaV2 Backbone

  • The core difference from standard BERT is the Disentangled Attention mechanism.
  • We need to implement DebertaAttentionLayer which handles Content-to-Content(c2c), Content-to-Position(c2p), and Position-to-Content(p2c) attention scores separately.
  • Relative positional embeddings shoud be handled dynamically.

2. GLiNER Specialized Layers

  • SpanRepLayer : Aggregates token embeddings into span repreentations by concatenating start and end token projection.
  • CountLSTMLayer : Predicts the number of entities in the text using a sequence modeling approach.

TODO

FYI

model structure
============================================================
🧠 Model Configuration
============================================================
Encoder model      : microsoft/mdeberta-v3-base
Counting layer     : count_lstm
Token pooling      : first
============================================================

GLiNER2(
  (encoder): DebertaV2Model(
    (embeddings): DebertaV2Embeddings(
      (word_embeddings): Embedding(250112, 768, padding_idx=0)
      (LayerNorm): LayerNorm((768,), eps=1e-07, elementwise_affine=True)
      (dropout): Dropout(p=0.1, inplace=False)
    )
    (encoder): DebertaV2Encoder(
      (layer): ModuleList(
        (0-11): 12 x DebertaV2Layer(
          (attention): DebertaV2Attention(
            (self): DisentangledSelfAttention(
              (query_proj): Linear(in_features=768, out_features=768, bias=True)
              (key_proj): Linear(in_features=768, out_features=768, bias=True)
              (value_proj): Linear(in_features=768, out_features=768, bias=True)
              (pos_dropout): Dropout(p=0.1, inplace=False)
              (dropout): Dropout(p=0.1, inplace=False)
            )
            (output): DebertaV2SelfOutput(
              (dense): Linear(in_features=768, out_features=768, bias=True)
              (LayerNorm): LayerNorm((768,), eps=1e-07, elementwise_affine=True)
              (dropout): Dropout(p=0.1, inplace=False)
            )
          )
          (intermediate): DebertaV2Intermediate(
            (dense): Linear(in_features=768, out_features=3072, bias=True)
            (intermediate_act_fn): GELUActivation()
          )
          (output): DebertaV2Output(
            (dense): Linear(in_features=3072, out_features=768, bias=True)
            (LayerNorm): LayerNorm((768,), eps=1e-07, elementwise_affine=True)
            (dropout): Dropout(p=0.1, inplace=False)
          )
        )
      )
      (rel_embeddings): Embedding(512, 768)
      (LayerNorm): LayerNorm((768,), eps=1e-07, elementwise_affine=True)
    )
  )

  (span_rep): SpanRepLayer(
    (span_rep_layer): SpanMarkerV0(
      (project_start): Sequential(
        (0): Linear(in_features=768, out_features=3072, bias=True)
        (1): ReLU()
        (2): Dropout(p=0.1, inplace=False)
        (3): Linear(in_features=3072, out_features=768, bias=True)
      )
      (project_end): Sequential(
        (0): Linear(in_features=768, out_features=3072, bias=True)
        (1): ReLU()
        (2): Dropout(p=0.1, inplace=False)
        (3): Linear(in_features=3072, out_features=768, bias=True)
      )
      (out_project): Sequential(
        (0): Linear(in_features=1536, out_features=3072, bias=True)
        (1): ReLU()
        (2): Dropout(p=0.1, inplace=False)
        (3): Linear(in_features=3072, out_features=768, bias=True)
      )
    )
  )
  (classifier): Sequential(
    (0): Linear(in_features=768, out_features=1536, bias=True)
    (1): ReLU()
    (2): Linear(in_features=1536, out_features=1, bias=True)
  )
  (count_pred): Sequential(
    (0): Linear(in_features=768, out_features=1536, bias=True)
    (1): ReLU()
    (2): Linear(in_features=1536, out_features=20, bias=True)
  )
  (count_embed): CountLSTM(
    (pos_embedding): Embedding(20, 768)
    (gru): GRU(768, 768)
    (projector): Sequential(
      (0): Linear(in_features=1536, out_features=3072, bias=True)
      (1): ReLU()
      (2): Linear(in_features=3072, out_features=768, bias=True)
    )
  )
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions