H zhutaoi, it is very nice for you to post your implementation. But I have some questions about it.
In your code, you defined your CBOW model as same as the author’s NGramLanguageModeler and change the number of context size during training. I believe this can work but I don’t think it matches the definition of the CBOW model, which is (A*sum(q) + b). I think you can throw the context number away and add your context together before feed in the linear layer.
I am not in the area of NLP so if I misunderstood the model or made a mistake, please point it out and I am happy to discuss with you.
Thanks!