arubenruben
commited on
Commit
•
4c52ffd
1
Parent(s):
635c5ff
Upload 2 files
Browse files
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 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
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)
|