f31488d65a98107e03f2045f3c5e2f927dab067d,03-wordemb-pytorch/wordemb-cbow.py,,calc_sent_loss,#,71

Before Change


    padded_sent = [S] * N + sent + [S] * N

    // Step through the sentence
    total_loss = 0
    for i in range(N, len(sent) + N):
        // c is the context vector
        c = torch.tensor(padded_sent[i - N:i] + padded_sent[i + 1:i + N + 1]).type(type)
        t = torch.tensor([padded_sent[i]]).type(type) // This is the target vector
        log_prob = model(c)
        loss = criterion(log_prob, t)   // loss for predicting target from context vector
        if not inference:
            // Back prop while training only
            optimizer.zero_grad()
            loss.backward()
            optimizer.step()
        total_loss += loss.data.cpu().item()
    return total_loss


MAX_LEN = 100

After Change


        logits = model(c)
        loss = criterion(logits, t)   // loss for predicting target from context vector
        losses.append(loss)
    return torch.stack(losses).sum()


MAX_LEN = 100
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 4

Non-data size: 5

Instances


Project Name: neubig/nn4nlp-code
Commit Name: f31488d65a98107e03f2045f3c5e2f927dab067d
Time: 2019-01-18
Author: mysteryvaibhav@gmail.com
File Name: 03-wordemb-pytorch/wordemb-cbow.py
Class Name:
Method Name: calc_sent_loss


Project Name: neubig/nn4nlp-code
Commit Name: f31488d65a98107e03f2045f3c5e2f927dab067d
Time: 2019-01-18
Author: mysteryvaibhav@gmail.com
File Name: 03-wordemb-pytorch/wordemb-skip.py
Class Name:
Method Name: calc_sent_loss


Project Name: PIQuIL/QuCumber
Commit Name: 274ec230054107d30bb91de43ec42b7393170928
Time: 2019-07-17
Author: emerali@users.noreply.github.com
File Name: tests/grads_utils.py
Class Name: PosGradsUtils
Method Name: compute_numerical_NLL


Project Name: PIQuIL/QuCumber
Commit Name: 274ec230054107d30bb91de43ec42b7393170928
Time: 2019-07-17
Author: emerali@users.noreply.github.com
File Name: tests/grads_utils.py
Class Name: PosGradsUtils
Method Name: compute_numerical_kl