Language translation using TorchText (PyTorch)
I have recently started with ML/DL using PyTorch. The following pytorch example explains how we can train a simple model for translating from German to English.

https://pytorch.org/tutorials/beginner/torchtext_translation_tutorial.html

However I am confused on how to use the model for running inference on custom input. From my understanding so far :

1) We will need to save the "vocab" for both German (input) and English(output) [using torch.save()] so that they can be used later for running predictions.

2) At the time of running inference on a German paragraph, we will first need to convert the German text to tensor using the german vocab file.

3) The above tensor will be passed to the model's forward method for translation

4) The model will again return a tensor for the destination language i.e., English in current example.

5) We will use the English vocab saved in first step to convert this tensor back to English text.

Questions:

1) If the above understanding is correct, can the above steps be treated as a generic approach for running inference on any language translation model if we know the source and destination language and have the vocab files for the same? Or can we use the vocab provided by third party libraries like spacy?

2) How do we convert the output tensor returned from model back to target language? I couldn't find any example on how to do that. The above blog explains how to convert the input text to tensor using source-language vocab.

I could easily find various examples and detailed explanation for image/vision models but not much for text.

Yes globally what you are saying is correct, and of course you can any vocab, e.g. provided by spacy. To convert a tensor into natrual text, one of the most used thechniques is to keep both a dict that maps indexes to words and an other dict that maps words to indexes, the code below can do this:
tok2idx = defaultdict(lambda: 0)
idx2tok = {}

for seq in sequences:
    for tok in seq:
        if not tok in tok2idx:
            tok2idx[tok] = index
            idx2tok[index] = tok
            index += 1

Here sequences is a list of all the sequences (i.e. sentences in your dataset). You can change the model easily if you have only a list of words or tokens, by only keeping the inner loop.
