import torch
from torch import nn

from transformers import BertModel


class BertModelForBinaryMultiLabelClassifier(nn.Module):
    def __init__(self, num_labels, pretrained_model_name_or_path=None):
        super(BertModelForBinaryMultiLabelClassifier, self).__init__()
        if pretrained_model_name_or_path:
            self.model = BertModel.from_pretrained(
                pretrained_model_name_or_path)
        else:
            raise NotImplementedError
        self.num_labels = num_labels
        self.dropout = nn.Dropout(0.2)
        self.classifier = nn.Linear(
            self.model.pooler.dense.out_features, num_labels)
        self.add_module('fc_output', self.classifier)

    def forward(self, input_ids=None, labels=None, attention_mask=None,
                token_type_ids=None, position_ids=None, head_mask=None,
                inputs_embeds=None, encoder_hidden_states=None,
                encoder_attention_mask=None):
        outputs = self.model(input_ids,
                             attention_mask=attention_mask,
                             token_type_ids=token_type_ids,
                             position_ids=position_ids,
                             head_mask=head_mask,
                             inputs_embeds=inputs_embeds,
                             encoder_hidden_states=encoder_hidden_states,
                             encoder_attention_mask=encoder_attention_mask)
        # pooled_output = outputs[1]
        pooled_output = torch.mean(outputs[0], dim=1)

        pooled_output = self.dropout(pooled_output)
        logits = self.classifier(pooled_output)

        # add hidden states and attention if they are here
        outputs = (logits,) + outputs[2:]

        return outputs  # logits, (hidden_states), (attentions)

    def resize_token_embeddings(self, token_num):
        self.model.resize_token_embeddings(token_num)

96e5fc49eb3ba7fd2ed37504b936d212d3a07b1b
<mask token>


class BertModelForBinaryMultiLabelClassifier(nn.Module):

    def __init__(self, num_labels, pretrained_model_name_or_path=None):
        super(BertModelForBinaryMultiLabelClassifier, self).__init__()
        if pretrained_model_name_or_path:
            self.model = BertModel.from_pretrained(
                pretrained_model_name_or_path)
        else:
            raise NotImplementedError
        self.num_labels = num_labels
        self.dropout = nn.Dropout(0.2)
        self.classifier = nn.Linear(self.model.pooler.dense.out_features,
            num_labels)
        self.add_module('fc_output', self.classifier)
    <mask token>
    <mask token>

<mask token>


class BertModelForBinaryMultiLabelClassifier(nn.Module):

    def __init__(self, num_labels, pretrained_model_name_or_path=None):
        super(BertModelForBinaryMultiLabelClassifier, self).__init__()
        if pretrained_model_name_or_path:
            self.model = BertModel.from_pretrained(
                pretrained_model_name_or_path)
        else:
            raise NotImplementedError
        self.num_labels = num_labels
        self.dropout = nn.Dropout(0.2)
        self.classifier = nn.Linear(self.model.pooler.dense.out_features,
            num_labels)
        self.add_module('fc_output', self.classifier)
    <mask token>

    def resize_token_embeddings(self, token_num):
        self.model.resize_token_embeddings(token_num)

<mask token>


class BertModelForBinaryMultiLabelClassifier(nn.Module):

    def __init__(self, num_labels, pretrained_model_name_or_path=None):
        super(BertModelForBinaryMultiLabelClassifier, self).__init__()
        if pretrained_model_name_or_path:
            self.model = BertModel.from_pretrained(
                pretrained_model_name_or_path)
        else:
            raise NotImplementedError
        self.num_labels = num_labels
        self.dropout = nn.Dropout(0.2)
        self.classifier = nn.Linear(self.model.pooler.dense.out_features,
            num_labels)
        self.add_module('fc_output', self.classifier)

    def forward(self, input_ids=None, labels=None, attention_mask=None,
        token_type_ids=None, position_ids=None, head_mask=None,
        inputs_embeds=None, encoder_hidden_states=None,
        encoder_attention_mask=None):
        outputs = self.model(input_ids, attention_mask=attention_mask,
            token_type_ids=token_type_ids, position_ids=position_ids,
            head_mask=head_mask, inputs_embeds=inputs_embeds,
            encoder_hidden_states=encoder_hidden_states,
            encoder_attention_mask=encoder_attention_mask)
        pooled_output = torch.mean(outputs[0], dim=1)
        pooled_output = self.dropout(pooled_output)
        logits = self.classifier(pooled_output)
        outputs = (logits,) + outputs[2:]
        return outputs

    def resize_token_embeddings(self, token_num):
        self.model.resize_token_embeddings(token_num)

