Skip to content

Instantly share code, notes, and snippets.

@harisankarh
Created March 12, 2018 16:08
Show Gist options
  • Save harisankarh/ddc9418657ae78d64c31a7fc304403a9 to your computer and use it in GitHub Desktop.
Save harisankarh/ddc9418657ae78d64c31a7fc304403a9 to your computer and use it in GitHub Desktop.
SELECT *,
(sum_correct_logprobs/num_examples) + 1e-3*(0.5*(w_00*w_00 + w_01*w_01 + w_10*w_10 + w_11*w_11) + 0.5*(w2_00*w2_00 + w2_01*w2_01 + w2_10*w2_10 + w2_11*w2_11)) AS loss
FROM
(SELECT *,
SUM(correct_logprobs) OVER () sum_correct_logprobs,
COUNT(1) OVER () num_examples
FROM
(SELECT *,
(CASE
WHEN y = 0 THEN -1*LOG(probs_0)
ELSE -1*LOG(probs_1)
END) AS correct_logprobs
FROM {inner subquery}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment