huggingface / pytorch-openai-transformer-lm

🐥A PyTorch implementation of OpenAI's finetuned transformer language model with a script to import the weights pre-trained by OpenAI
MIT License
1.51k stars 285 forks source link

Using negative index to reshape the input tensor. #8

Closed rodgzilla closed 6 years ago

rodgzilla commented 6 years ago

Hi,

This is a really simple patch that allows more flexibility with the size of the input tensor.

In the code example, the task used for the finetuning of the model takes a pair of sentences as input so the tensor is of shape (batch, sentence index, sequence length, data or position index). Now let's say I want to use the model to do language modelling, I would like my input shape to simply be (batch, sequence_length, data or position index) which is not possible with the current version of the code.

My commit fixes this. By using negative indices, the model can now take both tensor shapes as input.

thomwolf commented 6 years ago

Nice indeed, thanks!