Skip to content

Instantly share code, notes, and snippets.

@eob
Created November 24, 2010 19:05
Show Gist options
  • Save eob/714195 to your computer and use it in GitHub Desktop.
Save eob/714195 to your computer and use it in GitHub Desktop.
def initializeToCrfPosteriors = {
_Y = emptyY // Initialize to all 0s
require (_Y.size == _crfPotentials.size) // Santiy check: both are over tweets
for (tweet <- 0 until _crfPotentials.size) {
_forwardBackward.setInput(_crfPotentials(tweet))
val nodeMarginals = _forwardBackward.getNodeMarginals()
val nonBorderMarginals = nodeMarginals.slice(1, nodeMarginals.size - 1)
require (nonBorderMarginals.size == _Y(tweet).size) // Santiy check: both are over tokens
for (token <- 0 until nonBorderMarginals.size) {
require (nonBorderMarginals(token).size == _Y(tweet)(token).size) // Santiy check: both are over labels
for (label <- 0 until nonBorderMarginals(token).size) {
_Y(tweet)(token)(label) = nonBorderMarginals(token)(label)
}
}
}
checkOK // Ensure proper distribution
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment