Skip to content

Instantly share code, notes, and snippets.

@Cowa
Created October 21, 2015 19:53
Show Gist options
  • Save Cowa/4b47b3b0e6d46a6cfa73 to your computer and use it in GitHub Desktop.
Save Cowa/4b47b3b0e6d46a6cfa73 to your computer and use it in GitHub Desktop.
val ngramWithProbability = ngramWithCount.map { case (k, v) =>
(k, v.toDouble / ngramWithCount.filterKeys(_.take(n - 1) == k.take(n - 1)).values.sum)
}
// Map(List(eating, the) -> 1.0, List(blue, sky) -> 1.0, List(red, koala) -> 1.0, List(near, the) -> 1.0, List(The, blue) -> 1.0, List(the, sky) -> 0.5, List(koala, eating) -> 1.0, List(sky, is) -> 1.0, List(the, red) -> 0.5, List(is, near) -> 1.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment