I am facing problem in using PHP-ML Persistency feature. The model is not working as expected

I am building a model to analyze sentences whether positive or negative. After the model is successfully trained, I am trying to save the model using PHP-ML Persistency. The model is being saved successfully as well.

But the problem is when I restore the model from file and try to predict, the predict method is throwing error as follows :

Type: PhpmlExceptionInvalidArgumentExceptionMessage: Missing feature. All samples must have equal number of features.

My example code is as follows :

require_once __DIR__ . '/vendor/autoload.php';

use PhpmlClassificationNaiveBayes;
use PhpmlFeatureExtractionTokenCountVectorizer;
use PhpmlTokenizationWhitespaceTokenizer;
use PhpmlModelManager;

$modelPath = '/var/www/ai/models/sentiment_analyzer';

if( ! file_exists($modelPath) ) {

    // Training data
    sentences = [
       'I love this product!',
       'This is terrible, do not buy it.',
       'The customer service was amazing.',
       'I am very disappointed with this purchase.',
       'The quality of this item is excellent.',
       'I would recommend this to anyone.',
       'This product is a waste of money.',
       'The shipping was fast and efficient.',
       'I regret buying this product.',
       'This is the best product I have ever used.'
    ;
    
    labels = [
       'positive',
       'negative',
       'positive',
       'negative',
       'positive',
       'positive',
       'negative',
       'positive',
       'negative',
       'positive'
    ;

    // Vectorize the sentences
    vectorizer = new TokenCountVectorizer(new WhitespaceTokenizer());
    vectorizer->fit($sentences);
    vectorizer->transform($sentences);

    // Train the Naive Bayes classifier
    classifier = new NaiveBayes();
    classifier->train($sentences, $labels);


    modelManager = new ModelManager();
    modelManager->saveToFile($classifier, $filepath);
}
else
{
    $classifier = modelManager->restoreFromFile($filepath);
}


// Predict the sentiment of a new sentence
$newSentence = 'This product is not worth the money.';
$newSentenceVector = $vectorizer->transform([$newSentence])[0];
$predictedLabel = $classifier->predict($newSentenceVector);

echo 'Prediction : ' . $predictedLabel;

Please do note, if I am not saving the model, the prediction is working fine without any errors.