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

beam search #157

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

beam search #157

wants to merge 2 commits into from

Conversation

TITC
Copy link
Collaborator

@TITC TITC commented May 31, 2022

code is taken and modified from huggingface transformers. Not much improvement in score, just a tiny (~0.1) positive fluctuation.

usage

switch the return function under LaTeX-OCR/pix2tex/models/utils.py

    @torch.no_grad()
    def generate(self, x: torch.Tensor, temperature: float = 0.25, **kwargs):
        args = Munch(self.args)
        args.update(kwargs)
        args.temperature = temperature
        # return self.decoder.beam_generate((torch.LongTensor([self.args.bos_token]*len(x))[:, None]).to(x.device), context=self.encoder(x), seq_len=self.args.max_seq_len, **args)
        return self.decoder.generate((torch.LongTensor([self.args.bos_token]*len(x))[:, None]).to(x.device), context=self.encoder(x), seq_len=self.args.max_seq_len, **args)

and modify 2 hyper-parameter in config.yaml

num_beams: 3
length_penalty: 0.7 

TITC added 2 commits May 31, 2022 10:51
code taken and modify from huggingface transformers
@lukas-blecher
Copy link
Owner

Thanks! I'll check it out.
Seems to be quite slow, but that was to be expected.
For some reason the method does not work super well with the model because the model is often pretty sure about its guess for the next token (I don't know why). The performance increase is only very marginal.

There definitely needs to be an option to turn this on or off in the cli and gui.

@lukas-blecher lukas-blecher added the enhancement New feature or request label Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants