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

ImportError: cannot import name 'context_models' from 'src.config' when running transformers_predictor.py #43

Open
zrc0123 opened this issue Jul 21, 2023 · 2 comments

Comments

@zrc0123
Copy link

zrc0123 commented Jul 21, 2023

Hello,

I got ImportError: cannot import name 'context_models' from 'src.config' when running transformers_predictor.py. I also didn't find the definition of context_models in src folder. Is it a result of changed function names?

Thank you!

@zrc0123
Copy link
Author

zrc0123 commented Jul 21, 2023

Hello,

Now I can run the file with these modifications:

  1. from transformers import RobertaTokenizerFast
  2. self.tokenizer = RobertaTokenizerFast.from_pretrained(self.conf.embedder_type, add_prefix_space=True)
  3. batch_max_scores, batch_max_ids = self.model(subword_input_ids = batch.input_ids.to(self.conf.device),
    word_seq_lens = batch.word_seq_len.to(self.conf.device),
    orig_to_tok_index = batch.orig_to_tok_index.to(self.conf.device),
    attention_mask = batch.attention_mask.to(self.conf.device),
    is_train = False)

@wulonmt
Copy link

wulonmt commented Mar 28, 2024

Threre's my modifications:

  1. Establish tokenizer from AutoTokenizer
    from transformers import AutoTokenizer
    &
    self.tokenizer = AutoTokenizer.from_pretrained(self.conf.embedder_type, add_prefix_space=True, use_fast=True)

  2. Modify the parameters when calling self.model
    batch_max_scores, batch_max_ids = self.model(subword_input_ids = batch.input_ids.to(self.conf.device),
    word_seq_lens = batch.word_seq_len.to(self.conf.device),
    orig_to_tok_index = batch.orig_to_tok_index.to(self.conf.device),
    attention_mask = batch.attention_mask.to(self.conf.device),
    is_train=False)
    Then it works well.

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