Skip to content

Instantly share code, notes, and snippets.

@aria42
Created September 19, 2010 20:05
Show Gist options
  • Select an option

  • Save aria42/587075 to your computer and use it in GitHub Desktop.

Select an option

Save aria42/587075 to your computer and use it in GitHub Desktop.
(defn score-assign
"Log probability of assigning word to tag"
[state word-info tag]
(+ ;; Tag Prior
(log-prob (:tag-prior state) tag)
;; Feature Prob
(sum
(fn t1 [[k v]]
(log-prob (get-in state [:feat-distrs tag k]) v))
(:feats word-info))
;; Token Transition/Emission Prob
;; There's a subtely here in that we need to add one to the num-keys
;; for the emission distribution
(let [type-assigns (-> state :type-assigns (assoc (:word word-info) tag))
word-log-prob
(-> (:emission-distrs state)
(get tag)
(update-in [:num-keys] inc)
(log-prob (:word word-info)))]
(sum
(fn t2 [[[before after] count]]
(let [before-tag (type-assigns before) after-tag (type-assigns after)]
(* count
(+ word-log-prob
(-> state :trans-distrs (get before-tag) (log-prob tag))
(-> state :trans-distrs (get tag) (log-prob after-tag))))))
(-> word-info :contexts :counts)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment