text: import tensorflow as tf
  
  import torch
  
  device = torch.device("cuda")
  
  sentences = data.summary.values
  labels = data.hrsactual.values
  
  from transformers import BertTokenizer
  
  tokenizer = BertTokenizer.from_pretrained('bert-base-uncased', do_lower_case=True)
  
  max_len = 0
  
  for sent in sentences:
      input_ids = tokenizer.encode(sent, add_special_tokens=True)
      max_len = max(max_len, len(input_ids))
  
  input_ids = []
  attention_masks = []
  
  for sent in sentences:
      encoded_dict = tokenizer.encode_plus(
                          sent,                    
                          add_special_tokens = True, 
                          max_length = 64,          
                          pad_to_max_length = True,
                          return_attention_mask = True,   
                          return_tensors = 'pt',    
                     )
        
      input_ids.append(encoded_dict['input_ids'])
      attention_masks.append(encoded_dict['attention_mask'])
  
  input_ids = torch.cat(input_ids, dim=0)
  attention_masks = torch.cat(attention_masks, dim=0)
  labels = torch.tensor(labels)
  
  from torch.utils.data import TensorDataset, random_split
  
  dataset = TensorDataset(input_ids, attention_masks, labels)
  train_size = int(0.9 * len(dataset))
  val_size = len(dataset) - train_size
  train_dataset, val_dataset = random_split(dataset, [train_size, val_size])
  from torch.utils.data import DataLoader, RandomSampler, SequentialSampler
  batch_size = 32
  
  train_dataloader = DataLoader(
              train_dataset, 
              sampler = RandomSampler(train_dataset), 
              batch_size = batch_size 
          )
  
  validation_dataloader = DataLoader(
              val_dataset,
              sampler = SequentialSampler(val_dataset), 
              batch_size = batch_size 
          )
  
  from transformers import BertForSequenceClassification, AdamW, BertConfig
  
  model = BertForSequenceClassification.from_pretrained(
      "bert-base-uncased", 
      num_labels = 3, # kai kuriais atvejais 4 
      output_attentions = False,
      output_hidden_states = False,
  )
  
  model.cuda()
  
  params = list(model.named_parameters())
  
  
  for p in params[0:5]:
      print("{:<55} {:>12}".format(p[0], str(tuple(p[1].size()))))
  
  
  for p in params[5:21]:
      print("{:<55} {:>12}".format(p[0], str(tuple(p[1].size()))))
  
  
  for p in params[-4:]:
      print("{:<55} {:>12}".format(p[0], str(tuple(p[1].size()))))
  
  optimizer = AdamW(model.parameters(),
                    lr = 2e-5, 
                    eps = 1e-8 
                  )
  
  from transformers import get_linear_schedule_with_warmup
  
  epochs = 4
  
  total_steps = len(train_dataloader) * epochs
  
  scheduler = get_linear_schedule_with_warmup(optimizer, 
                                              num_warmup_steps = 0,
                                              num_training_steps = total_steps)
  
  import numpy as np
  
  def flat_accuracy(preds, labels):
      pred_flat = np.argmax(preds, axis=1).flatten()
      labels_flat = labels.flatten()
      return np.sum(pred_flat == labels_flat) / len(labels_flat)
  
  import time
  import datetime
  
  def format_time(elapsed):
      elapsed_rounded = int(round((elapsed)))
      return str(datetime.timedelta(seconds=elapsed_rounded))
  
  import random
  import numpy as np
  
  seed_val = 42
  
  random.seed(seed_val)
  np.random.seed(seed_val)
  torch.manual_seed(seed_val)
  torch.cuda.manual_seed_all(seed_val)
  
  training_stats = []
  total_t0 = time.time()
  
  for epoch_i in range(0, epochs):
      t0 = time.time()
      total_train_loss = 0
      model.train()
      for step, batch in enumerate(train_dataloader):
          if step % 40 == 0 and not step == 0:
              elapsed = format_time(time.time() - t0)
          b_input_ids = batch[0].to(device)
          b_input_mask = batch[1].to(device)
          b_labels = batch[2].to(device)
          model.zero_grad()        
          loss, logits = model(b_input_ids, 
                               token_type_ids=None, 
                               attention_mask=b_input_mask, 
                               labels=b_labels)
          total_train_loss += loss.item()
          loss.backward()
          torch.nn.utils.clip_grad_norm_(model.parameters(), 1.0)
          optimizer.step()
          scheduler.step()
  
      avg_train_loss = total_train_loss / len(train_dataloader)            
      training_time = format_time(time.time() - t0)
  
      print("")
      print("  Average training loss: {0:.2f}".format(avg_train_loss))
      print("  Training epcoh took: {:}".format(training_time))
  
      t0 = time.time()
  
      model.eval()
  
      total_eval_accuracy = 0
      total_eval_loss = 0
      nb_eval_steps = 0
  
      for batch in validation_dataloader:
          b_input_ids = batch[0].to(device)
          b_input_mask = batch[1].to(device)
          b_labels = batch[2].to(device)
          with torch.no_grad():       
              (loss, logits) = model(b_input_ids, 
                                     token_type_ids=None, 
                                     attention_mask=b_input_mask,
                                     labels=b_labels)
          total_eval_loss += loss.item()
          logits = logits.detach().cpu().numpy()
          label_ids = b_labels.to('cpu').numpy()
          total_eval_accuracy += flat_accuracy(logits, label_ids)
          
      avg_val_accuracy = total_eval_accuracy / len(validation_dataloader)
      print("  Accuracy: {0:.2f}".format(avg_val_accuracy))
  
      avg_val_loss = total_eval_loss / len(validation_dataloader)
      validation_time = format_time(time.time() - t0)
      
      print("  Validation Loss: {0:.2f}".format(avg_val_loss))
      print("  Validation took: {:}".format(validation_time))
  
      training_stats.append(
          {
              'epoch': epoch_i + 1,
              'Training Loss': avg_train_loss,
              'Valid. Loss': avg_val_loss,
              'Valid. Accur.': avg_val_accuracy,
              'Training Time': training_time,
              'Validation Time': validation_time
          }
      )