Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Decode() got an unexpected keyword argument 'ignore_ids' #88

Open
raphkhan opened this issue Jul 8, 2021 · 0 comments
Open

Decode() got an unexpected keyword argument 'ignore_ids' #88

raphkhan opened this issue Jul 8, 2021 · 0 comments

Comments

@raphkhan
Copy link

raphkhan commented Jul 8, 2021

Hi, I have the following error when I run my script:
TypeError: decode() got an unexpected keyword argument 'ignore_ids'

However, I think I have used well the argument ignore_ids.
How can I fix it? Thanks

def predict_notes(model, tokenizer, keys, notes):
    keys_tokens = tokenizer.encode(keys)
    notes_tokens = tokenizer.encode(notes)

    if len(keys_tokens) + len(notes_tokens) > 510:
        notes_tokens = notes_tokens[len(notes_tokens) - len(keys_tokens) - 510:]

    context_tokens = [2] + keys_tokens + notes_tokens + [3]

    context_tokens = torch.tensor(context_tokens, dtype=torch.long).unsqueeze(0)

    if torch.cuda.is_available():
        context_tokens = context_tokens.cuda()
    
    bad_words_ids = []
    bad_words = ["x8 | "]
    for w in bad_words:
        bad_words_ids.append(tokenizer.encode(bad_words)[0])

    gen_tokens = model.generate(input_ids=context_tokens, 
                                max_length=320, 
                                min_length=32,
                                early_stopping=False,
                                num_beams=20,
                                bos_token_id=2, 
                                eos_token_id=3,
                                no_repeat_ngram_size=15,
                                pad_token_id=0,
                                bad_words_ids=bad_words_ids)
                                
    gen_tokens = gen_tokens[0].tolist()

    notes = tokenizer.decode(gen_tokens, ignore_ids=[0,1,2,3])[0]
    notes = notes.replace(" ", "").replace("|", "|\n")
    
    return notes
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant