perman2011 commited on
Commit
bab1cdc
1 Parent(s): b6794ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py CHANGED
@@ -8,6 +8,25 @@ MAX_LEN = 100
8
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
9
  tokenizer = DistilBertTokenizer.from_pretrained('distilbert-base-uncased', truncation=True, do_lower_case=True)
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  model_DB = DistilBERTClass()
12
  loaded_model_path = './model_DB_1.pt'
13
  model_DB.load_state_dict(torch.load(loaded_model_path, map_location=torch.device('cpu')))
 
8
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
9
  tokenizer = DistilBertTokenizer.from_pretrained('distilbert-base-uncased', truncation=True, do_lower_case=True)
10
 
11
+ class DistilBERTClass(torch.nn.Module):
12
+ def __init__(self):
13
+ super(DistilBERTClass, self).__init__()
14
+ self.l1 = DistilBertModel.from_pretrained("distilbert-base-uncased")
15
+ self.pre_classifier = torch.nn.Linear(768, 768)
16
+ self.dropout = torch.nn.Dropout(0.1)
17
+ self.classifier = torch.nn.Linear(768, 1)
18
+
19
+ def forward(self, input_ids, attention_mask, token_type_ids):
20
+ output_1 = self.l1(input_ids=input_ids, attention_mask=attention_mask)
21
+ hidden_state = output_1[0]
22
+ pooler = hidden_state[:, 0]
23
+ pooler = self.pre_classifier(pooler)
24
+ pooler = torch.nn.ReLU()(pooler)
25
+ pooler = self.dropout(pooler)
26
+ output = self.classifier(pooler)
27
+ return output
28
+
29
+
30
  model_DB = DistilBERTClass()
31
  loaded_model_path = './model_DB_1.pt'
32
  model_DB.load_state_dict(torch.load(loaded_model_path, map_location=torch.device('cpu')))