skogsgren commited on
Commit
32c64a8
1 Parent(s): d34c8d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py CHANGED
@@ -1,5 +1,36 @@
1
  import gradio as gr
2
  import pickle
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
 
5
  with open('learner.bin', 'rb') as f:
 
1
  import gradio as gr
2
  import pickle
3
+ import numpy as np
4
+ from torch import nn
5
+ from transformers import AutoModelForSequenceClassification
6
+ from sklearn.pipeline import Pipeline
7
+ from skorch import NeuralNetClassifier
8
+ from skorch.callbacks import LRScheduler, ProgressBar
9
+ from skorch.hf import HuggingfacePretrainedTokenizer
10
+ from torch.optim.lr_scheduler import LambdaLR
11
+ from skorch.callbacks import EarlyStopping
12
+ from sklearn.metrics import precision_recall_fscore_support
13
+ from sklearn.metrics import balanced_accuracy_score
14
+ from modAL.models import ActiveLearner
15
+ from modAL.uncertainty import uncertainty_sampling
16
+
17
+
18
+ class BertModule(nn.Module):
19
+ """ BERT model according to Skorch convention """
20
+ def __init__(self, name, num_labels):
21
+ super().__init__()
22
+ self.name = name
23
+ self.num_labels = num_labels
24
+ self.reset_weights()
25
+
26
+ def reset_weights(self):
27
+ self.bert = AutoModelForSequenceClassification.from_pretrained(
28
+ self.name, num_labels=self.num_labels
29
+ )
30
+
31
+ def forward(self, **kwargs):
32
+ pred = self.bert(**kwargs)
33
+ return pred.logits
34
 
35
 
36
  with open('learner.bin', 'rb') as f: