-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
40 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 22 additions & 14 deletions
36
applications/FLASK/Transformer/datasets/pretokenize/QM9_Pretokenize.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,34 @@ | ||
import numpy as np | ||
from SMILES_tokenizer import MolTokenizer | ||
from data_utils import random_zero_array | ||
import os | ||
import os.path | ||
|
||
|
||
def main(): | ||
tokenizer = MolTokenizer("SMILES_vocab.json") | ||
data_dir = os.getenv("QM9_DATA_DIR", "/p/vast1/lbann/datasets/FLASK/QM9") | ||
|
||
tokenizer = MolTokenizer(os.path.join(data_dir, "QM9_vocab.json")) | ||
tokenizer.load_vocab_file() | ||
with open("QM9_smiles.txt", 'r') as smiles_data: | ||
smiles_data = smiles_data.readlines() | ||
num_samples = len(smiles_data) | ||
max_length = 32 | ||
|
||
tokenized_data = np.ones((num_samples, max_length)) * tokenizer.encode(tokenizer.pad_token) | ||
tokenized_data[:, 0] = tokenizer.encode(tokenizer.sep_token) | ||
data_file = os.path.join(data_dir, "QM9_smiles.txt") | ||
with open(data_file, "r") as smiles_data: | ||
smiles_data = smiles_data.readlines() | ||
num_samples = len(smiles_data) | ||
max_length = 32 | ||
|
||
tokenized_data = np.ones((num_samples, max_length)) * tokenizer.encode( | ||
tokenizer.pad_token | ||
) | ||
tokenized_data[:, 0] = tokenizer.encode(tokenizer.sep_token) | ||
|
||
for i, smiles in enumerate(smiles_data, start=1): | ||
tokens = tokenizer.tokenize(smiles) | ||
tokens = random_zero_array(tokens, 0.15, tokenizer.encode(tokenizer.mask_token)) | ||
tokenized_data[i, :len(tokens)] = tokens | ||
tokenized_data[i, len(tokens)] = tokenizer.encode(tokenizer.cls_token) | ||
for i, smiles in enumerate(smiles_data, start=0): | ||
tokens = tokenizer.tokenize(smiles) | ||
tokenized_data[i, : len(tokens)] = tokens | ||
tokenized_data[i, len(tokens)] = tokenizer.encode(tokenizer.sep_token) | ||
save_file_loc = os.path.join(data_dir, "QM9_Pretokenized.npy") | ||
np.save(save_file_loc, tokenized_data) | ||
|
||
np.save('QM9_Pretokenized.npy', tokenized_data) | ||
|
||
if __name__ == '__main__': | ||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters