In your example you are treating output [0, 0, 0, 1]
as probabilities as required by the mathematical definition of cross entropy. But PyTorch treats them as outputs, that don’t need to sum to 1
, and need to be first converted into probabilities for which it uses the softmax function.
So H(p, q)
becomes:
H(p, softmax(output))
Translating the output [0, 0, 0, 1]
into probabilities:
softmax([0, 0, 0, 1]) = [0.1749, 0.1749, 0.1749, 0.4754]
whence:
-log(0.4754) = 0.7437
Related Posts:
- What’s the difference between torch.stack() and torch.cat() functions?
- How to initialize weights in PyTorch?
- How to install pytorch in Anaconda with conda or pip?
- Expected 2D array, got 1D array instead error
- Error in Python script “Expected 2D array, got 1D array instead:”?
- How to use torch.stack function
- How does the “view” method work in PyTorch?
- Embedding in pytorch
- What does “unsqueeze” do in Pytorch?
- Cannot convert list to array: ValueError: only one element tensors can be converted to Python scalars
- What is the difference between sparse_categorical_crossentropy and categorical_crossentropy?
- Pytorch tensor to numpy array
- How to fix this strange error: “RuntimeError: CUDA error: out of memory”
- Pytorch reshape tensor dimension
- What is the difference between np.mean and tf.reduce_mean?
- No module named “Torch”
- How to install pytorch in windows?
- What is the meaning of ‘for _ in range()
- ValueError: x and y must be the same size
- What’s the difference between scikit-learn and tensorflow? Is it possible to use them together?
- Scikit-learn GridSearch giving “ValueError: multiclass format is not supported” error
- How to implement the ReLU function in Numpy
- ValueError: multiclass format is not supported
- Find the current directory and file’s directory [duplicate]
- Finding the index of an item in a list
- How to plot a histogram using Matplotlib in Python with a list of data?
- Convert pandas dataframe to NumPy array
- Fastest way to check if a value exists in a list
- TypeError: can’t multiply sequence by non-int of type ‘str’
- Error:cannot convert float NaN to integer in pandas
- What does the % sign mean in coding?
- Replacing column values in a pandas DataFrame
- How can I count the occurrences of a list item?
- Unable to plot Double Bar, Bar plot using pyplot for ndarray
- matplotlib error – no module named tkinter
- AttributeError: module ‘urllib3’ has no attribute ‘urlopen’ in python
- How to download a file over HTTP?
- filedialog, tkinter and opening files
- How do I get the row count of a Pandas DataFrame?
- ‘list’ object has no attribute ‘shape’
- What does the ‘b’ character do in front of a string literal?
- How to add multiple values per key in python dictionary
- Pythonic way to combine FOR loop and IF statement
- Python: OverflowError: math range error
- Best way to replace multiple characters in a string?
- Convert base-2 binary number string to int
- setup script exited with error: command ‘x86_64-linux-gnu-gcc’ failed with exit status 1
- sublime text2 python error message /usr/bin/python: can’t find ‘__main__’ module in ”
- load csv into 2D matrix with numpy for plotting
- Python TypeError: cannot convert the series to
when trying to do math on dataframe - How do I do a case-insensitive string comparison?
- How to fix ‘ValueError: list.remove(x): x not in list’ error in Python
- Converting binary to decimal integer output
- Don’t understand this SyntaxError: illegal target for annotation
- No module named setuptools
- Using Queue in python
- Whats the difference between ‘for x in list:’ and ‘for x in list[:]:’
- Python: maximum recursion depth exceeded while calling a Python object
- Checking if a number is prime in Python
- Implementing an efficient queue in Python
- Modify the legend of pandas bar plot
- Python int to binary string?
- Full examples of using pySerial package
- Checking whether a variable is an integer or not
- Pandas DataFrame: replace all values in a column, based on condition
- How to create a trie in Python
- How to convert string to datetime format in pandas python?
- TypeError: expected a character buffer object
- “RuntimeError: Make sure the Graphviz executables are on your system’s path” after installing Graphviz 2.38
- Convert date to datetime in Python
- UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\xa0′ in position 20: ordinal not in range(128)
- How to install PyQt5 on Windows?
- How do I get the day of week given a date?
- TypeError: ‘dict_keys’ object does not support indexing
- Add Variables to Tuple
- Python: Converting string into decimal number
- Segmentation fault: 11 in OS X
- Removing duplicates from a list of lists
- plotly: TypeError: cannot convert dictionary update sequence element #0 to a sequence
- Update python dictionary (add another value to existing key)
- scrapy run spider from script
- Using replace() method in python by index
- Python, how to handle the “ValueError: unsupported pickle protocol: 4” error?
- python error: TypeError: an integer is required
- Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)
- Plot a histogram such that the total area of the histogram equals 1
- pip throws TypeError: parse() got an unexpected keyword argument ‘transport_encoding’ when trying to install new packages
- How to change legend size with matplotlib.pyplot
- An equivalent function to matplotlib.mlab.bivariate_normal
- Sorting arrays in NumPy by column
- How to open html file?
- In Python, is there an elegant way to print a list in a custom format without explicit looping?
- “Python version 2.7 required, which was not found in the registry” error when attempting to install netCDF4 on Windows 8
- Does tkinter have a table widget?
- Releasing memory in Python
- Text progress bar in terminal with block characters
- Extracting specific selected columns to new DataFrame as a copy
- How to read a CSV file from a URL with Python?
- How to print both strings in a dictionary in Python
- Python: OSError: [Errno 2] No such file or directory: ”