dmlc / gluon-nlp

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

[Bug] Bug of top-p sampling #1481

Open sxjscience opened 3 years ago

sxjscience commented 3 years ago

Description

The top-p sampling here is not correct. https://github.com/dmlc/gluon-nlp/blob/52da8aba758b826189505213e1c01f12ebd944fd/src/gluonnlp/sequence_sampler.py#L720-L724 We should sort the probabilities in descending order and then do a cumsum of the probabilities. After that, we set the threshold based on the cumsum values.

@hymzoque