I got an implementation of CBOW here. Please try to finish it yourself until check others!

  
      github.com
  
  
    towerjoo/pytorch-playground/blob/master/official_tut/cbow.py 398
import torch
import torch.autograd as autograd
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim

torch.manual_seed(1)

CONTEXT_SIZE = 2  # 2 words to the left, 2 to the right
raw_text = """We are about to study the idea of a computational process.
Computational processes are abstract beings that inhabit computers.
As they evolve, processes manipulate other abstract things called data.
The evolution of a process is directed by a pattern of rules
called a program. People create programs to direct processes. In effect,
we conjure the spirits of the computer with our spells.""".split()
word_to_ix = {}
for i, word in enumerate(raw_text):
    if word not in word_to_ix:
        word_to_ix[word] = len(word_to_ix)
data = []


  This file has been truncated. show original