unitorch.cli.models.bert¤
BertProcessor¤
Tip
core/process/bert
is the section for configuration of BertProcessor.
Bases: BertProcessor
Processor for BERT models.
Initialize BertProcessor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vocab_path |
str
|
The path to the vocabulary file. |
required |
max_seq_length |
int
|
The maximum sequence length. Defaults to 128. |
128
|
special_input_ids |
Dict
|
Special input IDs. Defaults to an empty dictionary. |
dict()
|
do_lower_case |
bool
|
Whether to lower case the input text. Defaults to True. |
True
|
do_basic_tokenize |
bool
|
Whether to perform basic tokenization. Defaults to True. |
True
|
do_whole_word_mask |
bool
|
Whether to use whole word masking. Defaults to True. |
True
|
masked_lm_prob |
float
|
The probability of masking a token for masked language modeling. Defaults to 0.15. |
0.15
|
max_predictions_per_seq |
int
|
The maximum number of masked LM predictions per sequence. Defaults to 20. |
20
|
Source code in src/unitorch/cli/models/bert/processing.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
from_core_configure
classmethod
¤
from_core_configure(config, **kwargs)
Create an instance of BertProcessor from a core configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
The core configuration. |
required | |
**kwargs |
Additional keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
BertProcessor |
An instance of BertProcessor. |
Source code in src/unitorch/cli/models/bert/processing.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
BertForClassification¤
Tip
core/model/classification/bert
is the section for configuration of BertForClassification.
Bases: BertForClassification
BERT model for classification tasks.
Initialize BertForClassification.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_path |
str
|
The path to the model configuration file. |
required |
num_classes |
int
|
The number of classes for classification. Defaults to 1. |
1
|
gradient_checkpointing |
bool
|
Whether to use gradient checkpointing. Defaults to False. |
False
|
Source code in src/unitorch/cli/models/bert/modeling.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
forward ¤
forward(
input_ids: Tensor,
attention_mask: Optional[Tensor] = None,
token_type_ids: Optional[Tensor] = None,
position_ids: Optional[Tensor] = None,
)
Forward pass of the BertForClassification model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_ids |
Tensor
|
Input IDs. |
required |
attention_mask |
Tensor
|
Attention mask. Defaults to None. |
None
|
token_type_ids |
Tensor
|
Token type IDs. Defaults to None. |
None
|
position_ids |
Tensor
|
Position IDs. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
ClassificationOutputs |
Model outputs for classification. |
Source code in src/unitorch/cli/models/bert/modeling.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
from_core_configure
classmethod
¤
from_core_configure(config, **kwargs)
Create an instance of BertForClassification from a core configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
The core configuration. |
required | |
**kwargs |
Additional keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
BertForClassification |
An instance of BertForClassification. |
Source code in src/unitorch/cli/models/bert/modeling.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|