def __init__(self, config, gpu_list, *args, **params): super(DEC, self).__init__() self.sentence_encoder = LSTMEncoder(config, gpu_list, *args, **params) self.document_encoder = LSTMEncoder(config, gpu_list, *args, **params) self.sentence_attention = Attention(config, gpu_list, *args, **params) self.document_attention = Attention(config, gpu_list, *args, **params)
def __init__(self, config, gpu_list, *args, **params): super(Model, self).__init__() self.hidden_size = config.getint("model", "hidden_size") self.word_num = 0 f = open(config.get("data", "word2id"), "r", encoding="utf8") for line in f: self.word_num += 1 self.embedding = nn.Embedding(self.word_num, self.hidden_size) self.context_encoder = LSTMEncoder(config, gpu_list, *args, **params) self.question_encoder = LSTMEncoder(config, gpu_list, *args, **params) # self.attention = Attention(config, gpu_list, *args, **params) self.resnet = resnet50(pretrained=True) # self.seresnet = seresnet50(pretrained=True) # self.densenet = densenet121(pretrained=True) self.res_module = nn.Linear(1000, 16) self.fc_module = nn.Linear(16 + 1, 4) self.criterion = nn.CrossEntropyLoss() self.dropout = nn.Dropout(config.getfloat("model", "dropout")) self.softmax = nn.Softmax(dim=1) # self.rouge_module = nn.Linear(1000, 4) self.accuracy_function = single_label_top1_accuracy
def __init__(self, config, gpu_list, *args, **params): super(CAPSModel, self).__init__() self.hidden_size = config.getint("model", "hidden_size") self.word_num = 0 f = open(config.get("data", "word2id"), "r", encoding="utf8") for line in f: self.word_num += 1 self.embedding = nn.Embedding(self.word_num, self.hidden_size) self.context_encoder = LSTMEncoder(config, gpu_list, *args, **params) self.question_encoder = LSTMEncoder(config, gpu_list, *args, **params) self.attention = Attention(config, gpu_list, *args, **params) self.num_classes = 4 # self.conv_channel = config.getint("data", "max_question_len") + config.getint("data", "max_option_len") self.dim_capsule = config.getint("model", "dim_capsule") self.num_compressed_capsule = config.getint("model", "num_compressed_capsule") self.ngram_size = [2, 4, 8] self.convs_doc = nn.ModuleList([ nn.Conv1d(self.hidden_size, 32, K, stride=2) for K in self.ngram_size ]) torch.nn.init.xavier_uniform_(self.convs_doc[0].weight) torch.nn.init.xavier_uniform_(self.convs_doc[1].weight) torch.nn.init.xavier_uniform_(self.convs_doc[2].weight) self.primary_capsules_doc = PrimaryCaps(num_capsules=self.dim_capsule, in_channels=32, out_channels=32, kernel_size=1, stride=1) self.flatten_capsules = FlattenCaps() self.W_doc = nn.Parameter( torch.FloatTensor(49024, self.num_compressed_capsule)) torch.nn.init.xavier_uniform_(self.W_doc) self.fc_capsules_doc_child = FCCaps( config, output_capsule_num=self.num_classes, input_capsule_num=self.num_compressed_capsule, in_channels=self.dim_capsule, out_channels=self.dim_capsule) # self.rank_module = nn.Linear(hidden_size, 1) # self.criterion = nn.CrossEntropyLoss() self.bce = nn.BCELoss(reduction='mean') self.fc_module = nn.Linear(self.dim_capsule, self.num_classes) self.accuracy_function = multi_label_top1_accuracy
def __init__(self, config, gpu_list, *args, **params): super(Model, self).__init__() self.hidden_size = config.getint("model", "hidden_size") self.word_num = 0 f = open(config.get("data", "word2id"), "r", encoding="utf8") for line in f: self.word_num += 1 self.embedding = nn.Embedding(self.word_num, self.hidden_size) self.context_encoder = LSTMEncoder(config, gpu_list, *args, **params) self.question_encoder = LSTMEncoder(config, gpu_list, *args, **params) self.attention = Attention(config, gpu_list, *args, **params) self.rank_module = nn.Linear(self.hidden_size * 2, 1) self.criterion = nn.CrossEntropyLoss() self.multi_module = nn.Linear(4, 16) self.accuracy_function = single_label_top1_accuracy
def __init__(self, config, gpu_list, *args, **params): super(ModelS, self).__init__() self.hidden_size = config.getint("model", "hidden_size") self.word_num = 0 f = open(config.get("data", "word2id"), "r", encoding="utf8") for line in f: self.word_num += 1 self.context_len = config.getint("data", "max_option_len") * 4 self.question_len = config.getint("data", "max_question_len") self.embedding = nn.Embedding(self.word_num, self.hidden_size) self.context_encoder = LSTMEncoder(config, gpu_list, *args, **params) self.question_encoder = LSTMEncoder(config, gpu_list, *args, **params) self.attention = Attention(config, gpu_list, *args, **params) self.dropout = nn.Dropout(config.getfloat("model", "dropout")) self.bce = nn.MultiLabelSoftMarginLoss(reduction='sum') self.gelu = nn.GELU() # self.fc_module_q = nn.Linear(self.question_len, 1) self.fc_module = nn.Linear(self.hidden_size * 2, 4) self.accuracy_function = multi_label_top1_accuracy
def __init__(self, config, gpu_list, *args, **params): super(BiDAF, self).__init__() self.hidden_size = config.getint("model", "hidden_size") self.embedding = nn.Embedding( len(json.load(open(config.get("data", "word2id")))), config.getint("model", "hidden_size")) self.encoder = LSTMEncoder(config, gpu_list, *args, **params) self.attention = Attention(config, gpu_list, *args, **params) self.fc = nn.Linear(self.hidden_size * 2, 1) self.criterion = cross_entropy_loss self.accuracy_function = single_label_top1_accuracy