Upload folder using huggingface_hub
Browse files- config.json +30 -0
- config_alignscore.py +10 -0
- merges.txt +0 -0
- model.safetensors +3 -0
- modeling_alignscore.py +129 -0
- special_tokens_map.json +15 -0
- tokenizer.json +0 -0
- tokenizer_config.json +58 -0
- vocab.json +0 -0
config.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"AlignscoreModel"
|
| 4 |
+
],
|
| 5 |
+
"attention_probs_dropout_prob": 0.1,
|
| 6 |
+
"auto_map": {
|
| 7 |
+
"AutoConfig": "config_alignscore.AlignscoreConfig",
|
| 8 |
+
"AutoModelForSequenceClassification": "modeling_alignscore.AlignscoreModel"
|
| 9 |
+
},
|
| 10 |
+
"bos_token_id": 0,
|
| 11 |
+
"classifier_dropout": null,
|
| 12 |
+
"eos_token_id": 2,
|
| 13 |
+
"hidden_act": "gelu",
|
| 14 |
+
"hidden_dropout_prob": 0.1,
|
| 15 |
+
"hidden_size": 1024,
|
| 16 |
+
"initializer_range": 0.02,
|
| 17 |
+
"intermediate_size": 4096,
|
| 18 |
+
"layer_norm_eps": 1e-05,
|
| 19 |
+
"max_position_embeddings": 514,
|
| 20 |
+
"model_type": "alignscore",
|
| 21 |
+
"num_attention_heads": 16,
|
| 22 |
+
"num_hidden_layers": 24,
|
| 23 |
+
"pad_token_id": 1,
|
| 24 |
+
"position_embedding_type": "absolute",
|
| 25 |
+
"torch_dtype": "float32",
|
| 26 |
+
"transformers_version": "4.51.3",
|
| 27 |
+
"type_vocab_size": 1,
|
| 28 |
+
"use_cache": true,
|
| 29 |
+
"vocab_size": 50265
|
| 30 |
+
}
|
config_alignscore.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers.models.roberta import RobertaConfig
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class AlignscoreConfig(RobertaConfig):
|
| 5 |
+
"""
|
| 6 |
+
This is a custom configuration class for the Alignscore model, inheriting from RobertaConfig.
|
| 7 |
+
It can be extended with additional parameters specific to the Alignscore model if needed.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
model_type = "alignscore"
|
merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:75013f907d46ca316e2821f8230cbb9a8e15989395e5c60a3f72cbe734434cfa
|
| 3 |
+
size 1421512112
|
modeling_alignscore.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dataclasses import dataclass
|
| 2 |
+
from typing import Optional, Tuple, Union
|
| 3 |
+
|
| 4 |
+
import torch
|
| 5 |
+
from torch import nn
|
| 6 |
+
from transformers import (
|
| 7 |
+
AutoTokenizer,
|
| 8 |
+
AutoModel,
|
| 9 |
+
AutoModelForSequenceClassification,
|
| 10 |
+
AutoConfig,
|
| 11 |
+
)
|
| 12 |
+
from transformers.modeling_outputs import (
|
| 13 |
+
BaseModelOutputWithPastAndCrossAttentions,
|
| 14 |
+
BaseModelOutputWithPoolingAndCrossAttentions,
|
| 15 |
+
CausalLMOutputWithCrossAttentions,
|
| 16 |
+
MaskedLMOutput,
|
| 17 |
+
MultipleChoiceModelOutput,
|
| 18 |
+
QuestionAnsweringModelOutput,
|
| 19 |
+
SequenceClassifierOutput,
|
| 20 |
+
TokenClassifierOutput,
|
| 21 |
+
)
|
| 22 |
+
from transformers.models.roberta import (
|
| 23 |
+
RobertaConfig,
|
| 24 |
+
RobertaForMaskedLM,
|
| 25 |
+
RobertaForSequenceClassification,
|
| 26 |
+
RobertaModel,
|
| 27 |
+
RobertaPreTrainedModel,
|
| 28 |
+
)
|
| 29 |
+
from transformers.models.roberta.modeling_roberta import RobertaLMHead
|
| 30 |
+
from config_alignscore import AlignscoreConfig
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
@dataclass
|
| 34 |
+
class ModelOutput:
|
| 35 |
+
loss: Optional[torch.FloatTensor] = None
|
| 36 |
+
all_loss: Optional[list] = None
|
| 37 |
+
loss_nums: Optional[list] = None
|
| 38 |
+
prediction_logits: torch.FloatTensor = None
|
| 39 |
+
seq_relationship_logits: torch.FloatTensor = None
|
| 40 |
+
tri_label_logits: torch.FloatTensor = None
|
| 41 |
+
reg_label_logits: torch.FloatTensor = None
|
| 42 |
+
hidden_states: Optional[Tuple[torch.FloatTensor]] = None
|
| 43 |
+
attentions: Optional[Tuple[torch.FloatTensor]] = None
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class AlignscoreModel(RobertaPreTrainedModel):
|
| 47 |
+
config_class = AlignscoreConfig
|
| 48 |
+
# COPIED FROM transformers.models.roberta.modeling_roberta.RobertaForSequenceClassification
|
| 49 |
+
|
| 50 |
+
def __init__(self, config):
|
| 51 |
+
super().__init__(config)
|
| 52 |
+
# NUM_LABELS WILL BE IGNOREDD
|
| 53 |
+
# self.num_labels = config.num_labels
|
| 54 |
+
|
| 55 |
+
self.config = config
|
| 56 |
+
|
| 57 |
+
self.roberta = RobertaModel(config, add_pooling_layer=True)
|
| 58 |
+
self.bin_layer = nn.Linear(config.hidden_size, 2)
|
| 59 |
+
self.tri_layer = nn.Linear(config.hidden_size, 3)
|
| 60 |
+
self.reg_layer = nn.Linear(config.hidden_size, 1)
|
| 61 |
+
|
| 62 |
+
if config.hidden_dropout_prob != 0.1:
|
| 63 |
+
print(
|
| 64 |
+
"Warning: The hidden_dropout_prob is not set to 0.1, which may affect the model's performance."
|
| 65 |
+
)
|
| 66 |
+
self.dropout = nn.Dropout(config.hidden_dropout_prob) # should be 0.1
|
| 67 |
+
self.softmax = nn.Softmax(dim=-1)
|
| 68 |
+
# Initialize weights and apply final processing
|
| 69 |
+
self.post_init()
|
| 70 |
+
|
| 71 |
+
def forward(
|
| 72 |
+
self,
|
| 73 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 74 |
+
attention_mask: Optional[torch.FloatTensor] = None,
|
| 75 |
+
token_type_ids: Optional[torch.LongTensor] = None,
|
| 76 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 77 |
+
head_mask: Optional[torch.FloatTensor] = None,
|
| 78 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 79 |
+
labels: Optional[torch.LongTensor] = None,
|
| 80 |
+
output_attentions: Optional[bool] = None,
|
| 81 |
+
output_hidden_states: Optional[bool] = None,
|
| 82 |
+
return_dict: Optional[bool] = None,
|
| 83 |
+
) -> Union[Tuple[torch.Tensor], SequenceClassifierOutput]:
|
| 84 |
+
r"""
|
| 85 |
+
labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
|
| 86 |
+
Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
|
| 87 |
+
config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
|
| 88 |
+
`config.num_labels > 1` a classification loss is computed (Cross-Entropy).
|
| 89 |
+
"""
|
| 90 |
+
return_dict = (
|
| 91 |
+
return_dict if return_dict is not None else self.config.use_return_dict
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
outputs = self.roberta(
|
| 95 |
+
input_ids,
|
| 96 |
+
attention_mask=attention_mask,
|
| 97 |
+
token_type_ids=token_type_ids,
|
| 98 |
+
position_ids=position_ids,
|
| 99 |
+
head_mask=head_mask,
|
| 100 |
+
inputs_embeds=inputs_embeds,
|
| 101 |
+
output_attentions=output_attentions,
|
| 102 |
+
output_hidden_states=output_hidden_states,
|
| 103 |
+
return_dict=return_dict,
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
seq_relationship_score = self.bin_layer(
|
| 107 |
+
self.dropout(outputs.pooler_output)
|
| 108 |
+
) ## pooled output for classification
|
| 109 |
+
tri_label_score = self.tri_layer(self.dropout(outputs.pooler_output))
|
| 110 |
+
reg_label_score = self.reg_layer(outputs.pooler_output)
|
| 111 |
+
|
| 112 |
+
if labels is not None:
|
| 113 |
+
raise NotImplementedError(
|
| 114 |
+
"AlignscoreModel does not support labels for training. "
|
| 115 |
+
"Please use the model for inference only."
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
return ModelOutput(
|
| 119 |
+
loss=None,
|
| 120 |
+
all_loss=None,
|
| 121 |
+
loss_nums=None,
|
| 122 |
+
prediction_logits=None,
|
| 123 |
+
seq_relationship_logits=seq_relationship_score,
|
| 124 |
+
tri_label_logits=tri_label_score,
|
| 125 |
+
reg_label_logits=reg_label_score,
|
| 126 |
+
hidden_states=outputs.hidden_states,
|
| 127 |
+
attentions=outputs.attentions,
|
| 128 |
+
)
|
| 129 |
+
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": "<s>",
|
| 3 |
+
"cls_token": "<s>",
|
| 4 |
+
"eos_token": "</s>",
|
| 5 |
+
"mask_token": {
|
| 6 |
+
"content": "<mask>",
|
| 7 |
+
"lstrip": true,
|
| 8 |
+
"normalized": false,
|
| 9 |
+
"rstrip": false,
|
| 10 |
+
"single_word": false
|
| 11 |
+
},
|
| 12 |
+
"pad_token": "<pad>",
|
| 13 |
+
"sep_token": "</s>",
|
| 14 |
+
"unk_token": "<unk>"
|
| 15 |
+
}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"added_tokens_decoder": {
|
| 4 |
+
"0": {
|
| 5 |
+
"content": "<s>",
|
| 6 |
+
"lstrip": false,
|
| 7 |
+
"normalized": true,
|
| 8 |
+
"rstrip": false,
|
| 9 |
+
"single_word": false,
|
| 10 |
+
"special": true
|
| 11 |
+
},
|
| 12 |
+
"1": {
|
| 13 |
+
"content": "<pad>",
|
| 14 |
+
"lstrip": false,
|
| 15 |
+
"normalized": true,
|
| 16 |
+
"rstrip": false,
|
| 17 |
+
"single_word": false,
|
| 18 |
+
"special": true
|
| 19 |
+
},
|
| 20 |
+
"2": {
|
| 21 |
+
"content": "</s>",
|
| 22 |
+
"lstrip": false,
|
| 23 |
+
"normalized": true,
|
| 24 |
+
"rstrip": false,
|
| 25 |
+
"single_word": false,
|
| 26 |
+
"special": true
|
| 27 |
+
},
|
| 28 |
+
"3": {
|
| 29 |
+
"content": "<unk>",
|
| 30 |
+
"lstrip": false,
|
| 31 |
+
"normalized": true,
|
| 32 |
+
"rstrip": false,
|
| 33 |
+
"single_word": false,
|
| 34 |
+
"special": true
|
| 35 |
+
},
|
| 36 |
+
"50264": {
|
| 37 |
+
"content": "<mask>",
|
| 38 |
+
"lstrip": true,
|
| 39 |
+
"normalized": false,
|
| 40 |
+
"rstrip": false,
|
| 41 |
+
"single_word": false,
|
| 42 |
+
"special": true
|
| 43 |
+
}
|
| 44 |
+
},
|
| 45 |
+
"bos_token": "<s>",
|
| 46 |
+
"clean_up_tokenization_spaces": false,
|
| 47 |
+
"cls_token": "<s>",
|
| 48 |
+
"eos_token": "</s>",
|
| 49 |
+
"errors": "replace",
|
| 50 |
+
"extra_special_tokens": {},
|
| 51 |
+
"mask_token": "<mask>",
|
| 52 |
+
"model_max_length": 512,
|
| 53 |
+
"pad_token": "<pad>",
|
| 54 |
+
"sep_token": "</s>",
|
| 55 |
+
"tokenizer_class": "RobertaTokenizer",
|
| 56 |
+
"trim_offsets": true,
|
| 57 |
+
"unk_token": "<unk>"
|
| 58 |
+
}
|
vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|