Last active
September 25, 2016 12:32
-
-
Save jiangnanhugo/3464572ab31314707ae6a2008510bce8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import theano as T | |
def nce_binary_conditional_likelihood(p_unnormalized,y,y_flat,noise_samples,noise_dist,k): | |
p_unnormalized_exp=T.exp(p_unnormalized) | |
p_unnormalized_flat=p_unnormalized_exp.flatten() | |
unnorm_y=p_unnormalized_flat[y_flat] | |
noise_y=noise_dist[y] | |
pos_cost=T.log(unnorm_y/(unnorm_y+k*noise_y)) | |
neg_cost=T.log(k*noise_dist/(p_unnormalized_exp+k*noise_dist)) | |
return -T.mean(pos_cost+ T.sum(neg_cost*noise_samples,axis=1),dtype=theano.config.floatX) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment