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

TypeError: list indices must be integers or slices, not str #243

Closed
AshishKumarB opened this issue Oct 6, 2021 · 4 comments
Closed

TypeError: list indices must be integers or slices, not str #243

AshishKumarB opened this issue Oct 6, 2021 · 4 comments

Comments

@AshishKumarB
Copy link

The below code was working perfectly in pytorch 1.4 and python3.6

import nlpaug.augmenter.sentence as nas
aug = nas.ContextualWordEmbsForSentenceAug(model_path='xlnet-base-cased')
text= "Please find below some recent comparative data between the below product and ibrance"
augmented_texts = aug.augment(text, n=3)

---------------------------------------------- Error-----------------------------------------------------------

TypeError Traceback (most recent call last)
in
1 aug = nas.ContextualWordEmbsForSentenceAug(model_path='xlnet-base-cased')
2 text= "Please find below some recent comparative data between the below product and ibrance"
----> 3 augmented_texts = aug.augment(text, n=3)

~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/nlpaug/base_augmenter.py in augment(self, data, n, num_thread)
93 elif self.class.name in ['AbstSummAug', 'BackTranslationAug', 'ContextualWordEmbsAug', 'ContextualWordEmbsForSentenceAug']:
94 for _ in range(aug_num):
---> 95 result = action_fx(clean_data)
96 if isinstance(result, list):
97 augmented_results.extend(result)

~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/nlpaug/augmenter/sentence/context_word_embs_sentence.py in insert(self, data)
96 all_data = [data]
97
---> 98 return self.model.predict(all_data)
99
100 @classmethod

~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/nlpaug/model/lang_models/text_generation_transformers.py in predict(self, texts, target_words, n)
88 results.extend(predict_result)
89
---> 90 return [r['generated_text'] for r in results]

~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/nlpaug/model/lang_models/text_generation_transformers.py in (.0)
88 results.extend(predict_result)
89
---> 90 return [r['generated_text'] for r in results]

TypeError: list indices must be integers or slices, not str

@makcedward makcedward added bug Something isn't working and removed bug Something isn't working labels Oct 18, 2021
@makcedward
Copy link
Owner

transformers changed interface from 4.11. You may either use transformers 4.10 or upgrading nlpaug to 1.1.8

@makcedward
Copy link
Owner

Fixed in 1.1.8 version

@TimbusCalin
Copy link

This still doesn't work for me. I tried with transformers==4.10 and nlp==1.1.8 with Python 3.8 and I still get this error thrown.

@TimbusCalin
Copy link

If anyone is interested, I made it work with:

transformers==4.11.3
sentencepiece==0.1.96
nlpaug==1.1.8

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

3 participants