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_qa.py 968 B

123456789101112131415161718192021222324
  1. import pytest
  2. from fastNLP.io.pipe.qa import CMRC2018BertPipe
  3. from fastNLP.io.loader.qa import CMRC2018Loader
  4. class CMRC2018PipeTest:
  5. def test_process(self):
  6. data_bundle = CMRC2018Loader().load('tests/data_for_tests/io/cmrc/')
  7. pipe = CMRC2018BertPipe()
  8. data_bundle = pipe.process(data_bundle)
  9. for name, dataset in data_bundle.iter_datasets():
  10. for ins in dataset:
  11. if 'target_start' in ins:
  12. # 抓到的答案是对应上的
  13. start_index = ins['target_start']
  14. end_index = ins['target_end']+1
  15. extract_answer = ''.join(ins['raw_chars'][start_index:end_index])
  16. assert(extract_answer == ins['answers'][0])
  17. # 测试context_len是对的
  18. raw_chars = ins['raw_chars']
  19. expect_len = raw_chars.index('[SEP]')
  20. assert(expect_len == ins['context_len'])