Rename configuration_gpt_bert.py to configuration_ltgbert.py
Browse files- configuration_gpt_bert.py +0 -54
- configuration_ltgbert.py +36 -0
configuration_gpt_bert.py
DELETED
@@ -1,54 +0,0 @@
|
|
1 |
-
from __future__ import annotations
|
2 |
-
|
3 |
-
import json
|
4 |
-
import pathlib
|
5 |
-
import copy
|
6 |
-
|
7 |
-
from typing import Any
|
8 |
-
from transformers.configuration_utils import PretrainedConfig
|
9 |
-
|
10 |
-
|
11 |
-
class ModelConfig(PretrainedConfig):
|
12 |
-
|
13 |
-
def __init__(self: ModelConfig, config_file: pathlib.Path | str | None = None, **kwargs):
|
14 |
-
"""
|
15 |
-
"""
|
16 |
-
super().__init__(**kwargs)
|
17 |
-
if config_file is None:
|
18 |
-
self.attention_probs_dropout_prob: float = 0.1
|
19 |
-
self.hidden_dropout_prob = 0.1
|
20 |
-
self.hidden_size = 384
|
21 |
-
self.intermediate_size = 1280
|
22 |
-
self.max_sequence_length = 128
|
23 |
-
self.position_bucket_size = 32
|
24 |
-
self.num_attention_heads = 6
|
25 |
-
self.num_layers = 12
|
26 |
-
self.vocab_size = 8192
|
27 |
-
self.layer_norm_eps = 1e-7
|
28 |
-
else:
|
29 |
-
if config_file == "str":
|
30 |
-
config_file = pathlib.Path(config_file)
|
31 |
-
|
32 |
-
config: dict[str, Any] = json.load(config_file.open("r"))
|
33 |
-
|
34 |
-
for key, value in config.items():
|
35 |
-
setattr(self, key, value)
|
36 |
-
|
37 |
-
def __repr__(self) -> str:
|
38 |
-
return str(self.to_json_string())
|
39 |
-
|
40 |
-
def to_dict(self) -> dict[str, Any]:
|
41 |
-
"""Serializes this instance to a Python dictionary."""
|
42 |
-
output: dict[str, Any] = copy.deepcopy(self.__dict__)
|
43 |
-
return output
|
44 |
-
|
45 |
-
def to_json_string(self) -> str:
|
46 |
-
"""Serializes this instance to a JSON string."""
|
47 |
-
return json.dumps(self.to_dict(), indent=2, sort_keys=True) + "\n"
|
48 |
-
|
49 |
-
def to_json_file(self, json_file_path: pathlib.Path | str) -> None:
|
50 |
-
"""Save this instance to a json file."""
|
51 |
-
if isinstance(json_file_path, str):
|
52 |
-
json_file_path: pathlib.Path = pathlib.Path(json_file_path)
|
53 |
-
with json_file_path.open("w", encoding='utf-8') as writer:
|
54 |
-
writer.write(self.to_json_string())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configuration_ltgbert.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers.configuration_utils import PretrainedConfig
|
2 |
+
|
3 |
+
|
4 |
+
class LtgbertConfig(PretrainedConfig):
|
5 |
+
"""Configuration class to store the configuration of a `LtgbertModel`.
|
6 |
+
"""
|
7 |
+
def __init__(
|
8 |
+
self,
|
9 |
+
vocab_size=32768,
|
10 |
+
attention_probs_dropout_prob=0.1,
|
11 |
+
hidden_dropout_prob=0.1,
|
12 |
+
hidden_size=768,
|
13 |
+
intermediate_size=2048,
|
14 |
+
max_position_embeddings=512,
|
15 |
+
position_bucket_size=32,
|
16 |
+
num_attention_heads=12,
|
17 |
+
num_hidden_layers=12,
|
18 |
+
layer_norm_eps=1.0e-7,
|
19 |
+
output_all_encoded_layers=True,
|
20 |
+
temperature=1.0,
|
21 |
+
**kwargs,
|
22 |
+
):
|
23 |
+
super().__init__(**kwargs)
|
24 |
+
|
25 |
+
self.vocab_size = vocab_size
|
26 |
+
self.hidden_size = hidden_size
|
27 |
+
self.num_hidden_layers = num_hidden_layers
|
28 |
+
self.num_attention_heads = num_attention_heads
|
29 |
+
self.intermediate_size = intermediate_size
|
30 |
+
self.hidden_dropout_prob = hidden_dropout_prob
|
31 |
+
self.attention_probs_dropout_prob = attention_probs_dropout_prob
|
32 |
+
self.max_position_embeddings = max_position_embeddings
|
33 |
+
self.output_all_encoded_layers = output_all_encoded_layers
|
34 |
+
self.position_bucket_size = position_bucket_size
|
35 |
+
self.layer_norm_eps = layer_norm_eps
|
36 |
+
self.temperature = temperature
|