Update pipe.py
Browse files
pipe.py
CHANGED
|
@@ -92,15 +92,15 @@ class SmilesDiffusionPipe(Pipeline):
|
|
| 92 |
mask_token = voc.vocab["[MASK]"]
|
| 93 |
|
| 94 |
total_tokens = sequences.size(1)
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
|
| 105 |
encoded = self.encode(self.tokenize(masked_smi))
|
| 106 |
encoded_tensor = torch.tensor(encoded, dtype=torch.long).unsqueeze(0).to(device)
|
|
|
|
| 92 |
mask_token = voc.vocab["[MASK]"]
|
| 93 |
|
| 94 |
total_tokens = sequences.size(1)
|
| 95 |
+
original_num_masked = (sequences == mask_token).sum().item()
|
| 96 |
+
print(f"Original number of masked tokens: {original_num_masked}")
|
| 97 |
+
|
| 98 |
+
if total_tokens == 0:
|
| 99 |
+
raise ValueError("Encoded SMILES has no tokens.")
|
| 100 |
+
if original_num_masked == 0:
|
| 101 |
+
print("No masked tokens found. Returning original SMILES.")
|
| 102 |
+
input_ids = input_ids[1:-1]
|
| 103 |
+
return self.decode(input_ids)
|
| 104 |
|
| 105 |
encoded = self.encode(self.tokenize(masked_smi))
|
| 106 |
encoded_tensor = torch.tensor(encoded, dtype=torch.long).unsqueeze(0).to(device)
|