--showProbs = HM.foldrWithKey (\(e,f) a acc -> if a>0.001 then (unwords [BS2.unpack f,BS2.unpack e, (printf "%.4f\n" a)])++acc else acc) []

perplexity :: Corpus -> Probs -> Double
perplexity corpus probs = foldr (\k acc -> acc - (logBase 2 (prob k))) 0 corpus
  where prob (f,e) = foldr (\(x, y) ac -> ac * (probs HM.! (y,x))) 1 $ zip f e
perplexity :: Corpus -> Probs -> Double
perplexity corpus probs = foldr (\k acc -> acc - (logBase 2 (prob k))) 0 corpus
  where prob (f,e) = foldr (\(x, y) ac -> ac * (probs HM.! (y,x))) 1 $ zip f e
perplexity corpus probs = foldr (\k acc -> acc - (logBase 2 (prob k))) 0 corpus
  where prob (f,e) = foldr (\(x, y) ac -> ac * (probs HM.! (y,x))) 1 $ zip f e