Я настроил две отдельные модели bert (bert-base-uncased) для анализа настроений и задач маркировки pos. Теперь я хочу использовать выходные данные тега pos (batch, seqlength, hiddensize) в качестве входных данных для модели настроений. конфигурации. json». Вот мой код:
class DeepSequentialModel(nn.Module):
def __init__(self, sentiment_model_file, postag_model_file, device):
super(DeepSequentialModel, self).__init__()
self.sentiment_model = SentimentModel().to(device)
self.sentiment_model.load_state_dict(torch.load(sentiment_model_file, map_location=device))
self.postag_model = PosTagModel().to(device)
self.postag_model.load_state_dict(torch.load(postag_model_file, map_location=device))
self.classificationLayer = nn.Linear(768, 1)
def forward(self, seq, attn_masks):
postag_context = self.postag_model(seq, attn_masks)
sent_context = self.sentiment_model(postag_context, attn_masks)
logits = self.classificationLayer(sent_context)
return logits
class PosTagModel(nn.Module):
def __init__(self,):
super(PosTagModel, self).__init__()
self.bert_layer = BertModel.from_pretrained('bertModel/')
self.classificationLayer = nn.Linear(768, 43)
def forward(self, seq, attn_masks):
cont_reps, _ = self.bert_layer(seq, attention_mask=attn_masks)
return cont_reps
class SentimentModel(nn.Module):
def __init__(self,):
super(SentimentModel, self).__init__()
self.bert_layer = BertModel.from_pretrained('bertModel/')
self.cls_layer = nn.Linear(768, 1)
def forward(self, input, attn_masks):
cont_reps, _ = self.bert_layer(encoder_hidden_states=input, encoder_attention_mask=attn_masks)
cls_rep = cont_reps[:, 0]
return cls_rep
Но я получаю ошибку ниже. Я ценю, если кто-то может мне помочь. Спасибо!
cont_reps, _ = self.bert_layer(encoder_hidden_states=input, encoder_attention_mask=attn_masks)
result = self.forward(*input, **kwargs)
TypeError: forward() got an unexpected keyword argument 'encoder_hidden_states'