Merge pull request #106 from chrislee973/fix-norm-calculation

Fix tensor normalization in EmbeddingsPipeline
This commit is contained in:
Joshua Lochner 2023-05-07 15:54:20 +02:00 committed by GitHub
commit 13b570ce97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions

View File

@ -628,7 +628,7 @@ class EmbeddingsPipeline extends Pipeline {
*/
_normalize(tensor) {
for (let batch of tensor) {
let norm = Math.sqrt(batch.data.reduce((a, b) => a + b * b))
let norm = Math.sqrt(batch.data.reduce((a, b) => a + b * b, 0))
for (let i = 0; i < batch.data.length; ++i) {
batch.data[i] /= norm;