In [1]:
import torch
from seq2seq.tools.inference import Translator
from torch.utils.model_zoo import load_url

In [2]:
checkpoint = load_url('https://dl.dropboxusercontent.com/s/x7no5myh06xs5fu/lstm-b67c3edb.pth?dl=0',
                        map_location=lambda storage, loc: storage)
model = Translator(checkpoint=checkpoint,
                               beam_size=8,
                               length_normalization_factor=1,
                               cuda=False)

In [3]:
model.translate('hello world')


Out[3]:
'hallo Welt'

In [4]:
model.translate('This seems to be working good')


Out[4]:
'Das scheint gut zu sein'

In [5]:
model.translate('may the force be with you')


Out[5]:
'kann die Kraft mit Ihnen sein'

In [6]:
model.translate("good morning to you all!")


Out[6]:
'good morning to you all!'

In [7]:
model.translate("I don't speak German")


Out[7]:
'Ich weiss Deutsch , dass ich Deutsch spreche .'

In [8]:
model.translate("those are some silly mistakes!")


Out[8]:
'Das sind einige dumm falsch !'

In [9]:
model.translate(["what is your favourite color?", "What is the airspeed velocity of an unladen Swallow?"])


Out[9]:
['Was ist dein Favorit ?',
 'Was ist die Luftgeschwindigkeit einer unladen Swallow-Seite ?']