Jamie@TitanML commited on
Commit
8fe5261
1 Parent(s): df96927

Create configuration_jina.py

Browse files
Files changed (1) hide show
  1. configuration_jina.py +132 -0
configuration_jina.py ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers.configuration_utils import PretrainedConfig
2
+ from transformers.utils import logging
3
+
4
+
5
+ logger = logging.get_logger(__name__)
6
+
7
+
8
+ class JinaBertConfig(PretrainedConfig):
9
+ r"""
10
+ This is the configuration class to store the configuration of a [`JinaBertModel`]. It is used to
11
+ instantiate a BERT model according to the specified arguments, defining the model architecture. Instantiating a
12
+ configuration with the defaults will yield a similar configuration to that of the BERT
13
+ [bert-base-uncased](https://huggingface.co/bert-base-uncased) architecture.
14
+
15
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
16
+ documentation from [`PretrainedConfig`] for more information.
17
+
18
+
19
+ Args:
20
+ vocab_size (`int`, *optional*, defaults to 30522):
21
+ Vocabulary size of the BERT model. Defines the number of different tokens that can be represented by the
22
+ `inputs_ids` passed when calling [`BertModel`] or [`TFBertModel`].
23
+ hidden_size (`int`, *optional*, defaults to 768):
24
+ Dimensionality of the encoder layers and the pooler layer.
25
+ num_hidden_layers (`int`, *optional*, defaults to 12):
26
+ Number of hidden layers in the Transformer encoder.
27
+ num_attention_heads (`int`, *optional*, defaults to 12):
28
+ Number of attention heads for each attention layer in the Transformer encoder.
29
+ intermediate_size (`int`, *optional*, defaults to 3072):
30
+ Dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer encoder.
31
+ hidden_act (`str` or `Callable`, *optional*, defaults to `"gelu"`):
32
+ The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
33
+ `"relu"`, `"silu"` and `"gelu_new"` are supported.
34
+ hidden_dropout_prob (`float`, *optional*, defaults to 0.1):
35
+ The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
36
+ attention_probs_dropout_prob (`float`, *optional*, defaults to 0.1):
37
+ The dropout ratio for the attention probabilities.
38
+ max_position_embeddings (`int`, *optional*, defaults to 512):
39
+ The maximum sequence length that this model might ever be used with. Typically set this to something large
40
+ just in case (e.g., 512 or 1024 or 2048).
41
+ type_vocab_size (`int`, *optional*, defaults to 2):
42
+ The vocabulary size of the `token_type_ids` passed when calling [`BertModel`] or [`TFBertModel`].
43
+ initializer_range (`float`, *optional*, defaults to 0.02):
44
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
45
+ layer_norm_eps (`float`, *optional*, defaults to 1e-12):
46
+ The epsilon used by the layer normalization layers.
47
+ position_embedding_type (`str`, *optional*, defaults to `"absolute"`):
48
+ Type of position embedding. Choose one of `"absolute"`, `"relative_key"`, `"relative_key_query"`. For
49
+ positional embeddings use `"absolute"`. For more information on `"relative_key"`, please refer to
50
+ [Self-Attention with Relative Position Representations (Shaw et al.)](https://arxiv.org/abs/1803.02155).
51
+ For more information on `"relative_key_query"`, please refer to *Method 4* in [Improve Transformer Models
52
+ with Better Relative Position Embeddings (Huang et al.)](https://arxiv.org/abs/2009.13658).
53
+ is_decoder (`bool`, *optional*, defaults to `False`):
54
+ Whether the model is used as a decoder or not. If `False`, the model is used as an encoder.
55
+ use_cache (`bool`, *optional*, defaults to `True`):
56
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
57
+ relevant if `config.is_decoder=True`.
58
+ classifier_dropout (`float`, *optional*):
59
+ The dropout ratio for the classification head.
60
+ feed_forward_type (`str`, *optional*, defaults to `"original"`):
61
+ The type of feed forward layer to use in the bert layers.
62
+ Can be one of GLU variants, e.g. `"reglu"`, `"geglu"`
63
+ emb_pooler (`str`, *optional*, defaults to `None`):
64
+ The function to use for pooling the last layer embeddings to get the sentence embeddings.
65
+ Should be one of `None`, `"mean"`.
66
+ attn_implementation (`str`, *optional*, defaults to `"torch"`):
67
+ The implementation of the self-attention layer. Can be one of:
68
+ - `None` for the original implementation,
69
+ - `torch` for the PyTorch SDPA implementation,
70
+
71
+ Examples:
72
+
73
+ ```python
74
+ >>> from transformers import JinaBertConfig, JinaBertModel
75
+
76
+ >>> # Initializing a JinaBert configuration
77
+ >>> configuration = JinaBertConfig()
78
+
79
+ >>> # Initializing a model (with random weights) from the configuration
80
+ >>> model = JinaBertModel(configuration)
81
+
82
+ >>> # Accessing the model configuration
83
+ >>> configuration = model.config
84
+
85
+ >>> # Encode text inputs
86
+ >>> embeddings = model.encode(text_inputs)
87
+ ```"""
88
+ model_type = "bert"
89
+
90
+ def __init__(
91
+ self,
92
+ vocab_size=30522,
93
+ hidden_size=768,
94
+ num_hidden_layers=12,
95
+ num_attention_heads=12,
96
+ intermediate_size=3072,
97
+ hidden_act="gelu",
98
+ hidden_dropout_prob=0.1,
99
+ attention_probs_dropout_prob=0.1,
100
+ max_position_embeddings=512,
101
+ type_vocab_size=2,
102
+ initializer_range=0.02,
103
+ layer_norm_eps=1e-12,
104
+ pad_token_id=0,
105
+ position_embedding_type="absolute",
106
+ use_cache=True,
107
+ classifier_dropout=None,
108
+ feed_forward_type="original",
109
+ emb_pooler=None,
110
+ attn_implementation="torch",
111
+ **kwargs,
112
+ ):
113
+ super().__init__(pad_token_id=pad_token_id, **kwargs)
114
+
115
+ self.vocab_size = vocab_size
116
+ self.hidden_size = hidden_size
117
+ self.num_hidden_layers = num_hidden_layers
118
+ self.num_attention_heads = num_attention_heads
119
+ self.hidden_act = hidden_act
120
+ self.intermediate_size = intermediate_size
121
+ self.hidden_dropout_prob = hidden_dropout_prob
122
+ self.attention_probs_dropout_prob = attention_probs_dropout_prob
123
+ self.max_position_embeddings = max_position_embeddings
124
+ self.type_vocab_size = type_vocab_size
125
+ self.initializer_range = initializer_range
126
+ self.layer_norm_eps = layer_norm_eps
127
+ self.position_embedding_type = position_embedding_type
128
+ self.use_cache = use_cache
129
+ self.classifier_dropout = classifier_dropout
130
+ self.feed_forward_type = feed_forward_type
131
+ self.emb_pooler = emb_pooler
132
+ self.attn_implementation = attn_implementation