code: def __init__(
      self,
      model,
      train_path,
      val_path,
      test_path,
      ckpt,
      batch_size=32,
      max_epoch=100,
      lr=0.1,
      weight_decay=1e-5,
      warmup_step=300,
      opt="sgd",
  ):
      super().__init__()
      self.max_epoch = max_epoch
      # Load data
      if train_path != None:
          self.train_loader = SentenceRELoader(
              train_path,
              model.rel2id,
              model.sentence_encoder.tokenize,
              batch_size,
              True,
          )
  
      if val_path != None:
          self.val_loader = SentenceRELoader(
              val_path,
              model.rel2id,
              model.sentence_encoder.tokenize,
              batch_size,
              False,
          )
  
      if test_path != None:
          self.test_loader = SentenceRELoader(
              test_path,
              model.rel2id,
              model.sentence_encoder.tokenize,
              batch_size,
              False,
          )
      # Model
      self.model = model
      self.parallel_model = nn.DataParallel(self.model)
      # Criterion
      self.criterion = nn.CrossEntropyLoss()
      # Params and optimizer
      params = self.parameters()
      self.lr = lr
      if opt == "sgd":
          self.optimizer = optim.SGD(
              params, lr, weight_decay=weight_decay
          )
      elif opt == "adam":
          self.optimizer = optim.Adam(
              params, lr, weight_decay=weight_decay
          )
      elif opt == "adamw":  # Optimizer for BERT
          from transformers import AdamW
  
          params = list(self.named_parameters())
          no_decay = ["bias", "LayerNorm.bias", "LayerNorm.weight"]
          grouped_params = [
              {
                  "params": [
                      p
                      for n, p in params
                      if not any(nd in n for nd in no_decay)
                  ],
                  "weight_decay": 0.01,
                  "lr": lr,
                  "ori_lr": lr,
              },
              {
                  "params": [
                      p
                      for n, p in params
                      if any(nd in n for nd in no_decay)
                  ],
                  "weight_decay": 0.0,
                  "lr": lr,
                  "ori_lr": lr,
              },
          ]
          self.optimizer = AdamW(grouped_params, correct_bias=False)
      else:
          raise Exception(
              "Invalid optimizer. Must be 'sgd' or 'adam' or 'adamw'."
          )
      # Warmup
      if warmup_step > 0:
          from transformers import get_linear_schedule_with_warmup
  
          training_steps = (
              self.train_loader.dataset.__len__()
              // batch_size
              * self.max_epoch
          )
          self.scheduler = get_linear_schedule_with_warmup(
              self.optimizer,
              num_warmup_steps=warmup_step,
              num_training_steps=training_steps,
          )
      else:
          self.scheduler = None
      # Cuda
      if torch.cuda.is_available():
          self.cuda()
      # Ckpt
      self.ckpt = ckpt
  
file_path: OpenNRE/opennre/framework/sentence_re.py
imports: import os, logging, json
  from tqdm import tqdm
  import torch
  from torch import nn, optim
  from .data_loader import SentenceRELoader
  from .utils import AverageMeter
label_desc: Use image node_id 1 to create a new SentenceRE object from inherited base classes: nn with example: obj = SentenceRE(model, train_path, val_path, test_path, ckpt, batch_size, max_epoch, lr, weight_decay, warmup_step, opt)