Ahmet Yildirim commited on
Commit ·
dc24a98
1
Parent(s): 6dfe435
- Development
Browse files- configuration_norbert.py +35 -0
- modeling_humit_tagger.py +9 -5
configuration_norbert.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Taken from https://huggingface.co/ltg/norbert3-large/blob/main/configuration_norbert.py
|
| 2 |
+
from transformers.configuration_utils import PretrainedConfig
|
| 3 |
+
|
| 4 |
+
class NorbertConfig(PretrainedConfig):
|
| 5 |
+
"""Configuration class to store the configuration of a `NorbertModel`.
|
| 6 |
+
"""
|
| 7 |
+
def __init__(
|
| 8 |
+
self,
|
| 9 |
+
vocab_size=50000,
|
| 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 |
+
**kwargs,
|
| 21 |
+
):
|
| 22 |
+
super().__init__(**kwargs)
|
| 23 |
+
|
| 24 |
+
self.vocab_size = vocab_size
|
| 25 |
+
self.hidden_size = hidden_size
|
| 26 |
+
self.num_hidden_layers = num_hidden_layers
|
| 27 |
+
self.num_attention_heads = num_attention_heads
|
| 28 |
+
self.intermediate_size = intermediate_size
|
| 29 |
+
self.hidden_dropout_prob = hidden_dropout_prob
|
| 30 |
+
self.attention_probs_dropout_prob = attention_probs_dropout_prob
|
| 31 |
+
self.max_position_embeddings = max_position_embeddings
|
| 32 |
+
self.output_all_encoded_layers = output_all_encoded_layers
|
| 33 |
+
self.position_bucket_size = position_bucket_size
|
| 34 |
+
self.layer_norm_eps = layer_norm_eps
|
| 35 |
+
|
modeling_humit_tagger.py
CHANGED
|
@@ -43,15 +43,16 @@ class HumitTaggerModel(torch.nn.Module):
|
|
| 43 |
spec.loader.exec_module(lemma_rules)
|
| 44 |
|
| 45 |
# Download base_model files into cache
|
| 46 |
-
base_config_file = hf_hub_download(repo_id=kwargs["this_model_config"]["base_model"], filename=kwargs["this_model_config"]["base_model_config_file"])
|
|
|
|
| 47 |
# base_model_file = hf_hub_download(repo_id=kwargs["this_model_config"]["base_model"], filename=kwargs["this_model_config"]["base_model_model_file"])
|
| 48 |
base_model_file = hf_hub_download(repo_id=repo_name, filename=kwargs["this_model_config"]["base_model_model_file"])
|
| 49 |
base_model_config_json_file = hf_hub_download(repo_id=kwargs["this_model_config"]["base_model"], filename=kwargs["this_model_config"]["base_model_config_json_file"])
|
| 50 |
fullformlist_file = hf_hub_download(repo_id=repo_name, filename=kwargs["this_model_config"]["fullformlist_file"])
|
| 51 |
|
| 52 |
# Copy base model's configuration python file into our working directory
|
| 53 |
-
config_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)) , os.path.basename(base_config_file))
|
| 54 |
-
shutil.copyfile(base_config_file, config_file_path)
|
| 55 |
|
| 56 |
# HACK: Modify base model main file since __init.py__ has already been read and the new file must not contain relative imports
|
| 57 |
# base_model_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)) , os.path.basename(base_model_file))
|
|
@@ -62,8 +63,11 @@ class HumitTaggerModel(torch.nn.Module):
|
|
| 62 |
|
| 63 |
# Register the new files:
|
| 64 |
# First register the base model config file
|
| 65 |
-
sys.path.append(os.path.dirname(config_file_path))
|
| 66 |
-
spec = importlib.util.spec_from_file_location("base_config", config_file_path)
|
|
|
|
|
|
|
|
|
|
| 67 |
base_config = importlib.util.module_from_spec(spec)
|
| 68 |
sys.modules["base_config"] = base_config
|
| 69 |
spec.loader.exec_module(base_config)
|
|
|
|
| 43 |
spec.loader.exec_module(lemma_rules)
|
| 44 |
|
| 45 |
# Download base_model files into cache
|
| 46 |
+
# base_config_file = hf_hub_download(repo_id=kwargs["this_model_config"]["base_model"], filename=kwargs["this_model_config"]["base_model_config_file"])
|
| 47 |
+
base_config_file = hf_hub_download(repo_id=repo_name, filename=kwargs["this_model_config"]["base_model_config_file"])
|
| 48 |
# base_model_file = hf_hub_download(repo_id=kwargs["this_model_config"]["base_model"], filename=kwargs["this_model_config"]["base_model_model_file"])
|
| 49 |
base_model_file = hf_hub_download(repo_id=repo_name, filename=kwargs["this_model_config"]["base_model_model_file"])
|
| 50 |
base_model_config_json_file = hf_hub_download(repo_id=kwargs["this_model_config"]["base_model"], filename=kwargs["this_model_config"]["base_model_config_json_file"])
|
| 51 |
fullformlist_file = hf_hub_download(repo_id=repo_name, filename=kwargs["this_model_config"]["fullformlist_file"])
|
| 52 |
|
| 53 |
# Copy base model's configuration python file into our working directory
|
| 54 |
+
# config_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)) , os.path.basename(base_config_file))
|
| 55 |
+
# shutil.copyfile(base_config_file, config_file_path)
|
| 56 |
|
| 57 |
# HACK: Modify base model main file since __init.py__ has already been read and the new file must not contain relative imports
|
| 58 |
# base_model_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)) , os.path.basename(base_model_file))
|
|
|
|
| 63 |
|
| 64 |
# Register the new files:
|
| 65 |
# First register the base model config file
|
| 66 |
+
# sys.path.append(os.path.dirname(config_file_path))
|
| 67 |
+
# spec = importlib.util.spec_from_file_location("base_config", config_file_path)
|
| 68 |
+
sys.path.append(os.path.dirname(base_config_file))
|
| 69 |
+
spec = importlib.util.spec_from_file_location("base_config", base_config_file)
|
| 70 |
+
|
| 71 |
base_config = importlib.util.module_from_spec(spec)
|
| 72 |
sys.modules["base_config"] = base_config
|
| 73 |
spec.loader.exec_module(base_config)
|