def __init__(self, args): self.args = args self.batch_size = args.batch_size #self.batch_size = 1 self.finetune_topk = args.finetune_topk self.lr = args.lr self.use_cuda = (args.use_cuda == True) and torch.cuda.is_available() print('Use cuda:', self.use_cuda) if self.use_cuda: torch.cuda.set_device(int(args.gpu)) module = importlib.import_module(".".join([args.model_name])) MyModel = getattr(module, 'MyModel') self.network = MyModel(args) self.init_optimizer() if args.pretrained: print('Load pretrained model from %s...' % args.pretrained) self.load(args.pretrained) else: self.load_embeddings(vocab.tokens(), args.embedding_file) self.network.register_buffer( 'fixed_embedding', self.network.embedding.weight.data[self.finetune_topk:].clone()) if self.use_cuda: self.network.cuda() print(self.network) self._report_num_trainable_parameters()
def __init__(self, args): self.args = args self.batch_size = args.batch_size self.finetune_topk = args.finetune_topk self.lr = args.lr self.use_cuda = (args.use_cuda == True) and torch.cuda.is_available() print('Use cuda:', self.use_cuda) if self.use_cuda: torch.cuda.set_device(int(args.gpu)) self.network = TriAN(args) self.init_optimizer() # load pretrained model if args.pretrained: print('Load pretrained model from %s...' % args.pretrained) self.load(args.pretrained) else: if args.use_elmo == False: self.load_embeddings(vocab.tokens(), args.embedding_file) if args.use_elmo == False: self.network.register_buffer( 'fixed_embedding', self.network.embedding.weight.data[self.finetune_topk:].clone( )) self.elmo = None else: options_file = "https://s3-us-west-2.amazonaws.com/allennlp/models/elmo/2x4096_512_2048cnn_2xhighway/elmo_2x4096_512_2048cnn_2xhighway_options.json" weight_file = "https://s3-us-west-2.amazonaws.com/allennlp/models/elmo/2x4096_512_2048cnn_2xhighway/elmo_2x4096_512_2048cnn_2xhighway_weights.hdf5" self.elmo = ElmoEmbedder(options_file, weight_file, cuda_device=0) # self.elmo = Elmo(options_file, weight_file, num_output_representations=2, dropout=0, requires_grad=False) if self.use_cuda: self.network.cuda() print(self.network) self._report_num_trainable_parameters()
def __init__(self, args): self.args = args self.batch_size = args.batch_size self.finetune_topk = args.finetune_topk self.lr = args.lr #self.use_cuda = (args.use_cuda == True) and torch.cuda.is_available() #print('Use cuda:', self.use_cuda) #if self.use_cuda: # torch.cuda.set_device(int(args.gpu)) tf.reset_default_graph() self.sess = tf.Session() self.network = TriAN(args) self.init_optimizer() if args.pretrained: print('Load pretrained model from %s...' % args.pretrained) self.load(args.pretrained) else: self.word_emb_mat = self.load_embeddings(vocab.tokens(), args.embedding_file) self.sess.run(tf.global_variables_initializer()) self._report_num_trainable_parameters()
def __init__(self, args): self.args = args self.batch_size = args.batch_size self.finetune_topk = args.finetune_topk self.lr = args.lr self.use_cuda = (args.use_cuda == True) and torch.cuda.is_available() print('Use cuda:', self.use_cuda) if self.use_cuda: torch.cuda.set_device(int(args.gpu)) self.network = JointQA(args) self.init_optimizer() self.nli_loss_criterion = torch.nn.NLLLoss() if args.pretrained: print('Load pretrained model from %s...' % args.pretrained) self.load(args.pretrained) else: self.load_embeddings(vocab.tokens(), args.embedding_file) self.network.register_buffer('fixed_embedding', self.network.embedding.weight.data[self.finetune_topk:].clone()) if self.use_cuda: self.network.cuda() print(self.network) self._report_num_trainable_parameters()
def __init__(self, args): self.args = args self.batch_size = args.batch_size self.finetune_topk = args.finetune_topk self.lr = args.lr self.use_cuda = (args.use_cuda == True) and torch.cuda.is_available() print('Use cuda:', self.use_cuda) if self.use_cuda: torch.cuda.set_device(int(args.gpu)) # self.network = TriAN(args) # self.network = simpleModel(args) self.network = simpleModel(args) self.init_optimizer() # load pretrained model if args.pretrained: print('Load pretrained model from %s...' % args.pretrained) self.load(args.pretrained) else: if args.use_elmo == False: self.load_embeddings(vocab.tokens(), args.embedding_file) if args.use_elmo == False: self.network.register_buffer('fixed_embedding', self.network.embedding.weight.data[self.finetune_topk:].clone()) self.elmo = None else: options_file = "https://s3-us-west-2.amazonaws.com/allennlp/models/elmo/2x4096_512_2048cnn_2xhighway/elmo_2x4096_512_2048cnn_2xhighway_options.json" weight_file = "https://s3-us-west-2.amazonaws.com/allennlp/models/elmo/2x4096_512_2048cnn_2xhighway/elmo_2x4096_512_2048cnn_2xhighway_weights.hdf5" from allennlp.commands.elmo import ElmoEmbedder self.elmo = ElmoEmbedder(options_file, weight_file, cuda_device=0) if self.use_cuda: self.network.cuda() print(self.network) self._report_num_trainable_parameters() self.crit = torch.nn.BCEWithLogitsLoss(reduce=False, pos_weight=torch.FloatTensor([args.pos_weight]).cuda())