import torch
from torch import nn
from transformers import BertModel


class BertModelForBinaryMultiLabelClassifier(nn.Module):

    def __init__(self, num_labels, pretrained_model_name_or_path=None):
        super(BertModelForBinaryMultiLabelClassifier, self).__init__()
        if pretrained_model_name_or_path:
            self.model = BertModel.from_pretrained(
                pretrained_model_name_or_path)
        else:
            raise NotImplementedError
        self.num_labels = num_labels
        self.dropout = nn.Dropout(0.2)
        self.classifier = nn.Linear(self.model.pooler.dense.out_features,
            num_labels)
        self.add_module('fc_output', self.classifier)

    def forward(self, input_ids=None, labels=None, attention_mask=None,
        token_type_ids=None, position_ids=None, head_mask=None,
        inputs_embeds=None, encoder_hidden_states=None,
        encoder_attention_mask=None):
        outputs = self.model(input_ids, attention_mask=attention_mask,
            token_type_ids=token_type_ids, position_ids=position_ids,
            head_mask=head_mask, inputs_embeds=inputs_embeds,
            encoder_hidden_states=encoder_hidden_states,
            encoder_attention_mask=encoder_attention_mask)
        pooled_output = torch.mean(outputs[0], dim=1)
        pooled_output = self.dropout(pooled_output)
        logits = self.classifier(pooled_output)
        outputs = (logits,) + outputs[2:]
        return outputs

    def resize_token_embeddings(self, token_num):
        self.model.resize_token_embeddings(token_num)

import torch
from torch import nn

from transformers import BertModel


class BertModelForBinaryMultiLabelClassifier(nn.Module):
    def __init__(self, num_labels, pretrained_model_name_or_path=None):
        super(BertModelForBinaryMultiLabelClassifier, self).__init__()
        if pretrained_model_name_or_path:
            self.model = BertModel.from_pretrained(
                pretrained_model_name_or_path)
        else:
            raise NotImplementedError
        self.num_labels = num_labels
        self.dropout = nn.Dropout(0.2)
        self.classifier = nn.Linear(
            self.model.pooler.dense.out_features, num_labels)
        self.add_module('fc_output', self.classifier)

    def forward(self, input_ids=None, labels=None, attention_mask=None,
                token_type_ids=None, position_ids=None, head_mask=None,
                inputs_embeds=None, encoder_hidden_states=None,
                encoder_attention_mask=None):
        outputs = self.model(input_ids,
                             attention_mask=attention_mask,
                             token_type_ids=token_type_ids,
                             position_ids=position_ids,
                             head_mask=head_mask,
                             inputs_embeds=inputs_embeds,
                             encoder_hidden_states=encoder_hidden_states,
                             encoder_attention_mask=encoder_attention_mask)
        # pooled_output = outputs[1]
        pooled_output = torch.mean(outputs[0], dim=1)

        pooled_output = self.dropout(pooled_output)
        logits = self.classifier(pooled_output)

        # add hidden states and attention if they are here
        outputs = (logits,) + outputs[2:]

        return outputs  # logits, (hidden_states), (attentions)

    def resize_token_embeddings(self, token_num):
        self.model.resize_token_embeddings(token_num)
