'Step 3 + 4: define the model + the loss function'

def _create_loss(self):

    with tf.device('/cpu:0'):
        with tf.name_scope('loss'):
            embed = tf.nn.embedding_lookup(self.embed_matrix, self.center_words, name='embed')
            nce_weight = tf.Variable(tf.truncated_normal([self.vocab_size, self.embed_size], stddev=(1.0 / (self.embed_size ** 0.5))), name='nce_weight')
            nce_bias = tf.Variable(tf.zeros([VOCAB_SIZE]), name='nce_bias')
            self.loss = tf.reduce_mean(tf.nn.nce_loss(weights=nce_weight, biases=nce_bias, labels=self.target_words, inputs=embed, num_sampled=self.num_sampled, num_classes=self.vocab_size), name='loss')
