-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpy52.py
More file actions
31 lines (24 loc) · 842 Bytes
/
Copy pathpy52.py
File metadata and controls
31 lines (24 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import numpy as np
softmax_outputs = np.array([[0.7, 0.1, 0.2],
[0.1, 0.5, 0.4],
[0.02, 0.9, 0.08]])
class_targets = np.array([[1, 0, 0],
[0, 1, 0],
[0, 1, 0]])
print(len(class_targets.shape))
print(class_targets.shape)
print(len([[1, 0, 0]]))
# Probabilities for target_values
# only if categorical labels
if len(class_targets.shape) == 1:
correct_confidences = softmax_outputs[range(len(softmax_outputs)), class_targets]
# Mask values only for one-hot encoded labels
elif len(class_targets.shape) == 2:
correct_confidences = np.sum(softmax_outputs*class_targets, axis=1)
# Losses
neg_log = -np.log(correct_confidences)
average_loss = np.mean(neg_log)
print(average_loss)
print(-np.log(1e-7))
print(1e-1)
print(10**-7)