Animenosekai / translate

A module grouping multiple translation APIs
GNU Affero General Public License v3.0
519 stars 60 forks source link

NoResult: No service has returned a valid result #67

Closed octner closed 2 years ago

octner commented 2 years ago

Hello,

Get "No service has returned a valid result" from time to time. Sometimes it can be fixed by explicitly specifying the languages in "translate", but sometimes it just doesn't. It refuses to translate specific columns from a data frame while works well with others.

NoResult                                  Traceback (most recent call last)
Input In [14], in <cell line: 3>()
      1 #protest translator
      2 #df['Title EN'] = df['Titlle'].apply(str).apply(lambda x: translator.translate(x, 'en', 'ru'))
----> 3 df['short_description EN'] = df['short_description'].apply(str).apply(lambda x: translator.translate(x, 'en', 'ru'))

File /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pandas/core/series.py:4138, in Series.apply(self, func, convert_dtype, args, **kwds)
   4136     else:
   4137         values = self.astype(object)._values
-> 4138         mapped = lib.map_infer(values, f, convert=convert_dtype)
   4140 if len(mapped) and isinstance(mapped[0], Series):
   4141     # GH 25959 use pd.array instead of tolist
   4142     # so extension arrays can be used
   4143     return self._constructor_expanddim(pd_array(mapped), index=self.index)

File pandas/_libs/lib.pyx:2467, in pandas._libs.lib.map_infer()

Input In [14], in <lambda>(x)
      1 #protest translator
      2 #df['Title EN'] = df['Title'].apply(str).apply(lambda x: translator.translate(x, 'en'))
----> 3 df['short_description EN'] = df['short_description'].apply(str).apply(lambda x: translator.translate(x, 'en', 'ru'))

File /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/translatepy/translate.py:135, in Translate.translate(self, text, destination_language, source_language)
    133         continue
    134 else:
--> 135     raise NoResult("No service has returned a valid result")

NoResult: No service has returned a valid result

Thanks

ZhymabekRoman commented 2 years ago

Hello, can you send example code in which exactly this error appears? Or can you please show the value of the translator variable?

octner commented 2 years ago
import pandas as pd
from translatepy.translators import GoogleTranslate

df = pd.read_csv("ru-en.csv")
translator = GoogleTranslate()
df['short_description EN'] = df['short_description'].apply(str).apply(lambda x: translator.translate(x, 'en', 'ru'))

Importing the entire translatepy gives the same result and does not change the behaviour/error message. The column is entirely in Russian and does not have any Null values.

Animenosekai commented 2 years ago
import pandas as pd
from translatepy.translators import GoogleTranslate

df = pd.read_csv("ru-en.csv")
translator = GoogleTranslate()
df['short_description EN'] = df['short_description'].apply(str).apply(lambda x: translator.translate(x, 'en', 'ru'))

Importing the entire translatepy gives the same result and does not change the behaviour/error message. The column is entirely in Russian and does not have any Null values.

I guess that there is quite a lot of data in ru-en.csv ?

Then, this might be why you hit the NoResult exception quite fast.

You should always use multiple translators, using translatepy.Translate, to avoid hitting the rate limits.

Animenosekai commented 2 years ago

(Also, don't run the translation every time you run the program and try to save the translated data)

octner commented 2 years ago
import pandas as pd
from translatepy.translators import GoogleTranslate

df = pd.read_csv("ru-en.csv")
translator = GoogleTranslate()
df['short_description EN'] = df['short_description'].apply(str).apply(lambda x: translator.translate(x, 'en', 'ru'))

Importing the entire translatepy gives the same result and does not change the behaviour/error message. The column is entirely in Russian and does not have any Null values.

I guess that there is quite a lot of data in ru-en.csv ?

Then, this might be why you hit the NoResult exception quite fast.

You should always use multiple translators, using translatepy.Translate, to avoid hitting the rate limits.

Thanks for the reply!

I do not think that the issue is related to the amount of data though. I ran the translation separately for each column (one of the columns had approx 5x times more text with the same number of rows), and it worked. However, it refuses to translate this one and throws this "NoResult" error.

Regarding the use of multiple translators: The first time I encountered this error, I was using multiple translators, but being more specific and picking GoogleTranslate worked for me and solved the issue. However, this time neither works. Maybe there is something problematic about this column, but I do not really see how it would be different from all the others that did get translated.

Animenosekai commented 2 years ago

How is the data at this column ? It seems weird that only this one encounters issues.

octner commented 2 years ago

How is the data at this column ? It seems weird that only this one encounters issues.

actually there was an empty line, it's just it was buried inside the csv file and for some reason I needed to find it manually myself + a couple of other strange rows. Deleting it fixed the issue. I guess can't have any empty lines in a pandas column?

Thanks for all your help!

Animenosekai commented 2 years ago

How is the data at this column ? It seems weird that only this one encounters issues.

actually there was an empty line, it's just it was buried inside the csv file and for some reason I needed to find it manually myself + a couple of other strange rows. Deleting it fixed the issue. I guess can't have any empty lines in a pandas column?

Thanks for all your help!

translatepy will try not to make any request when there is nothing to translate to avoid hitting rate limits