generated from VectorInstitute/aieng-template
-
Notifications
You must be signed in to change notification settings - Fork 0
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
4 changed files
with
73 additions
and
26 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
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
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,14 +1,28 @@ | ||
"""Tests for DataCollator.""" | ||
import torch | ||
|
||
from atomgen.data.data_collator import DataCollatorForAtomModeling | ||
from atomgen.data.tokenizer import AtomTokenizer | ||
|
||
|
||
def test_data_collator(): | ||
data_collator = DataCollatorForAtomModeling() | ||
input_ids = [1,2,10] | ||
coords = [[0.5, 0.2, 0.1], [0.3, 0.4, 0.5], [0.1, 0.2, 0.3]] | ||
labels = [[1, 2, 3], [4, 5, 6]] | ||
batch = data_collator(input_ids=input_ids, attention_mask=attention_mask, labels=labels) | ||
assert batch["input_ids"].tolist() == input_ids | ||
assert batch["attention_mask"].tolist() == attention_mask | ||
assert batch["labels"].tolist() == labels | ||
assert batch["decoder_input_ids"].tolist() == [[1, 2, 3], [4, 5, 6]] | ||
assert batch["decoder_attention_mask"].tolist() == [[1, 1, 1], [1, 1, 1]] | ||
assert batch["decoder_labels"].tolist() == [[1, 2, 3], [4, 5, 6]] | ||
"""Test DataCollatorForAtomModeling.""" | ||
tokenizer = AtomTokenizer(vocab_file="atomgen/data/tokenizer.json") | ||
data_collator = DataCollatorForAtomModeling( | ||
tokenizer=tokenizer, | ||
mam=False, | ||
coords_perturb=False, | ||
causal=False, | ||
return_edge_indices=False, | ||
pad=True, | ||
) | ||
size = torch.randint(4, 16, (10,)).tolist() | ||
dataset = [ | ||
{ | ||
"input_ids": torch.randint(0, 123, (size[i],)).tolist(), | ||
"coords": torch.randint(0, 123, (size[i], 3)).tolist(), | ||
} | ||
for i in range(10) | ||
] | ||
batch = data_collator(dataset) | ||
assert len(batch["input_ids"]) == 10 |
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,7 +1,10 @@ | ||
"""Test AtomTokenizer.""" | ||
from atomgen.data.tokenizer import AtomTokenizer | ||
|
||
|
||
def test_tokenizer(): | ||
"""Test AtomTokenizer.""" | ||
tokenizer = AtomTokenizer(vocab_file="atomgen/data/tokenizer.json") | ||
text = "BaCCHeNNN" | ||
text = "MgCCHeNNN" | ||
tokens = tokenizer.tokenize(text) | ||
assert tokens == ["Ba", "C", "C", "He", "N", "N", "N"] | ||
assert tokens == ["Mg", "C", "C", "He", "N", "N", "N"] |