dmlc / gluon-nlp

NLP made easy
https://nlp.gluon.ai/
Apache License 2.0
2.56k stars 535 forks source link

Add sorting of chunks to evaluation #1588

Open bartekkuncer opened 2 years ago

bartekkuncer commented 2 years ago

Description

This change introduces sorting of chunks before executing evaluation to reduce padding to minimum and in this way improve performance.

How the change works

As every input feature has unique qas_id it can be used for sorting. With the sorting evaluation function goes like this:

  1. sort input features by qas_id
  2. chunk data
  3. sort chunks by their length (to reduce padding to minimum)
  4. perform inference
  5. sort chunks and results by qas_id
  6. evaluate data

Step number 1 is performed so that chunks and their inference results can be easily put in proper order in step number 5 for evaluation in step 6.

Performance

Results for max_seq_length=128, doc_stride=32: no sort: image

sorted: image

Performance did not improve much due to most of the chunks being of same 128 length due to relatively small values of max_seq_length and doc_stride.

Results for max_seq_length=512, doc_stride=128 (default values in run_squad.py script): no sort: image

sorted: image

As you can see the performance improved significantly (~20%) without any loss of accuracy.

cc @dmlc/gluon-nlp-team