CodeWithKyrian / transformers-php

Transformers PHP is a toolkit for PHP developers to add machine learning magic to their projects easily.
https://codewithkyrian.github.io/transformers-php/
Apache License 2.0
291 stars 16 forks source link

Problem with AutoConfig.php #18

Closed CViniciusSDias closed 3 months ago

CViniciusSDias commented 3 months ago

System Info

SO: Ubuntu (under WSL) - Linux NotebookG15 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

PHP Version

8.3.6

Environment/Platform

Description

When trying to execute any simple code using TransformersPHP, I get the following error:

PHP Fatal error:  Uncaught TypeError: Codewithkyrian\Transformers\Utils\AutoConfig::__construct(): Argument #1 ($config) must be of type array, null given, called in /tmp/transformersphp/vendor/codewithkyrian/transformers/src/Utils/AutoConfig.php on line 53 and defined in /tmp/transformersphp/vendor/codewithkyrian/transformers/src/Utils/AutoConfig.php:26    
Stack trace:
#0 /tmp/transformersphp/vendor/codewithkyrian/transformers/src/Utils/AutoConfig.php(53): Codewithkyrian\Transformers\Utils\AutoConfig->__construct()
#1 /tmp/transformersphp/vendor/codewithkyrian/transformers/src/Models/Auto/PretrainedMixin.php(53): Codewithkyrian\Transformers\Utils\AutoConfig::fromPretrained()
#2 /tmp/transformersphp/vendor/codewithkyrian/transformers/src/Pipelines/Task.php(101): Codewithkyrian\Transformers\Models\Auto\PretrainedMixin::fromPretrained()
#3 /tmp/transformersphp/vendor/codewithkyrian/transformers/src/Pipelines/Pipeline.php(79): Codewithkyrian\Transformers\Pipelines\Task->pretrainedModel()
#4 /tmp/transformersphp/transformers.php(7): Codewithkyrian\Transformers\Pipelines\pipeline()
#5 {main}
  thrown in /tmp/transformersphp/vendor/codewithkyrian/transformers/src/Utils/AutoConfig.php on line 26

Reproduction

Run the following code:

<?php

use function Codewithkyrian\Transformers\Pipelines\pipeline;

require 'vendor/autoload.php';

$classifier = pipeline('sentiment-analysis');

var_dump($classifier('I love TransformersPHP!'));
CViniciusSDias commented 3 months ago

src/Utils/Helpers.php:77 has the following line:

return preg_replace('#/+#', '/', implode(DIRECTORY_SEPARATOR, $paths));

This returns https:/huggingface.co/Xenova/distilbert-base-uncased-finetuned-sst-2-english/resolve/main/config.json, with https:/ instead of https://, which is incorrect.

CodeWithKyrian commented 3 months ago

Thanks for bringing it to my attention. The PR has been merged but it'll be part of the upcoming v0.3.0 release in few hours