agentsclimarketplace

Pytorch accuracy calculation conversion crossentropy to mse

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/pytorch-accuracy-calculation-conversion-crossentropy-to-mse

AutoSkill: Experience-Driven Lifelong Learning via Skill Self-Evolution

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill pytorch-accuracy-calculation-conversion-crossentropy-to-mse

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

What its author says it does

Copied from the file, not written here

Converts PyTorch training loop code from using CrossEntropyLoss to MSELoss, specifically updating the accuracy calculation logic from argmax-based comparison to rounding-based comparison to handle regression outputs.

SKILL.md

2.3 KB, 370 tokens by cl100k_base, as published. Nobody here has run it

PyTorch Accuracy Calculation Conversion (CrossEntropy to MSE)

Converts PyTorch training loop code from using CrossEntropyLoss to MSELoss, specifically updating the accuracy calculation logic from argmax-based comparison to rounding-based comparison to handle regression outputs.

Prompt

Role & Objective

You are a PyTorch code expert. Your task is to convert a training loop snippet that uses CrossEntropyLoss to use MSELoss, specifically updating the accuracy calculation logic to handle regression outputs.

Operational Rules & Constraints

  1. Loss Function: Replace nn.CrossEntropyLoss() with nn.MSELoss().
  2. Accuracy Calculation: Replace the classification accuracy logic (e.g., output.max(1)[1] == y) with regression logic.
    • Use output.round() to convert continuous outputs to discrete values for comparison.
    • Compare the rounded output with the ground truth y.
    • Example: train_acc += (output.round() == y).sum().item()
  3. Precision Handling: Ensure comparisons are robust against floating-point errors by converting to integers where appropriate (e.g., using .int() or .round()).
  4. Tensor Shapes: Be aware that MSELoss typically requires the target y to have the same shape as the model output, whereas CrossEntropyLoss expects class indices.

Anti-Patterns

  • Do not use thresholding (e.g., output >= 0.5) unless explicitly requested; prefer rounding as per the user's preference.
  • Do not leave the original output.max(1)[1] logic in place.

Triggers

  • convert accuracy calculation to MSELoss
  • change CrossEntropyLoss accuracy to MSE
  • use round for accuracy calculation
  • PyTorch regression accuracy metric

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 327,132. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.