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

Fix autofeature on explicit judgements #992

Merged
merged 2 commits into from
Apr 3, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import ai.metarank.model.Event.{InteractionEvent, ItemEvent, RankingEvent, UserE
case class EventCountStat(items: Int = 0, users: Int = 0, rankings: Int = 0, ints: Int = 0, intsWithRanking: Int = 0) {
def total = items + users + rankings + ints
def refresh(event: Event): EventCountStat = event match {
case e: ItemEvent => copy(items = items + 1)
case e: UserEvent => copy(users = users + 1)
case e: RankingEvent => copy(rankings = rankings + 1)
case e: ItemEvent => copy(items = items + 1)
case e: UserEvent => copy(users = users + 1)
case e: RankingEvent => {
val labels = e.items.toList.count(_.label.isDefined)
copy(rankings = rankings + 1, intsWithRanking = intsWithRanking + labels)
}
case e: InteractionEvent =>
copy(ints = ints + 1, intsWithRanking = intsWithRanking + (if (e.ranking.isDefined) 1 else 0))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ package ai.metarank.main.autofeature.model
import ai.metarank.feature.NumberFeature.NumberFeatureSchema
import ai.metarank.main.command.autofeature.{EventCountStat, EventModel}
import ai.metarank.main.command.autofeature.model.LambdaMARTConfigGenerator
import ai.metarank.model.Event.RankItem
import ai.metarank.model.FieldName
import ai.metarank.model.FieldName.EventType.Item
import ai.metarank.model.Identifier.ItemId
import ai.metarank.model.Key.FeatureName
import ai.metarank.model.ScopeType.ItemScopeType
import ai.metarank.util.TestRankingEvent
import cats.data.NonEmptyList
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

Expand All @@ -31,4 +35,18 @@ class LambdaMARTConfigGeneratorTest extends AnyFlatSpec with Matchers {
val conf = LambdaMARTConfigGenerator.maybeGenerate(em, features)
conf should be(empty)
}

it should "accept explicit relevance judgments" in {
val event = TestRankingEvent(List("p1")).copy(items =
NonEmptyList.of(
RankItem(ItemId("p1"), label = Some(1)),
RankItem(ItemId("p2"), label = Some(0))
)
)
val stat = (0 until 100).map(_ => event).foldLeft(EventCountStat())((acc, next) => acc.refresh(next))
val em = EventModel(eventCount = stat)
val features = List(NumberFeatureSchema(FeatureName("foo"), FieldName(Item, "foo"), ItemScopeType))
val conf = LambdaMARTConfigGenerator.maybeGenerate(em, features)
conf shouldNot be(empty)
}
}