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

Doubt in indexing of labels #2

Open
vardaan123 opened this issue Jan 15, 2020 · 1 comment
Open

Doubt in indexing of labels #2

vardaan123 opened this issue Jan 15, 2020 · 1 comment

Comments

@vardaan123
Copy link

In https://github.com/chnsh/BERT-NER-CoNLL/blob/master/model.py#L25, shouldn't it be labels[mask.nonzero().squeeze(1)] instead of labels[mask]? If you do labels[mask], then mask is either 0 or 1, which means you are selecting the 1st or 2nd dim. of labels. Similarly for L18 embedding[mask]

@shivaat
Copy link

shivaat commented Jan 22, 2020

As far as I understand, mask is not 0 or 1 here. mask is a tensor, the same size as sequence length, with values True and False: True for valid labels, False for invalid labels (e.g. for [CLS], [SEP], "pad" tokens and the tokens that are the results of BERT word piece tokenisation). So this line returns the values of the labels/embedding tensors in those positions for which the entry in mask is True.
A toy example with numpy array looks like the following:
mask = np.array([False, True, False, True])
labels = np.array([1,2,3,4])
labels[mask] -> array([2, 4])

Although, I suppose your code snippet labels[mask.nonzero().squeeze(1)] does the same thing here.

In https://github.com/chnsh/BERT-NER-CoNLL/blob/master/model.py#L25, shouldn't it be labels[mask.nonzero().squeeze(1)] instead of labels[mask]? If you do labels[mask], then mask is either 0 or 1, which means you are selecting the 1st or 2nd dim. of labels. Similarly for L18 embedding[mask]

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