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 top 5 accuracy metric #718

Merged
merged 6 commits into from Dec 16, 2020
Merged

Conversation

brettkoonce
Copy link
Contributor

ping @xihui-wu

TrainingLoop/Metrics.swift Outdated Show resolved Hide resolved
TrainingLoop/Metrics.swift Outdated Show resolved Hide resolved
TrainingLoop/Metrics.swift Outdated Show resolved Hide resolved
Comment on lines 133 to 136
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, *))
Copy link
Contributor

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)

Copy link
Contributor Author

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!

@xihui-wu xihui-wu self-requested a review December 16, 2020 18:07
Copy link
Contributor

@xihui-wu xihui-wu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants