dazzleun-7 commited on
Commit
8136c24
ยท
verified ยท
1 Parent(s): 5fa5554

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -20
app.py CHANGED
@@ -80,26 +80,6 @@ class BERTClassifier(nn.Module):
80
  probabilities = self.softmax(logits) # Softmax๋กœ ๊ฐ ํด๋ž˜์Šค์˜ ํ™•๋ฅ  ๊ณ„์‚ฐ
81
  return probabilities # ๊ฐ ํด๋ž˜์Šค์— ๋Œ€ํ•œ ํ™•๋ฅ  ๋ฐ˜ํ™˜
82
 
83
- #์ •์˜ํ•œ ๋ชจ๋ธ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
84
- model = BERTClassifier(bertmodel,dr_rate=0.4).to(device)
85
- #model = BERTClassifier(bertmodel, dr_rate=0.5).to('cpu')
86
-
87
- # Prepare optimizer and schedule (linear warmup and decay)
88
- no_decay = ['bias', 'LayerNorm.weight']
89
- optimizer_grouped_parameters = [
90
- {'params': [p for n, p in model.named_parameters() if not any(nd in n for nd in no_decay)], 'weight_decay': 0.01},
91
- {'params': [p for n, p in model.named_parameters() if any(nd in n for nd in no_decay)], 'weight_decay': 0.0}
92
- ]
93
- optimizer = AdamW(optimizer_grouped_parameters, lr=learning_rate)
94
- loss_fn = nn.CrossEntropyLoss()
95
- t_total = len(train_dataloader) * num_epochs
96
- warmup_step = int(t_total * warmup_ratio)
97
- scheduler = get_cosine_schedule_with_warmup(optimizer, num_warmup_steps=warmup_step, num_training_steps=t_total)
98
- def calc_accuracy(X,Y):
99
- max_vals, max_indices = torch.max(X, 1)
100
- train_acc = (max_indices == Y).sum().data.cpu().numpy()/max_indices.size()[0]
101
- return train_acc
102
- train_dataloader
103
 
104
  model = torch.load('./model_weights_softmax(model).pth')
105
  model.eval()
 
80
  probabilities = self.softmax(logits) # Softmax๋กœ ๊ฐ ํด๋ž˜์Šค์˜ ํ™•๋ฅ  ๊ณ„์‚ฐ
81
  return probabilities # ๊ฐ ํด๋ž˜์Šค์— ๋Œ€ํ•œ ํ™•๋ฅ  ๋ฐ˜ํ™˜
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
  model = torch.load('./model_weights_softmax(model).pth')
85
  model.eval()