You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_batch.py 586 B

123456789101112131415161718
  1. import unittest
  2. from fastNLP.core.batch import Batch
  3. from fastNLP.core.dataset import construct_dataset
  4. from fastNLP.core.sampler import SequentialSampler
  5. class TestCase1(unittest.TestCase):
  6. def test_simple(self):
  7. dataset = construct_dataset(
  8. [["FastNLP", "is", "the", "most", "beautiful", "tool", "in", "the", "world"] for _ in range(40)])
  9. dataset.set_target()
  10. batch = Batch(dataset, batch_size=4, sampler=SequentialSampler(), use_cuda=False)
  11. cnt = 0
  12. for _, _ in batch:
  13. cnt += 1
  14. self.assertEqual(cnt, 10)