All Questions
Tagged with cross-entropy machine-learning
74 questions
2
votes
1
answer
37
views
How do I update pixelClassificationLayer() to a custom loss function?
I have seen in the Mathworks official website for the pixelClassificationLayer() function that I should update it to a custom loss function using the following code:
function loss = modelLoss(Y,T)
...
-1
votes
1
answer
54
views
How to track loss of multi-label MLP?
I am given binary data points of dimension 5,000. I am asked to perform machine learning predicting a binary vector of length 1k, where each position of the output is a class. The classes are not ...
1
vote
0
answers
378
views
Triplet Loss with Cross Entropy Loss?
I'm trying to learn how to use a TripletLoss in a Siamese Network.
My goal is to build a classification siamese model, so I suppose I need both a Triplet Loss to minimize distances and a Cross Entropy ...
1
vote
1
answer
90
views
Where are the actual predictions stored for Tensorflow keras CategoricalCrossentrophy model?
I'm learning about python and machine learning and reproduced some published code in a Kaggle notebook and modified it for my data within Azure Data Studio running Python 3.
(Removed externally ...
0
votes
1
answer
73
views
CrossEntropyLoss using weights gives RuntimeError: expected scalar type Float but found Long neural network
I am using a Feedforward neural network for a classification task with 4 classes. The classes are imbalanced and hence, I want to use a weight with the CrossEntropyLoss as mentioned here.
Here is my ...
0
votes
1
answer
282
views
Why does my MLP model's loss explode when using softmax and cross entropy in Python?
I am writing an NLP model from scratch in Python, using only NumPy for most of the functions.
import numpy as np
# my loss and activation functions
def relu(x):
return np.maximum(0, x)
def ...
0
votes
1
answer
252
views
PyTorch CrossEntropyLoss documentation example crashes
To make sure I'm using PyTorch CrossEntropyLoss correctly, I'm trying the examples from the documentation: https://pytorch.org/docs/stable/generated/torch.nn.CrossEntropyLoss.html
However, the first ...
3
votes
0
answers
123
views
"RuntimeError: Expected target size" error for the nn.CrossEntropyLoss() function
I am trying to train a GPT-2 model to take in a tokenized/padded input and predict the output. My batch size is 32. My max length is 343. I believe that the 768 comes from the model. I cannot get the ...
0
votes
1
answer
925
views
What is the correct way to penalize one prediction more over another?
I have a BERT-based sequence classification model that takes as an input 4 strings and out 2 labels for each one:
my_input = [string_1, string_2, string_3, string_4]
out_logits = model(my_input)....
2
votes
1
answer
1k
views
Different cross entropy results from NumPy and PyTorch
My prediction is y_hat = [ 0.57,0.05,0.14,0.10,0.14] and target is
target =[ 1, 0, 0, 0, 0 ].
I need to calculate Cross Entropy loss by NumPy and Pytorch loss function.
Using NumPy my formula is -np....
1
vote
1
answer
328
views
difference in categorical crossentropy when specified in loss or metrics
What is the difference between
tf.keras.losses.CategoricalCrossentropy and tf.keras.metrics.CategoricalCrossentropy?
model.compile(optimizer=Adam(learning_rate=lr), loss= 'categorical_crossentropy',
...
-1
votes
1
answer
3k
views
Is this formula of cross entropy for a single example i with C classes correctly written?
If y is the label and hat y is my prediction, would the following formula for cross-entropy with the number of C possible classes be right:
In the case of a Binary Cross Entropy, can I just remove ...
0
votes
1
answer
166
views
Is it possible to use PyTorch's `BatchNorm1d` with `BCELossWithLogits`?
I am attempting to normalize the outputs of my classifier that uses BCELossWithLogits as part of its loss function. As far as I know, this implements Sigmoid function internally and outputs the loss.
...
-1
votes
1
answer
289
views
Is this formula for weighted binary cross entropy loss correct?
Here it is the formula I built: My equation for weighted binary cross entropy loss
Where:
alpha(i) = #Negative samples / Total samples if y(i)=1
alpha(i) = #Positive samples / Total samples if y(i)=0
...
1
vote
1
answer
340
views
Getting RESNet18 to work with float32 data [duplicate]
I have float32 data that I am trying to get RESNet18 to work with. I am using the RESNet model in torchvision (and using pytorch lightning) and modified it to use one layer (grayscale) data like so:
...