Skip to content

Commit

Permalink
Fix SoftMax precision by utilizing double in the internal calculations (
Browse files Browse the repository at this point in the history
#3676)

* Fix SoftMax precision by utilizing double in the internal calculations

* Brew install libomp 7.0.0 only. (#3721)

* Brew install libomp 7.0.0 only.

* Brew install libomp 7.0.0 only.

* Brew install libomp 7.0.0 only.

* Brew install libomp 7.0.0 only.

* Fix SoftMax precision by utilizing double in the internal calculations
  • Loading branch information
najeeb-kazmi committed May 15, 2019
1 parent 822d4d8 commit 715ba89
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -740,15 +740,17 @@ public override ValueMapper<VBuffer<float>, VBuffer<float>> GetMapper()

private void NormalizeSoftmax(float[] scores, int count)
{
float sum = 0;
double sum = 0;
var score = new double[count];

for (int i = 0; i < count; i++)
{
scores[i] = (float)Math.Exp(scores[i]);
sum += scores[i];
score[i] = Math.Exp(scores[i]);
sum += score[i];
}

for (int i = 0; i < count; i++)
scores[i] = scores[i] / sum;
scores[i] = (float)(score[i] / sum);
}

public override JToken SaveAsPfa(BoundPfaContext ctx, JToken input)
Expand Down

0 comments on commit 715ba89

Please sign in to comment.