Skip to content

Commit

Permalink
eval hybrid pcfg ngram reranker
Browse files Browse the repository at this point in the history
  • Loading branch information
breandan committed Jul 9, 2024
1 parent 09fdc4c commit 2d9ef60
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ class PTree(val root: String = ".ε", val branches: List<Π2A<PTree>> = listOf()
fun samplePCFG5(pcfgTable: Map<Int, Int>, upUp: Int = 0, upLeft: Int = 0, upRight: Int = 0): Σᐩ {
if (isLeaf) return epsStr
val probs = triples.map {
/** See [Tree.quintuples] */
val hash = hash(upUp, upLeft, upRight, it.first, it.second)
(pcfgTable[hash] ?: 1)
// .also { if(Random.nextInt(10000) == 3) if (it == 1) println("$hash Miss"); else println("$hash Hit") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ open class MarkovChain<T>(

// Computes perplexity of a sequence normalized by sequence length (lower is better)
fun score(seq: List<T?>): Double =
if (memory < seq.size) -(scorePrefix + seq + scoreSuffix).windowed(memory)
.map { (getAtLeastOne(it) + 1) / (getAtLeastOne(it.dropLast(1) + null) + dictionary.size) }
.sumOf { ln(it) } / seq.size
if (memory < seq.size)
-(scorePrefix + seq + scoreSuffix).windowed(memory).map {
(getAtLeastOne(it) + 1) / (getAtLeastOne(it.dropLast(1) + null) + dictionary.size)
}.sumOf { ln(it) } / seq.size
else (seq.sumOf { counter.rawCounts.getEstimate(it) } + 1).toDouble() / counter.total.toDouble()

operator fun get(vararg variables: T?): Double =
Expand Down

0 comments on commit 2d9ef60

Please sign in to comment.