Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Want to get the top 10 translation results #15

Open
PPPNut opened this issue Aug 8, 2023 · 6 comments
Open

Want to get the top 10 translation results #15

PPPNut opened this issue Aug 8, 2023 · 6 comments

Comments

@PPPNut
Copy link

PPPNut commented Aug 8, 2023

I want to get the best 10 translations through the search algorithm, but I don't know how to do it.

@hzhwcmhf
Copy link
Member

hzhwcmhf commented Aug 9, 2023

The current implementation does not support this function. You may need to modify dag_search.

First,

https://github.com/thu-coai/DAG-Search/blob/d5056b8da20495be6794967a718f2a0a4f5df227/python/dag_search.pyx#L159-L167

L160 specifies the number of beams after sorting and filtering, it will be 1 when step is the last position. You may change it to 10 if you want 10 translations.

Second,

https://github.com/thu-coai/DAG-Search/blob/d5056b8da20495be6794967a718f2a0a4f5df227/python/dag_search.pyx#L181-L187

This function obtains the paths of the beams. It currently only obtains the path of the best beam (i.e., beams[i * SearchBeam.max_pos]), and save it to result. You may change it to beams[i * SearchBeam.max_pos + j] (j from 0 to 9) to get the other path.

You will need to compile the codes and reinstall dag_search by

cd dag_search
python3 setup.py build_ext --inplace
pip install -e .

I am sorry that I am busy in my work and does not have time to add this function recently. If you have any problem, please reply in this issue.

@PPPNut
Copy link
Author

PPPNut commented Sep 6, 2023

I have spent a long time trying to modify it, but without success. May I ask if the author has time to add this feature? I would be extremely grateful. 🙏

@hzhwcmhf
Copy link
Member

hzhwcmhf commented Sep 6, 2023

I will try to add this feature in two weeks.

@PPPNut
Copy link
Author

PPPNut commented Sep 6, 2023

Thank you sincerely.

@hzhwcmhf
Copy link
Member

I push an update to the nbest branch.

git fetch
git checkout nbest
git submodule update
cd dag_search
python3 setup.py build_ext --inplace
pip install -e .

You can then add --decode-final-beamsize 10 --nbest 10 in beamsearch to obtain 10 best candidates.

Please let me know whether it works well. I will merge it into main if no bugs exist. @PPPNut

@PPPNut
Copy link
Author

PPPNut commented Sep 12, 2023

Thank you very much for your guidance and advice. I will promptly provide you with feedback if there are any questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants