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 top 5 accuracy metric #718
Conversation
c79ac9b
to
f664701
Compare
3dfa909
to
f40f408
Compare
TrainingLoop/Metrics.swift
Outdated
let topK = _Raw.inTopKV2(predictions: predictions, targets: labels, k: Tensor<Int32>(k)) | ||
let correctCount = Tensor<Int32>(topK).sum() | ||
correctGuessCount += Int32(correctCount.scalar ?? 0) | ||
totalGuessCount += Int32(labels.shape.reduce(1, *)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should break GPT2-WikiText2. We may want to make the predictions and labels to the conforming shape before calling inTopKV2. Can you try the following and run test swift run -c release GPT2-Wiki2Text2
?
let predictionsReshaped = predictions.reshaped(
to: [predictions.shape.dropLast().reduce(1, *), predictions.shape.last!])
let labelsReshaped = labels.reshaped(to: [labels.shape.reduce(1, *)])
correctGuessCount += Int32(
Tensor<Int32>(
_Raw.inTopKV2(
predictions: predictionsReshaped, targets: labelsReshaped, k: Tensor<Int32>(k))).sum()
.scalar ?? 0)
totalGuessCount += Int32(labelsReshaped)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xihui-wu tweaked the last line slightly, works here w/ GPT2-Wiki2Text2 + LeNet-MNIST!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
ping @xihui-wu