Skip to content

Commit

Permalink
evaluate BIFI P@100
Browse files Browse the repository at this point in the history
  • Loading branch information
breandan committed Mar 26, 2024
1 parent a76e0b2 commit e366985
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ fun main() {
MAX_TOKENS = 79
// MAX_RADIUS = 3
CFG_THRESH = 10_000
evaluateBarHillelRepairOnStackOverflow()
// evaluateBarHillelRepairOnStackOverflow()
// evaluateSeq2ParseRepair()
// evaluateBIFIRepair()
evaluateBIFIRepair()
}

fun readPCFG3() =
Expand Down Expand Up @@ -350,22 +350,25 @@ fun evaluateBIFIRepair() {
val levDist = levenshtein(toRepair, humanRepair)

// Adjust for class imbalance between Levenshtein distances
// val rand = Random.nextDouble()
// when(levDist) {
// 1 -> if (rand > 0.02) return@forEach
// 2 -> if (rand > 0.04) return@forEach
// 3 -> if (rand > 0.1) return@forEach
// }
val rand = Random.nextDouble()
when (levDist) {
1 -> if (rand > 0.02) return@forEach
2 -> if (rand > 0.04) return@forEach
3 -> if (rand > 0.1) return@forEach
}

val bifiFix = bifiFix(toRepair)[0]
println("BROKEN: $toRepair")
val bifiFixes = bifiFix(toRepair, 100)

bifiFixes.take(10).forEachIndexed { i, it ->
println("BIFI-$i: ${levenshteinAlign(toRepair, it).paintANSIColors()}")
}

println("BRKE: $toRepair")
println("BIFI: ${levenshteinAlign(toRepair, bifiFix).paintANSIColors()}")
println("TRUE: ${levenshteinAlign(toRepair, humanRepair).paintANSIColors()}")
println("GROUND: ${levenshteinAlign(toRepair, humanRepair).paintANSIColors()}")

P_1ByLevDist.getOrPut(length to levDist) { S2PMetrics() }.total++

if (bifiFix == humanRepair) { P_1ByLevDist.getOrPut(length to levDist) { S2PMetrics() }.top1++ }
if (humanRepair in bifiFixes) { P_1ByLevDist.getOrPut(length to levDist) { S2PMetrics() }.top1++ }
println(P_1ByLevDist.summarizeLenAndDist())
println()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ fun seq2parseFix(
fun bifiFix(
brokenCode: String,
k: Int = 1,
prefix: String = "http://127.0.0.1:5000/api/topk?k=$k&bifi_translate="
prefix: String = "http://127.0.0.1:5000/api/text?k=$k&bifi_topk="
): List<String> =
try {
URL("$prefix${URLEncoder.encode(brokenCode,"UTF-8")}").readText()
Expand Down

0 comments on commit e366985

Please sign in to comment.