Compute softmax probability over raw logits.
(scores)
| 911 | |
| 912 | |
| 913 | def _compute_softmax(scores): |
| 914 | """Compute softmax probability over raw logits.""" |
| 915 | if not scores: |
| 916 | return [] |
| 917 | |
| 918 | max_score = None |
| 919 | for score in scores: |
| 920 | if max_score is None or score > max_score: |
| 921 | max_score = score |
| 922 | |
| 923 | exp_scores = [] |
| 924 | total_sum = 0.0 |
| 925 | for score in scores: |
| 926 | x = math.exp(score - max_score) |
| 927 | exp_scores.append(x) |
| 928 | total_sum += x |
| 929 | |
| 930 | probs = [] |
| 931 | for score in exp_scores: |
| 932 | probs.append(score / total_sum) |
| 933 | return probs |
| 934 | |
| 935 | |
| 936 | def generate_tf_record_from_json_file(input_file_path, |
no outgoing calls
no test coverage detected