MCPcopy Create free account
hub / github.com/huggingface/transformers / test_dataset

Function test_dataset

examples/seq2seq/test_seq2seq_examples.py:234–251  ·  view source on GitHub ↗
(tok)

Source from the content-addressed store, hash-verified

232 ["tok"], [pytest.param(T5_TINY), pytest.param(BART_TINY), pytest.param(MBART_TINY), pytest.param(MARIAN_TINY)]
233)
234def test_dataset(tok):
235 tokenizer = AutoTokenizer.from_pretrained(tok)
236 tmp_dir = make_test_data_dir()
237 max_len_source = max(len(tokenizer.encode(a)) for a in ARTICLES)
238 max_len_target = max(len(tokenizer.encode(a)) for a in SUMMARIES)
239 trunc_target = 4
240 train_dataset = SummarizationDataset(
241 tokenizer, data_dir=tmp_dir, type_path="train", max_source_length=20, max_target_length=trunc_target,
242 )
243 dataloader = DataLoader(train_dataset, batch_size=2, collate_fn=train_dataset.collate_fn)
244 for batch in dataloader:
245 assert batch["attention_mask"].shape == batch["input_ids"].shape
246 # show that articles were trimmed.
247 assert batch["input_ids"].shape[1] == max_len_source
248 assert 20 >= batch["input_ids"].shape[1] # trimmed significantly
249 # show that targets were truncated
250 assert batch["decoder_input_ids"].shape[1] == trunc_target # Truncated
251 assert max_len_target > trunc_target # Truncated

Callers

nothing calls this directly

Calls 4

make_test_data_dirFunction · 0.85
encodeMethod · 0.80
from_pretrainedMethod · 0.45

Tested by

no test coverage detected