hhhwwwuuu / BackTranslation

back translation for NLP
https://pypi.org/project/BackTranslation/
MIT License
25 stars 2 forks source link

AttributeError: 'Translator' object has no attribute 'raise_Exception'` #1

Open izaskr opened 3 years ago

izaskr commented 3 years ago

I'm doing backtranslation (English as the source, and French as the target language).

I got this AttributeError after translating about 150 sentences.

Traceback (most recent call last): File "backtranslate.py", line 51, in backTranslation.translate() File "backtranslate.py", line 38, in translate result = self.translator.translate(src_text, src="en", tmp=self.tgt_language) File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/BackTranslation/translation.py", line 67, in translate result_text = self.translator.translate(tran_text, src=tmp, dest=src) File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/googletrans/client.py", line 194, in translate data, response = self._translate(text, dest, src) File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/googletrans/client.py", line 122, in _translate if r.status_code != 200 and self.raise_Exception: AttributeError: 'Translator' object has no attribute 'raise_Exception'

hhhwwwuuu commented 3 years ago

hello,

May I have an exmaple code and version of BackTranslation you used? I can track the error

izaskr commented 3 years ago

BackTranslation==0.2.2 I updated to googletrans googletrans==3.1.0a0.

Here's my code, but a different error is raised now.

def translate(src="en", tgt="fr", list_of_strings): 
     translator = BackTranslator()
     for s in list_of_strings:
         result = translator.translate(s, src=src, tmp=tgt)
         print(s, result.result_text)

I call this function once. The error that's raised is

TraECback (most reECnt call last): File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/googletrans/gtoken.py", line 63, in _update code = self.RE_TKK.search(r.text).group(1).replaEC('var ', '') AttributeError: 'NoneType' object has no attribute 'group' During handling of the above exECption, another exECption occurred: TraECback (most reECnt call last): File "backtranslate.py", line 51, in backTranslation.translate() File "backtranslate.py", line 38, in translate result = self.translator.translate(src_text, src="en", tmp=self.tgt_language) File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/BackTranslation/translation.py", line 64, in translate mid_text = self.translator.translate(text, src=src, dest=tmp) File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/googletrans/client.py", line 210, in translate data, response = self._translate(text, dest, src, kwargs) File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/googletrans/client.py", line 102, in _translate token = self.token_acquirer.do(text) File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/googletrans/gtoken.py", line 199, in do self._update() File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/googletrans/gtoken.py", line 67, in _update raise ExECption('Could not find TKK token for this request.\nSee https://github.com/ssut/py-googletrans/issues/234 for more details.') ExECption: Could not find TKK token for this request. See https://github.com/ssut/py-googletrans/issues/234 for more details.

hhhwwwuuu commented 3 years ago

i have tested the code in my environment. It works well. however, I am using googletrans==4.0.0rc1. You may try to update googletrans and try again. if you still met some errors, please let me know.

Anyway, I will update this library with other method to avoid these issues.

GuillemGSubies commented 3 years ago

I had the same issue, it popped randomly so I guess it might have to be with a failed api call.

When creating a dataset with backtranslation, it pops fairly often.

jhkd-kevin commented 3 years ago

BackTranslation==0.2.2 I updated to googletrans googletrans==3.1.0a0.

Here's my code, but a different error is raised now.

def translate(src="en", tgt="fr", list_of_strings): 
     translator = BackTranslator()
     for s in list_of_strings:
         result = translator.translate(s, src=src, tmp=tgt)
         print(s, result.result_text)

I call this function once. The error that's raised is

TraECback (most reECnt call last): File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/googletrans/gtoken.py", line 63, in _update code = self.RE_TKK.search(r.text).group(1).replaEC('var ', '') AttributeError: 'NoneType' object has no attribute 'group' During handling of the above exECption, another exECption occurred: TraECback (most reECnt call last): File "backtranslate.py", line 51, in backTranslation.translate() File "backtranslate.py", line 38, in translate result = self.translator.translate(src_text, src="en", tmp=self.tgt_language) File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/BackTranslation/translation.py", line 64, in translate mid_text = self.translator.translate(text, src=src, dest=tmp) File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/googletrans/client.py", line 210, in translate data, response = self._translate(text, dest, src, kwargs) File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/googletrans/client.py", line 102, in _translate token = self.token_acquirer.do(text) File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/googletrans/gtoken.py", line 199, in do self._update() File "/home/EC/izaskr/anaconda3/lib/python3.6/site-packages/googletrans/gtoken.py", line 67, in _update raise ExECption('Could not find TKK token for this request.\nSee ssut/py-googletrans#234 for more details.') ExECption: Could not find TKK token for this request. See ssut/py-googletrans#234 for more details.

can I ask for you Complete code?

danielmarostica commented 2 years ago

I deleted the second condition on this line of client.py (googletrans lib) if r.status_code != 200 and self.raise_Exception: and it showed 429 error. That means API limit reached.

Try using the sleeping parameter.