Conversation
|
|
/describe |
User descriptionAdd tf_losses.py file which initializes edited version of AsymmetricLoss.forward() function for use with tensorflow. PR TypeEnhancement Description
Diagram Walkthroughflowchart LR
A["ASL Wrapper Function"] -- "gamma_neg, gamma_pos" --> B["ASL_func"]
B -- "logits, targets" --> C["Probability Calculation"]
C --> D["Cross Entropy Loss"]
D --> E["Asymmetric Focusing"]
E --> F["Weighted Loss Output"]
|
| Relevant files | |||
|---|---|---|---|
| Enhancement |
|
|
/agentic_review |
Code Review by Qodo
1. tf.math.log() can hit -inf
|
| # Calculating Probabilities | ||
| xs_pos = x | ||
| xs_neg = 1 - x | ||
|
|
||
| # Basic CE calculation | ||
| los_pos = y * tf.math.log(xs_pos) | ||
| los_neg = (1 - y) * tf.math.log(xs_neg) | ||
| loss = los_pos + los_neg |
There was a problem hiding this comment.
1. tf.math.log() can hit -inf 📘 Rule violation ⛯ Reliability
The loss computes tf.math.log(xs_pos) and tf.math.log(xs_neg) without clipping/validating that x is in (0,1), which can produce -inf/NaN and break training. This is missing boundary/edge-case handling and input validation.
Agent Prompt
## Issue description
`tf.math.log()` is applied to `x` and `1 - x` without ensuring values are strictly within (0,1), which can produce `-inf/NaN` for boundary/out-of-range inputs.
## Issue Context
This function is intended to be used as a Keras loss. Model outputs may be logits (unbounded) or probabilities that can reach exactly 0/1 depending on activations and numerics.
## Fix Focus Areas
- src/loss_functions/tf_losses.py[23-30]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| # Calculating Probabilities | ||
| xs_pos = x | ||
| xs_neg = 1 - x | ||
|
|
There was a problem hiding this comment.
2. Logits used as probs 🐞 Bug ✓ Correctness
ASL_func’s docstring says x is logits, but the implementation uses x directly as a probability (xs_pos=x, xs_neg=1-x) and omits the sigmoid step used by the reference ASL, producing an incorrect loss when model outputs are logits.
Agent Prompt
## Issue description
`src/loss_functions/tf_losses.py` documents `x` as logits but computes probabilities as `xs_pos = x` / `xs_neg = 1 - x`, which breaks ASL semantics when the model outputs logits.
## Issue Context
The repo’s reference ASL (`src/loss_functions/losses.py`) applies `sigmoid` to logits inside the loss, and training code passes logits with an explicit comment that sigmoid happens in the loss.
## Fix Focus Areas
- src/loss_functions/tf_losses.py[15-26]
- src/loss_functions/tf_losses.py[23-31]
- src/loss_functions/losses.py[23-27]
- train.py[110-113]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools




Add tf_losses.py file which initializes edited version of AsymmetricLoss.forward() function for use with tensorflow.