Spaces:
Runtime error
Runtime error
snaramirez872
commited on
Commit
·
e55d629
1
Parent(s):
d31451e
Update app.py
Browse files
app.py
CHANGED
@@ -62,8 +62,7 @@ class MultiLabelDataset(set):
|
|
62 |
'targets': torch.tensor(self.targets[idx], dtype=torch.float)
|
63 |
}
|
64 |
|
65 |
-
|
66 |
-
trainSize = 0.4
|
67 |
trainData = new.sample(frac=trainSize,random_state=200)
|
68 |
testData = new.drop(trainData.index).reset_index(drop=True)
|
69 |
trainData = trainData.reset_index(drop=True)
|
@@ -74,17 +73,17 @@ testSet = MultiLabelDataset(testData, tokenizer, MAX_LEN)
|
|
74 |
training_loader = DL(trainSet, batch_size=TRAIN_BATCH_SIZE, shuffle=True)
|
75 |
testing_loader = DL(testSet, batch_size=VALID_BATCH_SIZE, shuffle=True)
|
76 |
|
77 |
-
#
|
78 |
-
class
|
79 |
def __init__(self):
|
80 |
-
super(
|
81 |
self.l1 = BM.from_pretrained(modName)
|
82 |
self.pre_classifier = TNN.Linear(768, 768)
|
83 |
self.dropout = TNN.Dropout(0.1)
|
84 |
self.classifier = TNN.Linear(768, 6)
|
85 |
|
86 |
def forward(self, input_ids, attention_mask, token_type_ids):
|
87 |
-
out = self.l1(input_ids=input_ids, attention_mask=attention_mask)
|
88 |
hidden_state = out[0]
|
89 |
po = hidden_state[:, 0]
|
90 |
po = self.pre_classifier(po)
|
@@ -93,7 +92,7 @@ class DistilBERTClass(TNN.Module):
|
|
93 |
outs = self.classifier(po)
|
94 |
return outs
|
95 |
|
96 |
-
mod =
|
97 |
mod.to(device)
|
98 |
|
99 |
# Loss function and Optimizer
|
|
|
62 |
'targets': torch.tensor(self.targets[idx], dtype=torch.float)
|
63 |
}
|
64 |
|
65 |
+
trainSize = 0.8
|
|
|
66 |
trainData = new.sample(frac=trainSize,random_state=200)
|
67 |
testData = new.drop(trainData.index).reset_index(drop=True)
|
68 |
trainData = trainData.reset_index(drop=True)
|
|
|
73 |
training_loader = DL(trainSet, batch_size=TRAIN_BATCH_SIZE, shuffle=True)
|
74 |
testing_loader = DL(testSet, batch_size=VALID_BATCH_SIZE, shuffle=True)
|
75 |
|
76 |
+
# neural network
|
77 |
+
class BERTClass(TNN.Module):
|
78 |
def __init__(self):
|
79 |
+
super(BERTClass, self).__init__()
|
80 |
self.l1 = BM.from_pretrained(modName)
|
81 |
self.pre_classifier = TNN.Linear(768, 768)
|
82 |
self.dropout = TNN.Dropout(0.1)
|
83 |
self.classifier = TNN.Linear(768, 6)
|
84 |
|
85 |
def forward(self, input_ids, attention_mask, token_type_ids):
|
86 |
+
out = self.l1(input_ids=input_ids, attention_mask=attention_mask, token_type_ids=token_type_ids)
|
87 |
hidden_state = out[0]
|
88 |
po = hidden_state[:, 0]
|
89 |
po = self.pre_classifier(po)
|
|
|
92 |
outs = self.classifier(po)
|
93 |
return outs
|
94 |
|
95 |
+
mod = BERTClass()
|
96 |
mod.to(device)
|
97 |
|
98 |
# Loss function and Optimizer
|