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

IndexError: list index out of range in detokenize #4

Open
loretoparisi opened this issue Jan 14, 2020 · 0 comments
Open

IndexError: list index out of range in detokenize #4

loretoparisi opened this issue Jan 14, 2020 · 0 comments

Comments

@loretoparisi
Copy link

loretoparisi commented Jan 14, 2020

I get an error after running

for temp in [1.0]:
    bert_sents = generate(n_samples, seed_text=seed_text, batch_size=batch_size, max_len=max_len,
                          sample=sample, top_k=top_k, temperature=temp, burnin=burnin, max_iter=max_iter,
                          cuda=True)
    out_file = "data/%s-len%d-burnin%d-topk%d-temp%.3f.txt" % (model_version, max_len, burnin, top_k, temp)
    write_sents(out_file, bert_sents, should_detokenize=True)

Stacktrace:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-23-776125cadf25> in <module>()
     18                           cuda=True)
     19     out_file = "data/%s-len%d-burnin%d-topk%d-temp%.3f.txt" % (model_version, max_len, burnin, top_k, temp)
---> 20     write_sents(out_file, bert_sents, should_detokenize=True)

<ipython-input-19-027cb8b83cc4> in write_sents(out_file, sents, should_detokenize)
     15     with open(out_file, "w") as out_fh:
     16         for sent in sents:
---> 17             sent = detokenize(sent[1:-1]) if should_detokenize else sent
     18             out_fh.write("%s\n" % " ".join(sent))

<ipython-input-16-beace4564740> in detokenize(sent)
     20     for i, tok in enumerate(sent):
     21         if tok.startswith("##"):
---> 22             new_sent[len(new_sent) - 1] = new_sent[len(new_sent) - 1] + tok[2:]
     23         else:
     24             new_sent.append(tok)

IndexError: list index out of range

The saved file head

$ head -n3 bert-base-uncased-len40-burnin250-topk100-temp1.000.txt 
sammy harves [ " baby candy " / " dream of baby candy " ( gas station theme ) ) mary ford and baby candy . ( gas station theme ) concept album , featuring mary ford .
3 . contemporary art review ( 2nd ed . october 2008 ) , review with essays on contemporary art , ( london : bateman & partners , february 2009 ) sculpture and the minimalist movement , part .
the truth outside ( matthew greengrass ) psycho ( 1964 ? ) psycho ( orson welles ) monster show ( orson welles ) ( barnacles ) part 3 ( the snare drum ) - narration ;
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

1 participant