Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About code #1

Open
N-Kingsley opened this issue Jan 14, 2019 · 1 comment
Open

About code #1

N-Kingsley opened this issue Jan 14, 2019 · 1 comment

Comments

@N-Kingsley
Copy link

Hi, I want to ask some about your code.
In 176-188 lines in model.py, why to do this:
if start < self.window_size:
d = self.window_size - start
score[i, j, :d] = epsilon
if end > li + self.window_size:
d = (li + self.window_size) - end
score[i, j, d:] = epsilon

Shouldn’t it judge whether the selected window is beyond length?

@ChrisFugl
Copy link
Collaborator

Hi @N-Kingsley. You are right, that this part of the code should determine if the selected window is beyond the input sentence length - and that is what it does. The reason that we enforce the window to be within the interval [window_size, li + window_size] (rather than [0, li]) is that we have padded the input sentence on the left and on the right as a performance optimisation. (Doing so allows us to do local attention in batches.) We do not want the model to pay attention to the padded sides of the input sentence and so we set those attention scores to "epsilon" before applying a softmax on the scores.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants