Created
September 19, 2010 20:05
-
-
Save aria42/587075 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| (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