Comments (2)
I followed what tensor2tensor did.
https://github.com/tensorflow/tensor2tensor/blob/v.1.12.0/tensor2tensor/models/transformer.py#L1209
Actually, it does not change the size like that. line 282 removes the last word in the sequence, but it also adds a padding value to the first position of the sequence in line 283. When I insert print functions, output looks like this:
print(target_embedded.size()) # torch.Size([30, 33, 512])
target_embedded = target_embedded[:, :-1]
print(target_embedded.size()) # torch.Size([30, 32, 512])
target_embedded = F.pad(target_embedded, (0, 0, 1, 0))
print(target_embedded.size()) # torch.Size([30, 33, 512])
The reason why we remove the last word is that we don't need to predict the word after the last word. For example, let's think about this case that we use "abcd"
as an input. Then, we have to predict a
from nothing, and we have nothing to predict from d
. For this, we add a padding value in line 283, and remove the last word in line 282 to eliminate unnecessary computations.
input output
| <pad> | --(predict)--> | a |
| a | --(predict)--> | b |
| b | --(predict)--> | c |
| c | --(predict)--> | d |
| d |
from transformer-pytorch.
Got it and appreciate your quick reply!
from transformer-pytorch.
Related Issues (9)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from transformer-pytorch.