Tensor::normalize() doesn't normilize · Issue #110 · CodeWithKyrian/transformers-php · GitHub
Skip to content

Tensor::normalize() doesn't normilize #110

Open

Description

@bilelBoulhia

System Info

linux ubuntu 24.04 , using larvel

PHP Version

8.5

Environment/Platform

  • Command-line application
  • Web application
  • Serverless
  • Other (please specify)

Description

[0] to flatten the array, the output should be normalized to 1 during the unit test below, but its not

use function Codewithkyrian\Transformers\Pipelines\pipeline;

public function vectorize(string $text): array
    {
        return $this->extractor()($text, normalize: true, pooling: 'mean')[0]; 
    }



Reproduction

run this unit test after implementing the vecotrize function in a class

public function test_vector_is_normalized(): void
    {
        $vector = self::$vectorizer->vectorize('normal unit test');

        $norm = sqrt(array_sum(array_map(fn ($x) => $x ** 2, $vector)));

        $this->assertEqualsWithDelta(1.0, $norm, 0.001);
    }


Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions