f31488d65a98107e03f2045f3c5e2f927dab067d,03-wordemb-pytorch/wordemb-skip.py,,calc_sent_loss,#,73

Before Change


                context_id = sent[i + direction * j] if 0 <= i + direction * j < len(sent) else S
                context = torch.tensor([context_id]).type(type)   // Tensor for context word
                loss = model(c, context)
                if not inference:
                    // Back prop while training only
                    optimizer.zero_grad()
                    loss.backward()
                    optimizer.step()
                total_loss += loss.data.cpu().item()
    return total_loss

After Change


    // as we need to predict the eos as well, the future window at that point is N past it

    // Step through the sentence
    losses = []
    for i, word in enumerate(sent):
        for j in range(1, N + 1):
            for direction in [-1, 1]:
                c = torch.tensor([word]).type(type)  // This is tensor for center word
                context_id = sent[i + direction * j] if 0 <= i + direction * j < len(sent) else S
                context = torch.tensor([context_id]).type(type)   // Tensor for context word
                logits = model(c)
                loss = criterion(logits, context)
                losses.append(loss)
    return torch.stack(losses).sum()


MAX_LEN = 100
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 4

Instances


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: THUNLP-MT/THUMT
Commit Name: 62d2ea56ae4a090aa68baf133137982a836700bd
Time: 2018-01-25
Author: playinf@stu.xmu.edu.cn
File Name: thumt/utils/search.py
Class Name:
Method Name: create_inference_graph


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