emanuelaboros commited on
Commit
5dbef48
·
1 Parent(s): 3eadfd6

Initial commit of the trained NER model with code

Browse files
Files changed (2) hide show
  1. config.json +81 -1
  2. models.py +5 -2
config.json CHANGED
@@ -21,11 +21,91 @@
21
  "intermediate_size": 2048,
22
  "layer_norm_eps": 1e-12,
23
  "max_position_embeddings": 512,
24
- "model_type": "bert",
25
  "num_attention_heads": 8,
26
  "num_hidden_layers": 8,
27
  "pad_token_id": 0,
28
  "position_embedding_type": "absolute",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  "torch_dtype": "float32",
30
  "transformers_version": "4.40.0.dev0",
31
  "type_vocab_size": 2,
 
21
  "intermediate_size": 2048,
22
  "layer_norm_eps": 1e-12,
23
  "max_position_embeddings": 512,
24
+ "model_type": "extended_multitask",
25
  "num_attention_heads": 8,
26
  "num_hidden_layers": 8,
27
  "pad_token_id": 0,
28
  "position_embedding_type": "absolute",
29
+ "pretrained_config": {
30
+ "_name_or_path": "dbmdz/bert-medium-historic-multilingual-cased",
31
+ "add_cross_attention": false,
32
+ "architectures": [
33
+ "BertForMaskedLM"
34
+ ],
35
+ "attention_probs_dropout_prob": 0.1,
36
+ "bad_words_ids": null,
37
+ "begin_suppress_tokens": null,
38
+ "bos_token_id": null,
39
+ "chunk_size_feed_forward": 0,
40
+ "classifier_dropout": null,
41
+ "cross_attention_hidden_size": null,
42
+ "decoder_start_token_id": null,
43
+ "diversity_penalty": 0.0,
44
+ "do_sample": false,
45
+ "early_stopping": false,
46
+ "encoder_no_repeat_ngram_size": 0,
47
+ "eos_token_id": null,
48
+ "exponential_decay_length_penalty": null,
49
+ "finetuning_task": null,
50
+ "forced_bos_token_id": null,
51
+ "forced_eos_token_id": null,
52
+ "hidden_act": "gelu",
53
+ "hidden_dropout_prob": 0.1,
54
+ "hidden_size": 512,
55
+ "id2label": {
56
+ "0": "LABEL_0",
57
+ "1": "LABEL_1"
58
+ },
59
+ "initializer_range": 0.02,
60
+ "intermediate_size": 2048,
61
+ "is_decoder": false,
62
+ "is_encoder_decoder": false,
63
+ "label2id": {
64
+ "LABEL_0": 0,
65
+ "LABEL_1": 1
66
+ },
67
+ "layer_norm_eps": 1e-12,
68
+ "length_penalty": 1.0,
69
+ "max_length": 20,
70
+ "max_position_embeddings": 512,
71
+ "min_length": 0,
72
+ "model_type": "bert",
73
+ "no_repeat_ngram_size": 0,
74
+ "num_attention_heads": 8,
75
+ "num_beam_groups": 1,
76
+ "num_beams": 1,
77
+ "num_hidden_layers": 8,
78
+ "num_return_sequences": 1,
79
+ "output_attentions": false,
80
+ "output_hidden_states": false,
81
+ "output_scores": false,
82
+ "pad_token_id": 0,
83
+ "position_embedding_type": "absolute",
84
+ "prefix": null,
85
+ "problem_type": null,
86
+ "pruned_heads": {},
87
+ "remove_invalid_values": false,
88
+ "repetition_penalty": 1.0,
89
+ "return_dict": true,
90
+ "return_dict_in_generate": false,
91
+ "sep_token_id": null,
92
+ "suppress_tokens": null,
93
+ "task_specific_params": null,
94
+ "temperature": 1.0,
95
+ "tf_legacy_loss": false,
96
+ "tie_encoder_decoder": false,
97
+ "tie_word_embeddings": true,
98
+ "tokenizer_class": null,
99
+ "top_k": 50,
100
+ "top_p": 1.0,
101
+ "torch_dtype": null,
102
+ "torchscript": false,
103
+ "type_vocab_size": 2,
104
+ "typical_p": 1.0,
105
+ "use_bfloat16": false,
106
+ "use_cache": true,
107
+ "vocab_size": 32000
108
+ },
109
  "torch_dtype": "float32",
110
  "transformers_version": "4.40.0.dev0",
111
  "type_vocab_size": 2,
models.py CHANGED
@@ -4,6 +4,7 @@ import torch.nn as nn
4
  from transformers import PreTrainedModel, AutoModel, AutoConfig
5
  from torch.nn import CrossEntropyLoss
6
  from typing import Optional, Tuple, Union
 
7
  import logging
8
 
9
  logger = logging.getLogger(__name__)
@@ -11,7 +12,7 @@ logger = logging.getLogger(__name__)
11
 
12
  class ExtendedMultitaskModelForTokenClassification(PreTrainedModel):
13
 
14
- config_class = AutoConfig
15
  _keys_to_ignore_on_load_missing = [r"position_ids"]
16
 
17
  def __init__(self, config, num_token_labels_dict):
@@ -20,7 +21,9 @@ class ExtendedMultitaskModelForTokenClassification(PreTrainedModel):
20
  self.config = config
21
 
22
  # self.bert = AutoModel.from_config(config)
23
- self.bert = AutoModel.from_pretrained(config.name_or_path, config=config)
 
 
24
  if "classifier_dropout" not in config.__dict__:
25
  classifier_dropout = 0.1
26
  else:
 
4
  from transformers import PreTrainedModel, AutoModel, AutoConfig
5
  from torch.nn import CrossEntropyLoss
6
  from typing import Optional, Tuple, Union
7
+ from configuration import ImpressoConfig
8
  import logging
9
 
10
  logger = logging.getLogger(__name__)
 
12
 
13
  class ExtendedMultitaskModelForTokenClassification(PreTrainedModel):
14
 
15
+ config_class = ImpressoConfig
16
  _keys_to_ignore_on_load_missing = [r"position_ids"]
17
 
18
  def __init__(self, config, num_token_labels_dict):
 
21
  self.config = config
22
 
23
  # self.bert = AutoModel.from_config(config)
24
+ self.bert = AutoModel.from_pretrained(
25
+ config.name_or_path, config=config.pretrained_config
26
+ )
27
  if "classifier_dropout" not in config.__dict__:
28
  classifier_dropout = 0.1
29
  else: