PIXELBANKv9.1.0
Menu

Apply Softmax for Predictions

Problem Statement

Convert raw model outputs (logits) into probabilities using Softmax.

Background

Neural networks output raw scores called logits. To interpret these as probabilities, you need to apply Softmax, which converts them to values in [0, 1] that sum to 1 across classes.

Your Task

Write a function apply_softmax(logits) that takes a batch of logits and returns statistics about the resulting probability distribution.

Output Format

Return a dictionary with keys: "probabilities_sum" (list of floats, 1 decimal — should each be ~1.0), "predictions" (list of ints — predicted class per sample), "max_probs" (list of floats, 2 decimals — confidence per sample).

Example:

Input:
logits = [[2.0, 1.0, 0.1], [0.5, 2.5, 0.3]]
Output:
{'probabilities_sum': [1.0, 1.0], 'predictions': [0, 1], 'max_probs': [0.66, 0.8]}
Reasoning:

Softmax normalizes to probabilities, argmax gives predicted class

Constraints:

  • Use nn.Softmax(dim=1)
  • Round probabilities appropriately
  • Handle batch dimension correctly
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Apply Softmax for Predictions - Easy | PixelBank