EthanWng97 / Google-BERT-on-fake_or_real-news-dataset

📚 Use Google BERT on fake_or_real news dataset with best f1 score: 0.986
17 stars 7 forks source link

par_eda =1,error #4

Open jxy-001 opened 5 years ago

jxy-001 commented 5 years ago

if par_eda == 1: # use eda to operate sentences when par_eda is true for i in range(len(dat_plus['title_text'])): if i%6 == 1:
dat_plus['title_text'][i] = copy.deepcopy(eda_text(dat_plus['title_text'][i])) dat_plus['title_text'][i] = "".join(dat_plus['title_text'][i])


TypeError Traceback (most recent call last)

in 2 for i in range(len(dat_plus['title_text'])): 3 if i%6 == 1: ----> 4 dat_plus['title_text'][i] = copy.deepcopy(eda_text(dat_plus['title_text'][i])) 5 dat_plus['title_text'][i] = "".join(dat_plus['title_text'][i]) in eda_text(text) 23 if len(zz) <= 500: 24 #print(len(zz)) ---> 25 tmp_text = aug_text(tmp_text) 26 # conbine prior 3 sentences and rest sentences 27 for j in range(len(text)-3): in aug_text(text) 1 def aug_text(text): ----> 2 text = aug.augment(text) 3 return(text) /home/user5/Desktop/BERT-FAKE-OR-TRUE/nlpaug/flow/sequential.py in augment(self, data) 36 augmented_data = data[:] 37 for aug in self: ---> 38 augmented_data = aug.augment(augmented_data) 39 40 results.append(augmented_data) /home/user5/Desktop/BERT-FAKE-OR-TRUE/nlpaug/base_augmenter.py in augment(self, data) 71 return self.insert(data) 72 elif self.action == Action.SUBSTITUTE: ---> 73 return self.substitute(data) 74 elif self.action == Action.SWAP: 75 return self.swap(data) /home/user5/Desktop/BERT-FAKE-OR-TRUE/nlpaug/augmenter/word/bert.py in substitute(self, data) 98 for aug_idx in aug_idxes[:1]: 99 original_word = results[aug_idx] --> 100 candidate_words = self.model.predict(results, original_word, top_n=self.aug_n) 101 substitute_word = self.sample(candidate_words, 1)[0] 102 /home/user5/Desktop/BERT-FAKE-OR-TRUE/nlpaug/model/lang_models/bert.py in predict(self, input_tokens, target_word, top_n) 44 top_score_idx = target_idx 45 for _ in range(100): ---> 46 predictions[0, target_pos, top_score_idx] = -9999 47 top_score_idx = torch.argmax(predictions[0, target_pos]).item() 48 top_score_token = self.tokenizer.convert_ids_to_tokens([top_score_idx])[0] TypeError: 'tuple' object does not support item assignmen
EthanWng97 commented 5 years ago

I havent meet this problem before. Print dat_plus and its type. Maybe u can rerun the cells above to solve this problem.

jxy-001 commented 5 years ago

the type is str so how did you solve the problem?Rerun is useless.

EthanWng97 commented 5 years ago

maybe these links can help: https://stackoverflow.com/questions/7735838/typeerror-tuple-object-does-not-support-item-assignment-when-swapping-values https://stackoverflow.com/questions/19338209/how-to-fix-a-typeerror-tuple-object-does-not-support-item-assignment/19338259

BTW: sorry, I'm not familiar with python.