BERT总是预测同一类别(微调)

我在一个金融新闻数据集上对BERT进行微调。不幸的是,BERT似乎陷入了局部最小值。它满足于总是预测同一类别。

  • 平衡数据集不起作用
  • 调整参数也同样不起作用

老实说,我不确定是什么导致了这个问题。使用simpletransformers库时,我得到了非常好的结果。如果有人能帮我,我将非常感激。非常感谢!

完整代码在GitHub上:https://github.com/Bene939/BERT_News_Sentiment_Classifier

代码:

from transformers import BertForSequenceClassification, AdamW, BertTokenizer, get_linear_schedule_with_warmup, Trainer, TrainingArgumentsimport torchfrom torch.utils.data import DataLoader, RandomSampler, SequentialSampler, TensorDatasetimport pandas as pdfrom pathlib import Pathimport sklearnfrom sklearn.model_selection import train_test_splitfrom sklearn.metrics import accuracy_score, precision_recall_fscore_supportimport numpy as npfrom torch.nn import functional as Ffrom collections import defaultdictimport random#defining tokenizer, model and optimizertokenizer = BertTokenizer.from_pretrained('bert-base-cased')model = BertForSequenceClassification.from_pretrained('bert-base-cased', num_labels=3)if torch.cuda.is_available():  print("\nUsing: ", torch.cuda.get_device_name(0))  device = torch.device('cuda')else:  print("\nUsing: CPU")  device = torch.device('cpu')model = model.to(device)#loading datasetlabeled_dataset = "news_headlines_sentiment.csv"labeled_dataset_file = Path(labeled_dataset)file_loaded = Falsewhile not file_loaded:  if labeled_dataset_file.exists():    labeled_dataset = pd.read_csv(labeled_dataset_file)    file_loaded = True    print("Dataset Loaded")  else:    print("File not Found")print(labeled_dataset)#counting sentimentsnegative = 0neutral = 0positive = 0for idx, row in labeled_dataset.iterrows():  if row["sentiment"] == 0:    negative += 1  elif row["sentiment"] == 1:    neutral += 1  else:    positive += 1print("Unbalanced Dataset")print("negative: ", negative)print("neutral: ", neutral)print("positive: ", positive)#balancing dataset to 1/3 per sentimentfor idx, row in labeled_dataset.iterrows():  if row["sentiment"] == 0:    if negative - neutral != 0:      index_name = labeled_dataset[labeled_dataset["news"] == row["news"]].index      labeled_dataset.drop(index_name, inplace=True)      negative -= 1  elif row["sentiment"] == 2:    if positive - neutral != 0:      index_name = labeled_dataset[labeled_dataset["news"] == row["news"]].index      labeled_dataset.drop(index_name, inplace=True)      positive -= 1#custom dataset classclass NewsSentimentDataset(torch.utils.data.Dataset):  def __init__(self, encodings, labels):        self.encodings = encodings        self.labels = labels  def __getitem__(self, idx):      item = {key: torch.tensor(val[idx]) for key, val in self.encodings.items()}      item['labels'] = torch.tensor(self.labels[idx])      return item  def __len__(self):      return len(self.labels)#method for tokenizing dataset listdef tokenize_headlines(headlines, labels, tokenizer):  encodings = tokenizer.batch_encode_plus(      headlines,      add_special_tokens = True,      truncation = True,      padding = 'max_length',      return_attention_mask = True,      return_token_type_ids = True  )  dataset = NewsSentimentDataset(encodings, labels)  return dataset#splitting dataset into training and validation set#load news sentiment datasetall_headlines = labeled_dataset['news'].tolist()all_labels = labeled_dataset['sentiment'].tolist()train_headlines, val_headlines, train_labels, val_labels = train_test_split(all_headlines, all_labels, test_size=.2)val_dataset = tokenize_headlines(val_headlines, val_labels, tokenizer)train_dataset = tokenize_headlines(train_headlines, val_labels, tokenizer)#data loadertrain_batch_size = 8val_batch_size = 8train_data_loader = DataLoader(train_dataset, batch_size = train_batch_size, shuffle=True)val_data_loader = DataLoader(val_dataset, batch_size = val_batch_size, sampler=SequentialSampler(val_dataset))#optimizer and schedulernum_epochs = 1num_steps = len(train_data_loader) * num_epochsoptimizer = AdamW(model.parameters(), lr=5e-5, eps=1e-8)scheduler = get_linear_schedule_with_warmup(optimizer, num_warmup_steps=num_steps*0.06, num_training_steps=num_steps)#training and evaluationseed_val = 64random.seed(seed_val)np.random.seed(seed_val)torch.manual_seed(seed_val)torch.cuda.manual_seed_all(seed_val)for epoch in range(num_epochs):  print("\n###################################################")  print("Epoch: {}/{}".format(epoch+1, num_epochs))  print("###################################################\n")  #training phase   average_train_loss = 0  average_train_acc = 0  model.train()   for step, batch in enumerate(train_data_loader):                  input_ids = batch['input_ids'].to(device)      attention_mask = batch['attention_mask'].to(device)      labels = batch['labels'].to(device)      token_type_ids = batch['token_type_ids'].to(device)      outputs = model(input_ids=input_ids, attention_mask=attention_mask, token_type_ids = token_type_ids)      loss = F.cross_entropy(outputs[0], labels)      average_train_loss += loss      if step % 40 == 0:        print("Training Loss: ", loss)      logits = outputs[0].detach().cpu().numpy()      label_ids = labels.to('cpu').numpy()      average_train_acc += sklearn.metrics.accuracy_score(label_ids, np.argmax(logits, axis=1))      print("predictions: ",np.argmax(logits, axis=1))      print("labels:      ",label_ids)      print("#############")      optimizer.zero_grad()      loss.backward()      #maximum gradient clipping      torch.nn.utils.clip_grad_norm_(model.parameters(), 1.0)            optimizer.step()      scheduler.step()      model.zero_grad()  average_train_loss = average_train_loss / len(train_data_loader)  average_train_acc = average_train_acc / len(train_data_loader)  print("======Average Training Loss: {:.5f}======".format(average_train_loss))  print("======Average Training Accuracy: {:.2f}%======".format(average_train_acc*100))  #validation phase  average_val_loss = 0  average_val_acc = 0  model.eval()  for step,batch in enumerate(val_data_loader):    input_ids = batch['input_ids'].to(device)    attention_mask = batch['attention_mask'].to(device)    labels = batch['labels'].to(device)    token_type_ids = batch['token_type_ids'].to(device)    pred = []    with torch.no_grad():            outputs = model(input_ids=input_ids, attention_mask=attention_mask, token_type_ids=token_type_ids)      loss = F.cross_entropy(outputs[0], labels)      average_val_loss += loss      logits = outputs[0].detach().cpu().numpy()      label_ids = labels.to('cpu').numpy()      print("predictions: ",np.argmax(logits, axis=1))      print("labels:      ",label_ids)      print("#############")      average_val_acc += sklearn.metrics.accuracy_score(label_ids, np.argmax(logits, axis=1))  average_val_loss = average_val_loss / len(val_data_loader)  average_val_acc = average_val_acc / len(val_data_loader)  print("======Average Validation Loss: {:.5f}======".format(average_val_loss))  print("======Average Validation Accuracy: {:.2f}%======".format(average_val_acc*100))###################################################Epoch: 1/1###################################################Training Loss:  tensor(1.1006, device='cuda:0', grad_fn=<NllLossBackward>)predictions:  [1 0 2 0 0 0 2 0]labels:       [2 0 1 1 0 1 0 1]#############predictions:  [2 2 0 0 0 2 0 0]labels:       [1 2 1 0 2 0 1 2]#############predictions:  [0 0 0 0 1 0 0 1]labels:       [0 1 1 0 1 1 2 0]#############predictions:  [0 0 0 2 0 1 0 0]labels:       [0 0 0 2 0 0 2 1]#############predictions:  [1 0 0 0 0 0 2 0]labels:       [0 2 2 1 0 0 0 0]#############predictions:  [0 0 0 0 0 1 0 0]labels:       [1 0 2 2 2 1 1 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 2 2 2 2 0 2 0]#############predictions:  [0 1 0 0 0 0 0 0]labels:       [2 2 0 2 0 0 0 1]#############predictions:  [0 0 0 0 0 2 0 1]labels:       [0 1 0 2 2 0 1 2]#############predictions:  [0 0 2 0 0 0 1 0]labels:       [0 0 0 1 2 1 1 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 2 1 0 1 0 1 1]#############predictions:  [0 2 0 0 0 0 0 0]labels:       [2 2 0 1 0 1 2 1]#############predictions:  [0 1 0 0 0 0 1 2]labels:       [2 2 1 0 2 0 0 2]#############predictions:  [0 0 1 1 1 1 0 1]labels:       [1 2 1 1 1 1 2 2]#############predictions:  [1 0 0 0 0 1 2 1]labels:       [1 0 1 1 0 0 0 2]#############predictions:  [0 1 1 1 1 0 2 1]labels:       [2 2 1 2 2 1 1 2]#############predictions:  [0 0 1 0 1 1 0 0]labels:       [1 0 0 1 0 1 0 2]#############predictions:  [1 2 0 0 1 2 0 0]labels:       [0 2 2 1 2 0 1 0]#############predictions:  [0 2 1 1 0 1 1 0]labels:       [2 2 0 1 1 0 1 2]#############predictions:  [1 0 1 1 1 1 1 0]labels:       [0 2 0 1 0 1 2 2]#############predictions:  [0 2 1 2 0 0 1 1]labels:       [2 1 1 1 1 2 2 0]#############predictions:  [0 1 2 2 2 1 1 2]labels:       [2 2 1 1 2 1 0 1]#############predictions:  [2 2 2 1 2 1 1 1]labels:       [0 1 1 0 0 2 2 1]#############predictions:  [1 2 2 2 1 2 1 2]labels:       [0 0 0 0 2 0 1 2]#############predictions:  [2 1 1 1 2 2 2 2]labels:       [1 0 2 2 1 0 0 0]#############predictions:  [2 1 2 2 2 1 2 2]labels:       [2 1 1 1 1 1 2 2]#############predictions:  [1 1 0 2 1 2 1 2]labels:       [2 2 0 2 0 1 2 0]#############predictions:  [0 1 1 2 0 1 2 1]labels:       [2 2 2 1 2 2 0 1]#############predictions:  [2 1 1 1 1 2 1 1]labels:       [0 1 1 2 1 0 0 2]#############predictions:  [1 2 2 0 1 1 1 2]labels:       [0 1 2 1 2 1 0 1]#############predictions:  [0 1 1 1 1 1 1 0]labels:       [0 2 0 1 1 2 2 2]#############predictions:  [1 2 1 1 2 1 1 0]labels:       [0 2 2 2 0 0 1 0]#############predictions:  [2 2 2 1 2 1 1 2]labels:       [2 2 1 2 1 0 0 0]#############predictions:  [2 2 1 2 2 2 1 2]labels:       [1 1 2 2 2 0 2 1]#############predictions:  [2 2 2 2 2 0 2 2]labels:       [2 2 1 2 0 1 1 2]#############predictions:  [1 1 2 1 2 2 0 1]labels:       [2 1 1 1 0 0 2 2]#############predictions:  [2 1 2 2 2 2 1 0]labels:       [0 2 0 2 0 0 0 0]#############predictions:  [2 2 2 2 2 2 2 2]labels:       [1 1 0 2 0 1 2 1]#############predictions:  [2 2 2 2 1 2 2 2]labels:       [1 0 0 1 1 0 0 0]#############predictions:  [2 2 2 1 2 2 2 2]labels:       [1 0 1 1 0 2 2 0]#############Training Loss:  tensor(1.1104, device='cuda:0', grad_fn=<NllLossBackward>)predictions:  [2 0 1 2 1 2 2 0]labels:       [2 2 0 0 1 0 0 2]#############predictions:  [0 2 2 0 2 1 1 1]labels:       [0 0 0 1 0 0 1 0]#############predictions:  [0 2 2 0 1 1 1 2]labels:       [2 1 1 1 2 2 1 0]#############predictions:  [2 1 1 2 2 0 2 0]labels:       [1 2 1 2 1 0 2 1]#############predictions:  [0 2 2 0 0 2 1 2]labels:       [0 0 2 2 0 0 2 0]#############predictions:  [0 0 1 2 2 0 2 2]labels:       [0 0 0 0 0 0 0 0]#############predictions:  [1 1 2 1 2 0 1 2]labels:       [0 0 2 0 0 0 1 1]#############predictions:  [0 0 2 1 0 2 0 1]labels:       [1 1 2 1 1 0 2 0]#############predictions:  [0 0 0 0 1 0 0 0]labels:       [2 2 1 1 2 1 1 1]#############predictions:  [0 0 0 0 1 0 0 0]labels:       [1 1 2 2 1 1 2 0]#############predictions:  [0 0 0 0 0 1 1 1]labels:       [2 0 1 1 0 1 2 2]#############predictions:  [0 0 1 0 0 1 2 1]labels:       [1 2 0 2 2 0 2 1]#############predictions:  [1 1 1 1 0 1 0 1]labels:       [2 0 1 0 1 0 1 2]#############predictions:  [1 2 2 0 0 0 1 1]labels:       [2 0 0 2 1 2 2 2]#############predictions:  [1 0 2 1 0 2 2 0]labels:       [0 0 2 1 2 1 1 1]#############predictions:  [0 0 0 1 1 1 1 1]labels:       [1 2 1 0 0 0 1 0]#############predictions:  [1 1 1 0 1 1 0 1]labels:       [0 2 1 2 1 2 2 0]#############predictions:  [2 1 0 1 1 2 0 0]labels:       [0 1 0 0 1 2 0 2]#############predictions:  [0 1 1 0 0 1 0 1]labels:       [1 0 0 2 2 1 1 2]#############predictions:  [1 1 1 1 1 1 1 1]labels:       [2 0 1 0 2 0 0 2]#############predictions:  [1 0 0 1 0 1 0 2]labels:       [1 0 0 1 1 2 2 1]#############predictions:  [1 1 1 1 1 1 0 0]labels:       [1 1 0 2 1 0 2 0]#############predictions:  [1 1 2 1 0 1 0 0]labels:       [0 2 1 2 1 1 0 2]#############predictions:  [1 1 0 0 1 2 1 1]labels:       [0 2 1 0 2 2 0 1]#############predictions:  [0 1 1 0 0 1 0 1]labels:       [0 0 1 2 2 0 1 2]#############predictions:  [1 0 2 2 2 1 1 0]labels:       [2 2 1 0 0 1 1 2]#############predictions:  [1 2 2 1 1 2 1 1]labels:       [1 0 0 1 0 0 0 0]#############predictions:  [0 2 0 2 2 0 2 2]labels:       [2 0 0 0 2 1 1 2]#############predictions:  [0 0 1 0 1 0 2 2]labels:       [0 0 1 0 1 0 2 0]#############predictions:  [0 2 0 1 1 2 2 0]labels:       [0 2 0 2 0 2 0 0]#############predictions:  [2 2 2 2 2 2 2 1]labels:       [2 2 1 1 0 0 2 2]#############predictions:  [2 0 0 2 2 1 1 0]labels:       [1 0 0 1 0 2 1 2]#############predictions:  [2 0 0 2 0 2 2 0]labels:       [2 2 2 2 0 1 1 1]#############predictions:  [0 2 2 0 2 2 0 0]labels:       [1 0 1 2 0 1 1 1]#############predictions:  [0 0 0 0 0 0 0 2]labels:       [2 1 1 0 0 0 1 2]#############predictions:  [2 0 2 0 2 1 0 2]labels:       [2 1 1 2 1 1 0 0]#############predictions:  [1 1 2 0 2 0 2 2]labels:       [0 2 1 2 1 2 1 0]#############predictions:  [2 0 1 1 0 2 0 0]labels:       [2 1 0 1 1 0 2 0]#############predictions:  [2 0 0 2 0 2 1 0]labels:       [0 0 0 0 2 1 0 1]#############predictions:  [1 2 1 0 0 2 0 2]labels:       [2 0 2 1 0 0 1 1]#############Training Loss:  tensor(1.1162, device='cuda:0', grad_fn=<NllLossBackward>)predictions:  [2 0 0 1 1 1 0 1]labels:       [0 1 1 1 1 2 2 1]#############predictions:  [0 2 0 1 2 0 0 1]labels:       [2 2 1 0 1 0 0 0]#############predictions:  [0 0 1 0 0 0 0 1]labels:       [1 0 2 0 0 2 2 0]#############predictions:  [2 1 2 2 0 1 2 0]labels:       [2 0 1 0 2 1 0 1]#############predictions:  [1 0 0 2 0 0 1 1]labels:       [2 2 0 2 0 2 0 0]#############predictions:  [0 0 1 0 0 0 0 0]labels:       [2 2 2 1 2 2 2 2]#############predictions:  [0 0 1 1 0 1 1 0]labels:       [2 1 1 1 0 2 1 0]#############predictions:  [0 0 0 1 0 0 1 0]labels:       [2 0 2 2 0 0 1 2]#############predictions:  [1 0 1 0 0 2 0 0]labels:       [1 1 2 0 0 1 0 0]#############predictions:  [2 1 0 0 0 1 0 0]labels:       [1 2 0 0 0 0 0 0]#############predictions:  [0 2 0 0 0 0 0 0]labels:       [2 0 1 1 2 2 1 1]#############predictions:  [0 1 0 0 0 1 0 2]labels:       [0 2 1 1 0 0 1 2]#############predictions:  [0 2 1 0 0 1 1 1]labels:       [1 1 0 2 0 1 1 0]#############predictions:  [0 1 1 0 0 0 1 0]labels:       [0 0 1 0 1 2 1 1]#############predictions:  [0 1 1 0 1 0 0 0]labels:       [0 1 1 1 2 2 2 0]#############predictions:  [0 0 0 0 1 1 0 0]labels:       [2 0 2 2 1 2 2 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 2 0 2 2 0 1 1]#############predictions:  [0 1 0 0 0 0 0 0]labels:       [0 2 0 1 1 2 0 2]#############predictions:  [1 1 0 1 0 1 0 2]labels:       [1 2 0 0 2 2 2 1]#############predictions:  [1 1 0 0 0 1 2 1]labels:       [0 0 1 2 2 1 2 2]#############predictions:  [1 1 1 0 1 1 2 0]labels:       [0 0 0 2 0 1 0 2]#############predictions:  [0 1 0 0 1 1 2 1]labels:       [2 0 0 1 2 2 1 2]#############predictions:  [1 0 0 0 1 0 0 1]labels:       [1 2 2 2 2 1 0 1]#############predictions:  [2 0 0 0 0 0 0 0]labels:       [1 2 0 2 2 1 1 1]#############predictions:  [2 0 1 1 0 0 1 0]labels:       [0 0 0 0 2 2 1 1]#############predictions:  [2 0 0 1 0 0 1 1]labels:       [2 2 1 1 0 0 1 0]#############predictions:  [1 1 1 1 1 2 0 0]labels:       [0 0 2 1 0 0 0 0]#############predictions:  [1 1 2 0 1 2 0 1]labels:       [0 2 1 0 2 0 0 1]#############predictions:  [0 0 2 1 0 2 0 1]labels:       [1 2 0 2 2 1 0 0]#############predictions:  [0 0 2 0 2 1 1 2]labels:       [2 2 1 2 2 2 0 0]#############predictions:  [0 1 0 0 0 0 2 1]labels:       [1 1 0 1 1 1 0 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 1 0 0 2 0 0 2]#############predictions:  [2 2 2 0 1 1 1 0]labels:       [1 0 2 1 1 2 0 0]#############predictions:  [0 0 1 0 0 0 2 0]labels:       [0 1 2 1 1 0 0 0]#############predictions:  [0 2 0 1 0 2 0 0]labels:       [0 0 2 1 1 0 2 2]#############predictions:  [0 0 1 2 0 2 0 1]labels:       [2 2 0 0 0 2 2 2]#############predictions:  [1 0 0 0 2 0 0 1]labels:       [2 0 1 1 1 0 0 1]#############predictions:  [0 1 0 0 0 0 0 2]labels:       [1 1 1 0 0 0 2 2]#############predictions:  [0 2 0 1 0 2 0 0]labels:       [1 1 1 1 2 2 1 0]#############predictions:  [1 2 0 0 0 0 0 0]labels:       [2 0 2 1 0 1 1 1]#############Training Loss:  tensor(1.2082, device='cuda:0', grad_fn=<NllLossBackward>)predictions:  [0 2 0 0 0 0 2 0]labels:       [1 0 2 1 2 2 1 1]#############predictions:  [2 0 0 0 0 0 1 0]labels:       [1 0 0 0 0 2 1 0]#############predictions:  [0 0 0 0 2 1 1 1]labels:       [0 2 2 0 1 2 1 1]#############predictions:  [2 1 0 1 0 0 2 0]labels:       [1 0 2 1 0 2 1 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 1 0 0 0 0 1 0]#############predictions:  [0 2 1 0 0 0 1 1]labels:       [0 2 2 2 2 1 1 0]#############predictions:  [0 0 0 1 1 0 0 1]labels:       [0 1 0 1 2 2 2 2]#############predictions:  [0 0 0 1 1 1 1 2]labels:       [2 2 1 2 0 1 1 1]#############predictions:  [0 1 2 0 0 1 0 0]labels:       [0 2 1 0 0 1 0 0]#############predictions:  [1 1 1 1 0 0 0 0]labels:       [2 1 2 1 0 2 2 1]#############predictions:  [0 1 2 0 0 1 1 0]labels:       [2 0 2 1 1 1 2 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 0 0 0 1 1 0 0]#############predictions:  [0 0 0 0 0 1 2 2]labels:       [2 2 1 1 0 2 1 2]#############predictions:  [0 1 0 0 1 1 0 1]labels:       [0 1 0 2 1 0 0 1]#############predictions:  [0 2 2 0 0 0 0 2]labels:       [0 0 2 1 2 2 0 1]#############predictions:  [2 0 0 2 2 0 2 0]labels:       [2 1 0 2 2 0 1 0]#############predictions:  [0 2 2 0 2 1 1 2]labels:       [1 1 0 0 2 1 0 0]#############predictions:  [1 1 2 2 0 0 1 2]labels:       [2 0 2 0 1 1 1 1]#############predictions:  [0 1 1 0 0 1 1 0]labels:       [0 2 1 0 0 2 2 0]#############predictions:  [2 1 0 0 0 0 1 1]labels:       [0 2 0 2 0 0 1 1]#############predictions:  [1 2 0 1 2 0 0 0]labels:       [1 0 1 1 0 2 2 2]#############predictions:  [0 0 0 0 2 2 1 2]labels:       [2 2 2 1 1 1 1 0]#############predictions:  [1 2 0 1 0 0 2 0]labels:       [2 2 1 1 1 0 2 0]#############predictions:  [2 0 0 0 0 2 1]labels:       [0 1 1 2 2 0 2]#############======Average Training Loss: 1.11279============Average Training Accuracy: 33.77%======predictions:  [0 0 0 0 0 0 0 0]labels:       [0 2 0 1 1 0 1 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 1 0 2 1 0 0 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 2 2 2 1 2 0 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 1 1 2 0 1 2 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 0 2 0 0 1 2 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 1 0 1 2 1 0 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 2 1 2 0 2 1 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 2 1 2 2 1 1 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 1 0 2 2 0 0 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 0 0 0 2 0 1 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 1 0 1 1 2 1 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 1 1 2 2 0 2 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 0 0 0 1 2 2 1]#############predictions:  [0 0 0 1 0 0 0 0]labels:       [0 0 1 1 0 2 0 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 0 1 2 2 0 1 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 1 1 2 2 2 0 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 0 2 1 2 0 0 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 0 0 0 2 2 0 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 1 1 0 1 0 1 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 2 2 2 2 2 1 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 0 2 1 1 0 2 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 2 1 1 2 0 0 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 2 2 1 2 2 0 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 2 0 1 0 2 0 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 0 1 2 1 1 0 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 0 0 1 2 1 1 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 1 1 1 1 0 1 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 2 1 0 0 2 2 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 1 1 0 0 0 2 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 0 1 1 1 2 0 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 0 0 1 2 1 2 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 0 2 0 1 1 0 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 0 1 0 1 0 1 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 0 1 2 2 1 0 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 2 2 0 2 0 0 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 1 1 1 1 0 0 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 0 1 2 2 0 0 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 0 1 2 0 0 1 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 0 0 0 1 0 0 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 1 2 1 1 2 2 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 0 2 2 2 2 1 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 2 2 2 1 0 0 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 0 2 2 2 1 0 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 1 0 0 1 0 2 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 1 1 0 0 0 0 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 2 1 2 0 2 1 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 1 2 0 1 2 1 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 2 2 0 0 0 1 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 0 1 0 0 0 0 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 2 0 1 1 2 2 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 2 0 0 0 2 2 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 1 2 1 1 1 2 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 0 0 0 2 0 1 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 1 2 1 0 2 2 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 0 0 1 2 2 2 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 0 0 0 2 1 1 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 0 2 0 2 1 0 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 1 0 2 0 0 1 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 1 0 0 1 0 0 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 2 2 2 0 0 1 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 0 1 1 1 0 2 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 1 1 2 2 1 2 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 1 0 2 0 2 2 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 0 0 1 1 0 1 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 0 1 1 1 1 2 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 0 2 1 0 0 0 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 1 1 2 1 0 1 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 0 2 2 0 0 0 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 2 2 2 0 0 2 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 1 0 2 2 2 1 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 1 0 0 1 2 2 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 0 1 2 0 1 2 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 2 0 0 0 2 2 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 2 1 2 0 2 0 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 1 1 1 0 1 1 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 2 0 1 0 0 0 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 0 0 0 0 2 2 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 1 1 1 2 0 1 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 0 2 2 0 1 1 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 0 2 0 1 1 2 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 0 0 0 1 2 2 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 0 2 1 2 0 1 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 0 1 1 1 0 1 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 1 1 1 2 0 0 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 1 1 0 1 1 2 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 2 0 2 1 0 2 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 0 0 0 0 2 1 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 0 0 1 2 2 1 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 0 1 2 0 1 1 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 2 2 1 0 2 1 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 1 1 2 0 2 2 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 0 1 2 2 2 0 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 0 1 1 2 0 2 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 2 0 1 1 0 2 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 2 2 2 2 2 0 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 1 0 0 0 1 0 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 1 2 1 2 1 0 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 1 0 0 0 2 2 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 2 0 1 1 1 0 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 1 1 0 2 2 2 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 1 1 1 1 2 0 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 0 2 0 1 0 2 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 2 0 2 2 0 2 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 0 1 2 2 2 1 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 0 0 1 0 2 1 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 2 2 1 0 2 0 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 0 2 0 2 2 1 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 2 0 0 1 0 1 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 2 1 0 0 0 2 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 2 0 1 2 1 0 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 1 2 2 2 2 0 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 0 0 1 2 0 2 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 0 2 1 1 1 1 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 1 0 0 0 1 0 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 1 2 0 1 2 2 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 1 1 1 2 1 0 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [1 0 1 1 1 0 0 2]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 2 0 0 0 0 1 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [0 0 1 1 2 0 0 1]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 1 1 1 0 1 0 0]#############predictions:  [0 0 0 0 0 0 0 0]labels:       [2 0 2 2 2 0 0 1]#############predictions:  [0 0 0 0 0 0 0]labels:       [2 2 1 1 0 0 1]#############======Average Validation Loss: 1.09527============Average Validation Accuracy: 35.53%======

回答:

对于使用BERT进行多类分类/情感分析,’neutral’类必须是2!它不能在’negative’ = 0和’positive’ = 2之间

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注