kelu01 commited on
Commit
eeff8a1
·
verified ·
1 Parent(s): 06b7798

Update pipe.py

Browse files
Files changed (1) hide show
  1. pipe.py +7 -3
pipe.py CHANGED
@@ -35,10 +35,14 @@ class SmilesDiffusionPipe(Pipeline):
35
 
36
  def encode(self, char_list):
37
  smiles_matrix = np.zeros(len(char_list), dtype=np.float32)
 
 
 
 
 
38
  for i, char in enumerate(char_list):
39
- if char not in self.voc.vocab:
40
- raise ValueError(f"Token '{char}' not in vocabulary.")
41
- smiles_matrix[i] = self.voc.vocab[char]
42
  return smiles_matrix
43
 
44
  def decode(self, matrix):
 
35
 
36
  def encode(self, char_list):
37
  smiles_matrix = np.zeros(len(char_list), dtype=np.float32)
38
+
39
+ unk_id = self.voc.vocab.get("[UNK]")
40
+ if unk_id is None:
41
+ raise ValueError("[UNK] token not found in vocabulary.")
42
+
43
  for i, char in enumerate(char_list):
44
+ smiles_matrix[i] = self.voc.vocab.get(char, unk_id)
45
+
 
46
  return smiles_matrix
47
 
48
  def decode(self, matrix):