postgrammar commited on
Commit
c1bf3bd
·
verified ·
1 Parent(s): 62d24d5

Upload VAD transformer model

Browse files
.gitattributes CHANGED
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ vad_by_category.png filter=lfs diff=lfs merge=lfs -text
37
+ vad_distribution.png filter=lfs diff=lfs merge=lfs -text
38
+ vad_vs_casualties.png filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # Disaster News VAD Model
3
+
4
+ This model predicts Valence, Arousal, and Dominance (VAD) values for disaster news headlines.
5
+ It was trained on the EmoBank dataset and fine-tuned on disaster news headlines.
6
+
7
+ ## Model Details
8
+
9
+ - **Architecture**: RoBERTa-based transformer model with regression heads for VAD prediction
10
+ - **Training Data**: EmoBank dataset
11
+ - **Application**: Emotional analysis of disaster news headlines
12
+ - **Date**: 2025-03-16
13
+
14
+ ## Usage
15
+
16
+ ```python
17
+ from transformers import RobertaTokenizer, AutoModel
18
+ import torch
19
+
20
+ # Load model and tokenizer
21
+ tokenizer = RobertaTokenizer.from_pretrained("postgrammar/disaster-news-vad-model")
22
+ model = AutoModel.from_pretrained("postgrammar/disaster-news-vad-model")
23
+
24
+ # Prepare input
25
+ text = "Earthquake devastates coastal town, rescue efforts underway"
26
+ inputs = tokenizer(text, return_tensors="pt")
27
+
28
+ # Get predictions
29
+ with torch.no_grad():
30
+ outputs = model(**inputs)
31
+
32
+ # Extract VAD values (first three values in the output tuple)
33
+ valence, arousal, dominance = outputs[0], outputs[1], outputs[2]
34
+
35
+ print(f"Valence: {valence.item():.4f}, Arousal: {arousal.item():.4f}, Dominance: {dominance.item():.4f}")
36
+ ```
37
+
38
+ ## Citation
39
+
40
+ If you use this model, please cite:
41
+
42
+ ```
43
+ @misc{disaster-news-vad-model,
44
+ author = {postgrammar},
45
+ title = {Disaster News VAD Model},
46
+ year = {2024},
47
+ publisher = {Hugging Face},
48
+ howpublished = {\url{https://huggingface.co/postgrammar/disaster-news-vad-model}}
49
+ }
50
+ ```
config.json ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "RobertaForVADRegression"
4
+ ],
5
+ "model_type": "roberta",
6
+ "id2label": {
7
+ "0": "valence",
8
+ "1": "arousal",
9
+ "2": "dominance"
10
+ },
11
+ "label2id": {
12
+ "valence": 0,
13
+ "arousal": 1,
14
+ "dominance": 2
15
+ },
16
+ "problem_type": "regression",
17
+ "return_dict": true,
18
+ "output_hidden_states": false,
19
+ "output_attentions": false,
20
+ "torchscript": false,
21
+ "torch_dtype": "float32",
22
+ "use_bfloat16": false,
23
+ "tf_legacy_loss": false,
24
+ "pruned_heads": {},
25
+ "tie_word_embeddings": true,
26
+ "chunk_size_feed_forward": 0,
27
+ "is_encoder_decoder": false,
28
+ "is_decoder": false,
29
+ "cross_attention_hidden_size": null,
30
+ "add_cross_attention": false,
31
+ "tie_encoder_decoder": false,
32
+ "max_length": 20,
33
+ "min_length": 0,
34
+ "do_sample": false,
35
+ "early_stopping": false,
36
+ "num_beams": 1,
37
+ "num_beam_groups": 1,
38
+ "diversity_penalty": 0.0,
39
+ "temperature": 1.0,
40
+ "top_k": 50,
41
+ "top_p": 1.0,
42
+ "typical_p": 1.0,
43
+ "repetition_penalty": 1.0,
44
+ "length_penalty": 1.0,
45
+ "no_repeat_ngram_size": 0,
46
+ "encoder_no_repeat_ngram_size": 0,
47
+ "bad_words_ids": null,
48
+ "num_return_sequences": 1,
49
+ "output_scores": false,
50
+ "return_dict_in_generate": false,
51
+ "forced_bos_token_id": null,
52
+ "forced_eos_token_id": null,
53
+ "remove_invalid_values": false,
54
+ "exponential_decay_length_penalty": null,
55
+ "suppress_tokens": null,
56
+ "begin_suppress_tokens": null,
57
+ "finetuning_task": null,
58
+ "tokenizer_class": null,
59
+ "prefix": null,
60
+ "bos_token_id": 0,
61
+ "pad_token_id": 1,
62
+ "eos_token_id": 2,
63
+ "sep_token_id": null,
64
+ "decoder_start_token_id": null,
65
+ "task_specific_params": null,
66
+ "_name_or_path": "roberta-base",
67
+ "_attn_implementation_autoset": true,
68
+ "transformers_version": "4.49.0",
69
+ "vocab_size": 50265,
70
+ "hidden_size": 768,
71
+ "num_hidden_layers": 12,
72
+ "num_attention_heads": 12,
73
+ "hidden_act": "gelu",
74
+ "intermediate_size": 3072,
75
+ "hidden_dropout_prob": 0.1,
76
+ "attention_probs_dropout_prob": 0.1,
77
+ "max_position_embeddings": 514,
78
+ "type_vocab_size": 1,
79
+ "initializer_range": 0.02,
80
+ "layer_norm_eps": 1e-05,
81
+ "position_embedding_type": "absolute",
82
+ "use_cache": true,
83
+ "classifier_dropout": null
84
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
metadata.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "language": "en",
3
+ "license": "mit",
4
+ "tags": [
5
+ "disaster",
6
+ "news",
7
+ "emotion",
8
+ "vad",
9
+ "valence",
10
+ "arousal",
11
+ "dominance",
12
+ "roberta"
13
+ ],
14
+ "datasets": [
15
+ "emobank"
16
+ ],
17
+ "metrics": [
18
+ "mse"
19
+ ]
20
+ }
modeling_vad.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ VAD Transformer Model Definition
4
+
5
+ This module defines the custom RoBERTa-based model for VAD prediction
6
+ that will be uploaded to Hugging Face.
7
+
8
+ Author: AI Assistant
9
+ """
10
+
11
+ import torch
12
+ from transformers import RobertaModel, RobertaPreTrainedModel
13
+
14
+ class RobertaForVADRegression(RobertaPreTrainedModel):
15
+ """
16
+ RoBERTa model for predicting Valence, Arousal, and Dominance values.
17
+ This model extends RobertaPreTrainedModel to be compatible with the Hugging Face ecosystem.
18
+ """
19
+
20
+ def __init__(self, config):
21
+ super().__init__(config)
22
+ self.roberta = RobertaModel(config)
23
+ self.dropout = torch.nn.Dropout(config.hidden_dropout_prob)
24
+ self.valence_head = torch.nn.Linear(config.hidden_size, 1)
25
+ self.arousal_head = torch.nn.Linear(config.hidden_size, 1)
26
+ self.dominance_head = torch.nn.Linear(config.hidden_size, 1)
27
+
28
+ # Initialize weights
29
+ self.init_weights()
30
+
31
+ def forward(
32
+ self,
33
+ input_ids=None,
34
+ attention_mask=None,
35
+ token_type_ids=None,
36
+ position_ids=None,
37
+ head_mask=None,
38
+ inputs_embeds=None,
39
+ labels=None,
40
+ output_attentions=None,
41
+ output_hidden_states=None,
42
+ return_dict=None,
43
+ ):
44
+ """
45
+ Forward pass of the model.
46
+
47
+ Returns:
48
+ tuple: Tuple containing valence, arousal, and dominance predictions
49
+ or
50
+ dict: Dictionary containing loss and predictions if labels are provided
51
+ """
52
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
53
+
54
+ outputs = self.roberta(
55
+ input_ids=input_ids,
56
+ attention_mask=attention_mask,
57
+ token_type_ids=token_type_ids,
58
+ position_ids=position_ids,
59
+ head_mask=head_mask,
60
+ inputs_embeds=inputs_embeds,
61
+ output_attentions=output_attentions,
62
+ output_hidden_states=output_hidden_states,
63
+ return_dict=return_dict,
64
+ )
65
+
66
+ sequence_output = outputs[0]
67
+ pooled_output = sequence_output[:, 0, :] # Take CLS token representation
68
+ pooled_output = self.dropout(pooled_output)
69
+
70
+ valence = self.valence_head(pooled_output)
71
+ arousal = self.arousal_head(pooled_output)
72
+ dominance = self.dominance_head(pooled_output)
73
+
74
+ loss = None
75
+ if labels is not None:
76
+ # If labels are provided, calculate loss
77
+ # Assuming labels is a tensor of shape [batch_size, 3] with VAD values
78
+ loss_fct = torch.nn.MSELoss()
79
+ v_loss = loss_fct(valence.squeeze(), labels[:, 0])
80
+ a_loss = loss_fct(arousal.squeeze(), labels[:, 1])
81
+ d_loss = loss_fct(dominance.squeeze(), labels[:, 2])
82
+ loss = v_loss + a_loss + d_loss
83
+
84
+ if not return_dict:
85
+ output = (valence.squeeze(), arousal.squeeze(), dominance.squeeze()) + outputs[2:]
86
+ return ((loss,) + output) if loss is not None else output
87
+
88
+ return {
89
+ "loss": loss,
90
+ "valence": valence.squeeze(),
91
+ "arousal": arousal.squeeze(),
92
+ "dominance": dominance.squeeze(),
93
+ "hidden_states": outputs.hidden_states,
94
+ "attentions": outputs.attentions,
95
+ }
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5dbe9a2c1b047d6aa3ce9a844b17cb2afb89da179e48a25f5d7bae43738f481b
3
+ size 498674366
special_tokens_map.json ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<s>",
4
+ "lstrip": false,
5
+ "normalized": true,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "cls_token": {
10
+ "content": "<s>",
11
+ "lstrip": false,
12
+ "normalized": true,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "eos_token": {
17
+ "content": "</s>",
18
+ "lstrip": false,
19
+ "normalized": true,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "mask_token": {
24
+ "content": "<mask>",
25
+ "lstrip": true,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "pad_token": {
31
+ "content": "<pad>",
32
+ "lstrip": false,
33
+ "normalized": true,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ },
37
+ "sep_token": {
38
+ "content": "</s>",
39
+ "lstrip": false,
40
+ "normalized": true,
41
+ "rstrip": false,
42
+ "single_word": false
43
+ },
44
+ "unk_token": {
45
+ "content": "<unk>",
46
+ "lstrip": false,
47
+ "normalized": true,
48
+ "rstrip": false,
49
+ "single_word": false
50
+ }
51
+ }
tokenizer_config.json ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "unk_token": "<unk>"
57
+ }
vad_by_category.png ADDED

Git LFS Details

  • SHA256: 1ab2ab441633372abbf0d0f4d2287b08039d64760ff2d79bb12a1d39fb5641c4
  • Pointer size: 131 Bytes
  • Size of remote file: 165 kB
vad_distribution.png ADDED

Git LFS Details

  • SHA256: 5e6938c39fce678c267c7f887a5389ed8d71852261f6dadb627571f84b83445a
  • Pointer size: 131 Bytes
  • Size of remote file: 240 kB
vad_vs_casualties.png ADDED

Git LFS Details

  • SHA256: 21a46fa027a6b41a3f5f2c8ff1abf71b68c441169bd788aaa141cf25886f17c7
  • Pointer size: 131 Bytes
  • Size of remote file: 212 kB
vocab.json ADDED
The diff for this file is too large to render. See raw diff