def black_out(x, t, W, samples):
 batch_size = x.shape[0]
 neg_emb = embed_id.embed_id(samples, W)
 neg_y = matmul.batch_matmul(neg_emb, x)
 neg_y = reshape.reshape(neg_y, neg_y.shape[:(-1)])
 pos_emb = expand_dims.expand_dims(embed_id.embed_id(t, W), 1)
 pos_y = matmul.batch_matmul(pos_emb, x)
 pos_y = reshape.reshape(pos_y, pos_y.shape[:(-1)])
 logz = logsumexp.logsumexp(concat.concat([pos_y, neg_y]), axis=1)
 (blogz, bneg_y) = broadcast.broadcast(reshape.reshape(logz, (batch_size, 1)), neg_y)
 ny = exponential.log((1 - exponential.exp((bneg_y - blogz))))
 py = reshape.reshape(pos_y, (batch_size,))
 loss = ((py - logz) + _sum.sum(ny, axis=1))
 return ((- _sum.sum(loss)) / batch_size)

def black_out ( x , t , W , samples ) : batch_size = x . shape [ 0 ] neg_emb = embed_id . embed_id ( samples , W ) neg_y = matmul . batch_matmul ( neg_emb , x ) neg_y = reshape . reshape ( neg_y , neg_y . shape [ : ( - 1 ) ] ) pos_emb = expand_dims . expand_dims ( embed_id . embed_id ( t , W ) , 1 ) pos_y = matmul . batch_matmul ( pos_emb , x ) pos_y = reshape . reshape ( pos_y , pos_y . shape [ : ( - 1 ) ] ) logz = logsumexp . logsumexp ( concat . concat ( [ pos_y , neg_y ] ) , axis = 1 ) ( blogz , bneg_y ) = broadcast . broadcast ( reshape . reshape ( logz , ( batch_size , 1 ) ) , neg_y ) ny = exponential . log ( ( 1 - exponential . exp ( ( bneg_y - blogz ) ) ) ) py = reshape . reshape ( pos_y , ( batch_size , ) ) loss = ( ( py - logz ) + _sum . sum ( ny , axis = 1 ) ) return ( ( - _sum . sum ( loss ) ) / batch_size )
blackout loss function .