Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save aria42/587068 to your computer and use it in GitHub Desktop.
(defn obs-transitions
"if we set word to tag, we update the transition tag counts
from all context usages of word by weight amount"
[trans-distrs type-assigns word-info tag weight]
(reduce
(fn [res [[before after] count]]
(let [type-assigns (assoc type-assigns (:word word-info) tag)
before-tag (type-assigns before)
after-tag (type-assigns after)]
(-> res
;; Observe P(tag | tag-assign(before))
(update-in [before-tag] observe tag (* count weight))
;; Observe P(tag-assign(after) | tag)
(update-in [tag] observe after-tag (* count weight)))))
trans-distrs
(-> word-info :contexts :counts)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment