arubenruben commited on
Commit
4c52ffd
1 Parent(s): 635c5ff

Upload 2 files

Browse files
Files changed (2) hide show
  1. input.txt +2 -0
  2. model.py +21 -19
input.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ Olá o meu Nome é Rúben, e o teu qual é?
2
+ Olá meu nome é Rubens, e seu qual é?
model.py CHANGED
@@ -33,22 +33,24 @@ class Ensembler(torch.nn.Module):
33
  def forward(self, input_ids, attention_mask):
34
  outputs = []
35
 
36
- for domain in ['politics', 'news', 'law', 'social_media', 'literature', 'web']:
37
- specialist = LanguageIdentifier()
38
-
39
- specialist.load_state_dict(torch.load(f"models/{domain}.pt", map_location=self.device))
40
-
41
- specialist.eval()
42
-
43
- specialist.to(self.device)
44
-
45
- outputs.append(specialist(input_ids, attention_mask))
46
-
47
- # Remove the specialist from the GPU
48
- specialist.cpu()
49
- del specialist
50
-
51
-
52
- outputs = torch.cat(outputs, dim=1)
53
-
54
- return torch.mean(outputs, dim=1).unsqueeze(1)
 
 
 
33
  def forward(self, input_ids, attention_mask):
34
  outputs = []
35
 
36
+ with torch.no_grad():
37
+ for domain in ['politics', 'news', 'law', 'social_media', 'literature', 'web']:
38
+ specialist = LanguageIdentifier()
39
+
40
+ specialist.load_state_dict(torch.load(f"{domain}.pt", map_location=self.device))
41
+
42
+ specialist.eval()
43
+
44
+ specialist.to(self.device)
45
+
46
+ outputs.append(specialist(input_ids, attention_mask))
47
+
48
+ # Remove the specialist from the GPU
49
+ specialist.cpu()
50
+ del specialist
51
+ torch.cuda.empty_cache()
52
+
53
+
54
+ outputs = torch.cat(outputs, dim=1)
55
+
56
+ return torch.mean(outputs, dim=1).unsqueeze(1)