forked from fhamborg/NewsMTSC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom_multi.py
More file actions
47 lines (36 loc) · 1.28 KB
/
Copy pathrandom_multi.py
File metadata and controls
47 lines (36 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from argparse import Namespace
from typing import Dict
import torch
import torch.nn as nn
from NewsSentiment.consts import *
from NewsSentiment.dataset import FXDataset
from NewsSentiment.models.FXBaseModel import FXBaseModel
class RandomMulti(FXBaseModel):
"""
"""
@staticmethod
def get_language_models():
"""
All architecture assumes that at least one model is used so we just require
bert here for compatibility.
:return:
"""
return (BERT_BASE_UNCASED,)
@staticmethod
def get_input_field_ids():
return [
(BERT_BASE_UNCASED, FIELD_TEXT_IDS_WITH_SPECIAL_TOKENS),
(BERT_BASE_UNCASED, FIELD_TEXT_IDS_WITH_SPECIAL_TOKENS_TARGET_MASK),
]
def __init__(self, transformer_models: Dict, opt: Namespace):
super(RandomMulti, self).__init__()
self.num_classes = opt.polarities_dim
def forward(self, inputs):
text_bert_indices = FXDataset.get_input_by_params(
inputs, BERT_BASE_UNCASED, FIELD_TEXT_IDS_WITH_SPECIAL_TOKENS
)
batch_size = text_bert_indices.shape[0]
num_targets = text_bert_indices.shape[1]
# get a random tensor
logits = torch.rand(batch_size, num_targets, self.num_classes)
return logits