text: from transformers import BertTokenizer
  
  #########1. fine-tuning#########
  ###define input token ids and labels
  tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
  text_batch = ["I love Pixar.", "I don't care for Pixar."]
  encoding = tokenizer(text_batch, return_tensors='pt', padding=True, truncation=True)
  input_ids = encoding['input_ids']
  attention_mask = encoding['attention_mask']
  labels = torch.tensor([1,0]).unsqueeze(0)
  
  ###define the model
  from transformers import BertForSequenceClassification
  model = BertForSequenceClassification.from_pretrained('bert-base-uncased', return_dict=True)
  model.train()
  
  #freeze some parameters
  for param in model.base_model.parameters():
      param.requires_grad = False
  
  ###define the optimizer
  from transformers import AdamW
  no_decay = ['bias', 'LayerNorm.weight']
  optimizer_grouped_parameters = [
      {'params': [p for n, p in model.named_parameters() if not any(nd in n for nd in no_decay)], 'weight_decay': 0.01},
      {'params': [p for n, p in model.named_parameters() if any(nd in n for nd in no_decay)], 'weight_decay': 0.0}
  ]
  optimizer = AdamW(optimizer_grouped_parameters, lr=1e-5)
  
  ###to train
  outputs = model(input_ids, attention_mask=attention_mask, labels=labels)
  
  #provide a few learning rate scheduling tools
  from transformers import get_linear_schedule_with_warmup
  scheduler = get_linear_schedule_with_warmup(optimizer, num_warmup_steps, num_train_steps)
  
  loss = outputs.loss
  loss.backward()
  optimizer.step()
  scheduler.step()
  
  ###to compute loss
  from torch.nn import functional as F
  labels = torch.tensor([1,0]).unsqueeze(0)
  outputs = model(input_ids, attention_mask=attention_mask)
  loss = F.cross_entropy(labels, outputs.logitd)
  loss.backward()
  optimizer.step()
  
  
  #########2. Trainer#########
  from transformers import BertForSequenceClassification, Trainer, TrainingArguments
  
  model = BertForSequenceClassification.from_pretrained("bert-large-uncased")
  
  training_args = TrainingArguments(
      output_dir='./results',          # output directory
      num_train_epochs=3,              # total # of training epochs
      per_device_train_batch_size=16,  # batch size per device during training
      per_device_eval_batch_size=64,   # batch size for evaluation
      warmup_steps=500,                # number of warmup steps for learning rate scheduler
      weight_decay=0.01,               # strength of weight decay
      logging_dir='./logs',            # directory for storing logs
  )
  
  trainer = Trainer(
      model=model,                         # the instantiated 🤗 Transformers model to be trained
      args=training_args,                  # training arguments, defined above
      train_dataset=train_dataset,         # training dataset
      eval_dataset=test_dataset            # evaluation dataset
  )
  
  from sklearn.metrics import accuracy_score, precision_recall_fscore_support
  
  def compute_metrics(pred):
      labels = pred.label_ids
      preds = pred.predictions.argmax(-1)
      precision, recall, f1, _ = precision_recall_fscore_support(labels, preds, average='binary')
      acc = accuracy_score(labels, preds)
      return {
          'accuracy': acc,
          'f1': f1,
          'precision': precision,
          'recall': recall
      }