tensor2tensor icon indicating copy to clipboard operation
tensor2tensor copied to clipboard

How to use pretrained embedding

Open vishalnus opened this issue 9 years ago • 8 comments

HI all, can someone please suggest how to use pre-trained embedding for machine translation task using Transformer. Do I need to change the source code for modalities.SymbolModality._get_weights for this?

vishalnus avatar Jul 20 '17 04:07 vishalnus

Hi, I was actually wondering how this could work with sub-tokens.

Like, if you download some pre-trained embeddings, I would expect to get one vector per token (token = whole word). If you use sub-tokens though, now you end up with a different 'unit' to work with.

Do you also see this issue, or am I missing something here?

mirkobronzi avatar Aug 08 '17 20:08 mirkobronzi

This is a problem not only with tokens, but generally with pre-trained embeddings: you need to make sure that they were pre-trained on data tokenized in exactly the same way as your data. Also, during your training, some embeddings will be moving away and some (rare words) will not, making them less and less useful. That's why we never made it a priority: you can just do 2-problem training instead and train your problem together with a language or translation model. This makes sure your data is tokenized in the same way, and since you're training concurrently, you're pulling all words to the same space all the time. I'd really always do this rather than use pre-trained embedding, the only problem is increased training cost.

lukaszkaiser avatar Aug 08 '17 21:08 lukaszkaiser

Thanks @lukaszkaiser - indeed, that makes sense.

I suppose I was mainly interested in this because of scenarios where you have not so much data for your problem - and in these cases I was interested in trying to pre-train embeddings on bigger data source.

As you say though, it is basically a trade-off between training everything on the same small amount of data, or pre-training embeddings on much more - but somehow different - data. (not sure which one will provide the best results - without running experiments to check it)

mirkobronzi avatar Aug 10 '17 13:08 mirkobronzi

@lukaszkaiser by 2-problem training do you mean training the randomly initialized word vectors and also the problem that is of interest?

rawmarshmellows avatar Aug 22 '17 11:08 rawmarshmellows

Yes. For example, you can just do --problems=translate_ende_wmt32k-translate_enfr_wmt32k and it will train a en-de translation together with en-fr translation, which has much more data so it'll also train the English word embeddings nicely.

lukaszkaiser avatar Aug 23 '17 01:08 lukaszkaiser

Same question. How to use pretrained embedding for other tasks.

guotong1988 avatar Oct 16 '18 10:10 guotong1988

@lukaszkaiser Could you please give me some instructions about how to do the 2-problem training? Do you mean that we need to train the word embedding first?

guotong1988 avatar Oct 16 '18 10:10 guotong1988

I find it in readme:

Models can be used with any dataset and input mode (or even multiple); all modality-specific processing (e.g. embedding lookups for text tokens) is done with Modality objects, which are specified per-feature in the dataset/task specification.

guotong1988 avatar Oct 16 '18 10:10 guotong1988