Commit
·
1b37761
1
Parent(s):
3b9629b
lets try to change the pipeline
Browse files- model.safetensors +0 -3
- model2.safetensors +3 -0
- modeling_stacked.py +97 -97
model.safetensors
CHANGED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:03a807b124debff782406c816eacb7ced1f2e25b9a5198b27e1616a41faa0662
|
| 3 |
-
size 193971960
|
|
|
|
|
|
|
|
|
|
|
|
model2.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:03a807b124debff782406c816eacb7ced1f2e25b9a5198b27e1616a41faa0662
|
| 3 |
+
size 193971960
|
modeling_stacked.py
CHANGED
|
@@ -23,22 +23,22 @@ class ExtendedMultitaskModelForTokenClassification(PreTrainedModel):
|
|
| 23 |
|
| 24 |
def __init__(self, config):
|
| 25 |
super().__init__(config)
|
| 26 |
-
self.num_token_labels_dict = get_info(config.label_map)
|
| 27 |
-
self.config = config
|
| 28 |
-
# print(f"I dont think it arrives here: {self.config}")
|
| 29 |
-
self.bert = AutoModel.from_pretrained(
|
| 30 |
-
|
| 31 |
-
)
|
| 32 |
-
self.model_floret = floret.load_model(self.config.filename)
|
| 33 |
-
print(f"Model loaded: {self.model_floret}")
|
| 34 |
-
if "classifier_dropout" not in config.__dict__:
|
| 35 |
-
|
| 36 |
-
else:
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
# self.dropout = nn.Dropout(classifier_dropout)
|
| 43 |
#
|
| 44 |
# # Additional transformer layers
|
|
@@ -48,94 +48,94 @@ class ExtendedMultitaskModelForTokenClassification(PreTrainedModel):
|
|
| 48 |
# ),
|
| 49 |
# num_layers=2,
|
| 50 |
# )
|
| 51 |
-
|
| 52 |
-
#
|
| 53 |
# self.token_classifiers = nn.ModuleDict(
|
| 54 |
# {
|
| 55 |
# task: nn.Linear(config.hidden_size, num_labels)
|
| 56 |
# for task, num_labels in self.num_token_labels_dict.items()
|
| 57 |
# }
|
| 58 |
# )
|
| 59 |
-
|
| 60 |
-
# Initialize weights and apply final processing
|
| 61 |
-
self.post_init()
|
| 62 |
|
| 63 |
def get_floret_model(self):
|
| 64 |
return self.model_floret
|
| 65 |
|
| 66 |
-
def forward(
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
) -> Union[Tuple[torch.Tensor], TokenClassifierOutput]:
|
| 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 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
|
|
|
| 23 |
|
| 24 |
def __init__(self, config):
|
| 25 |
super().__init__(config)
|
| 26 |
+
# self.num_token_labels_dict = get_info(config.label_map)
|
| 27 |
+
# self.config = config
|
| 28 |
+
# # print(f"I dont think it arrives here: {self.config}")
|
| 29 |
+
# self.bert = AutoModel.from_pretrained(
|
| 30 |
+
# config.pretrained_config["_name_or_path"], config=config.pretrained_config
|
| 31 |
+
# )
|
| 32 |
+
# self.model_floret = floret.load_model(self.config.filename)
|
| 33 |
+
# print(f"Model loaded: {self.model_floret}")
|
| 34 |
+
# if "classifier_dropout" not in config.__dict__:
|
| 35 |
+
# classifier_dropout = 0.1
|
| 36 |
+
# else:
|
| 37 |
+
# classifier_dropout = (
|
| 38 |
+
# config.classifier_dropout
|
| 39 |
+
# if config.classifier_dropout is not None
|
| 40 |
+
# else config.hidden_dropout_prob
|
| 41 |
+
# )
|
| 42 |
# self.dropout = nn.Dropout(classifier_dropout)
|
| 43 |
#
|
| 44 |
# # Additional transformer layers
|
|
|
|
| 48 |
# ),
|
| 49 |
# num_layers=2,
|
| 50 |
# )
|
| 51 |
+
|
| 52 |
+
# For token classification, create a classifier for each task
|
| 53 |
# self.token_classifiers = nn.ModuleDict(
|
| 54 |
# {
|
| 55 |
# task: nn.Linear(config.hidden_size, num_labels)
|
| 56 |
# for task, num_labels in self.num_token_labels_dict.items()
|
| 57 |
# }
|
| 58 |
# )
|
| 59 |
+
#
|
| 60 |
+
# # Initialize weights and apply final processing
|
| 61 |
+
# self.post_init()
|
| 62 |
|
| 63 |
def get_floret_model(self):
|
| 64 |
return self.model_floret
|
| 65 |
|
| 66 |
+
# def forward(
|
| 67 |
+
# self,
|
| 68 |
+
# input_ids: Optional[torch.Tensor] = None,
|
| 69 |
+
# attention_mask: Optional[torch.Tensor] = None,
|
| 70 |
+
# token_type_ids: Optional[torch.Tensor] = None,
|
| 71 |
+
# position_ids: Optional[torch.Tensor] = None,
|
| 72 |
+
# head_mask: Optional[torch.Tensor] = None,
|
| 73 |
+
# inputs_embeds: Optional[torch.Tensor] = None,
|
| 74 |
+
# labels: Optional[torch.Tensor] = None,
|
| 75 |
+
# token_labels: Optional[dict] = None,
|
| 76 |
+
# output_attentions: Optional[bool] = None,
|
| 77 |
+
# output_hidden_states: Optional[bool] = None,
|
| 78 |
+
# return_dict: Optional[bool] = None,
|
| 79 |
+
# ) -> Union[Tuple[torch.Tensor], TokenClassifierOutput]:
|
| 80 |
+
# r"""
|
| 81 |
+
# token_labels (`dict` of `torch.LongTensor` of shape `(batch_size, seq_length)`, *optional*):
|
| 82 |
+
# Labels for computing the token classification loss. Keys should match the tasks.
|
| 83 |
+
# """
|
| 84 |
+
# return_dict = (
|
| 85 |
+
# return_dict if return_dict is not None else self.config.use_return_dict
|
| 86 |
+
# )
|
| 87 |
+
#
|
| 88 |
+
# bert_kwargs = {
|
| 89 |
+
# "input_ids": input_ids,
|
| 90 |
+
# "attention_mask": attention_mask,
|
| 91 |
+
# "token_type_ids": token_type_ids,
|
| 92 |
+
# "position_ids": position_ids,
|
| 93 |
+
# "head_mask": head_mask,
|
| 94 |
+
# "inputs_embeds": inputs_embeds,
|
| 95 |
+
# "output_attentions": output_attentions,
|
| 96 |
+
# "output_hidden_states": output_hidden_states,
|
| 97 |
+
# "return_dict": return_dict,
|
| 98 |
+
# }
|
| 99 |
+
#
|
| 100 |
+
# if any(
|
| 101 |
+
# keyword in self.config.name_or_path.lower()
|
| 102 |
+
# for keyword in ["llama", "deberta"]
|
| 103 |
+
# ):
|
| 104 |
+
# bert_kwargs.pop("token_type_ids")
|
| 105 |
+
# bert_kwargs.pop("head_mask")
|
| 106 |
+
#
|
| 107 |
+
# outputs = self.bert(**bert_kwargs)
|
| 108 |
+
#
|
| 109 |
+
# # For token classification
|
| 110 |
+
# token_output = outputs[0]
|
| 111 |
+
# token_output = self.dropout(token_output)
|
| 112 |
+
#
|
| 113 |
+
# # Pass through additional transformer layers
|
| 114 |
+
# token_output = self.transformer_encoder(token_output.transpose(0, 1)).transpose(
|
| 115 |
+
# 0, 1
|
| 116 |
+
# )
|
| 117 |
+
#
|
| 118 |
+
# # Collect the logits and compute the loss for each task
|
| 119 |
+
# task_logits = {}
|
| 120 |
+
# total_loss = 0
|
| 121 |
+
# for task, classifier in self.token_classifiers.items():
|
| 122 |
+
# logits = classifier(token_output)
|
| 123 |
+
# task_logits[task] = logits
|
| 124 |
+
# if token_labels and task in token_labels:
|
| 125 |
+
# loss_fct = CrossEntropyLoss()
|
| 126 |
+
# loss = loss_fct(
|
| 127 |
+
# logits.view(-1, self.num_token_labels_dict[task]),
|
| 128 |
+
# token_labels[task].view(-1),
|
| 129 |
+
# )
|
| 130 |
+
# total_loss += loss
|
| 131 |
+
#
|
| 132 |
+
# if not return_dict:
|
| 133 |
+
# output = (task_logits,) + outputs[2:]
|
| 134 |
+
# return ((total_loss,) + output) if total_loss != 0 else output
|
| 135 |
+
# print(f"Is there anobidy coming here?")
|
| 136 |
+
# return TokenClassifierOutput(
|
| 137 |
+
# loss=total_loss,
|
| 138 |
+
# logits=task_logits,
|
| 139 |
+
# hidden_states=outputs.hidden_states,
|
| 140 |
+
# attentions=outputs.attentions,
|
| 141 |
+
# )
|