MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / _compute_softmax

Function _compute_softmax

demo/BERT/helpers/data_processing.py:311–331  ·  view source on GitHub ↗

Compute softmax probability over raw logits.

(scores)

Source from the content-addressed store, hash-verified

309
310
311def _compute_softmax(scores):
312 """Compute softmax probability over raw logits."""
313 if not scores:
314 return []
315
316 max_score = None
317 for score in scores:
318 if max_score is None or score > max_score:
319 max_score = score
320
321 exp_scores = []
322 total_sum = 0.0
323 for score in scores:
324 x = math.exp(score - max_score)
325 exp_scores.append(x)
326 total_sum += x
327
328 probs = []
329 for score in exp_scores:
330 probs.append(score / total_sum)
331 return probs
332
333
334def get_predictions(doc_tokens, features, results, n_best_size, max_answer_length):

Callers 1

get_predictionsFunction · 0.85

Calls 2

expMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected