Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add err scorer #1162

Merged
merged 16 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions db/migrate/20250107195202_add_err.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class AddErr < ActiveRecord::Migration[8.0]
def change
Scorer.where(name: 'ERR@10').first_or_create(
scale: (0..3).to_a,
scale_with_labels: {"0":"Poor","1":"Fair","2":"Good","3":"Perfect"},
show_scale_labels: true,
code: File.readlines('./db/scorers/[email protected]','\n').join('\n'),
name: 'ERR@10',
communal: true
)
end
end
2 changes: 1 addition & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions db/scorers/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
let k = 10 // @Rank
// if less than K results, need to reduce K now or final score is too low
k = numReturned() < k ? numReturned() : k
const scores = Array(k);
const missing_rating = 0; // pessimistic assumption
let i = 0
for (i = 0; i < k; i++) {
if (hasDocRating(i)) {
scores[i] = (docRating(i));
} else {
scores[i] = missing_rating;
}
}

function gain(grade, maxGrade) {
return (Math.pow(2,grade) - 1.0)/Math.pow(2,maxGrade)
}
function err(lst) {
let ERR = 0.0
let trust = 1.0
for (i = 0; i < lst.length; i++) {
const rank = i + 1.0
// max is the maximum possible rating for the scorer.
const pUseful = gain(lst[i], max)
const disc = pUseful/rank
ERR = ERR + trust * disc
trust = trust * (1.0 - pUseful)
}
return ERR
}
setScore(err(scores))
9 changes: 9 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@
communal: true
)

Scorer.where(name: 'ERR@10').first_or_create(
scale: (0..3).to_a,
scale_with_labels: {"0":"Poor","1":"Fair","2":"Good","3":"Perfect"},
show_scale_labels: true,
code: File.readlines('./db/scorers/[email protected]','\n').join('\n'),
name: 'ERR@10',
communal: true
)

SelectionStrategy.where(name: 'Single Rater').first_or_create(
name: 'Single Rater',
description: 'A single rating for each query/doc pair is all that is required. The fastest way to get a lot of ratings, with lower quality.'
Expand Down
Loading