File size: 811 Bytes
945de56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""DeBERTa-v3-base for sentence-pair boundary classification."""

from transformers import (
    DebertaV2ForSequenceClassification,
    DebertaV2Tokenizer,
    PreTrainedTokenizerBase,
)

from src.datasets.combined_pairs_dataset import NUM_LABELS, ID2LABEL, LABEL2ID

BASE_MODEL = "microsoft/deberta-v3-base"


def load_deberta(
    pretrained: str = BASE_MODEL,
) -> DebertaV2ForSequenceClassification:
    """Instantiate DeBERTa-v3-base for 3-class sentence-pair classification."""
    return DebertaV2ForSequenceClassification.from_pretrained(
        pretrained,
        num_labels=NUM_LABELS,
        id2label=ID2LABEL,
        label2id=LABEL2ID,
    )


def load_deberta_tokenizer(
    pretrained: str = BASE_MODEL,
) -> PreTrainedTokenizerBase:
    return DebertaV2Tokenizer.from_pretrained(pretrained)