Skip to content

Commit 9484a2a

Browse files
authored
Update README.md
1 parent d5fa7d9 commit 9484a2a

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

README.md

+16-2
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,21 @@ It would be ideal to train using Teacher Forcing [only some of the time](https:/
470470

471471
__Can I use pretrained word embeddings (GloVe, CBOW, skipgram, etc.) instead of learning them from scratch?__
472472

473-
Yes, you could, with the `load_pretrained_embeddings()` method in the `Decoder`. You could also choose to fine-tune (or not) with the `fine_tune_embeddings()` method.
473+
Yes, you could, with the `load_pretrained_embeddings()` method in the `Decoder` class. You could also choose to fine-tune (or not) with the `fine_tune_embeddings()` method.
474+
475+
After creating the Decoder in [`train.py`](<https://github.com/sgrvinod/a-PyTorch-Tutorial-to-Image-Captioning/blob/master/eval.py), you should provide the pretrained vectors to `load_pretrained_embeddings()` stacked in the same order as in the `word_map`. For words that you don't have pretrained vectors for, like <start>, you can initialize embeddings randomly like we did in `init_weights()`. I recommend fine-tuning to learn more meaningful vectors for these randomly initialized vectors.
476+
477+
```python
478+
decoder = DecoderWithAttention(attention_dim=attention_dim,
479+
embed_dim=emb_dim,
480+
decoder_dim=decoder_dim,
481+
vocab_size=len(word_map),
482+
dropout=dropout)
483+
decoder.load_pretrained_embeddings(pretrained_embeddings)
484+
decoder.fine_tune_embeddings(True) # or False
485+
```
486+
487+
Also make sure to change the `embed_dim` parameter to the size of your pre-trained embeddings. This should automatically adjust the input size of the decoder LSTM to accomodate them.
474488

475489
---
476490

@@ -486,4 +500,4 @@ With the release of PyTorch `0.4`, wrapping tensors as `Variable`s is no longer
486500

487501
__How do I compute all BLEU (i.e. BLEU-1 to BLEU-4) scores during evaluation?__
488502

489-
You'd need to modify the code in [eval.py](<https://github.com/sgrvinod/a-PyTorch-Tutorial-to-Image-Captioning/blob/master/eval.py#L171>) to do this. Please see [this excellent answer](<https://github.com/sgrvinod/a-PyTorch-Tutorial-to-Image-Captioning/issues/37#issuecomment-455924998>) by [kmario23](<https://github.com/kmario23>) for a clear and detailed explanation.
503+
You'd need to modify the code in [`eval.py`](<https://github.com/sgrvinod/a-PyTorch-Tutorial-to-Image-Captioning/blob/master/eval.py) to do this. Please see [this excellent answer](<https://github.com/sgrvinod/a-PyTorch-Tutorial-to-Image-Captioning/issues/37#issuecomment-455924998>) by [kmario23](<https://github.com/kmario23>) for a clear and detailed explanation.

0 commit comments

Comments
 (0)