Skip to content

Commit

Permalink
Use logger instead of echo
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdalpino committed Aug 8, 2020
1 parent e7a4ef5 commit 7ca1c40
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
12 changes: 6 additions & 6 deletions train.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

use Rubix\ML\Other\Loggers\Screen;
use Rubix\ML\Datasets\Labeled;
use Rubix\ML\PersistentModel;
use Rubix\ML\Pipeline;
Expand All @@ -18,14 +19,15 @@
use Rubix\ML\NeuralNet\ActivationFunctions\LeakyReLU;
use Rubix\ML\NeuralNet\Optimizers\AdaMax;
use Rubix\ML\Persisters\Filesystem;
use Rubix\ML\Other\Loggers\Screen;
use Rubix\ML\Datasets\Unlabeled;

use function Rubix\ML\array_transpose;

ini_set('memory_limit', '-1');

echo 'Loading data into memory ...' . PHP_EOL;
$logger = new Screen();

$logger->info('Loading data into memory');

$samples = $labels = [];

Expand Down Expand Up @@ -60,9 +62,7 @@
new Filesystem('sentiment.model', true)
);

$estimator->setLogger(new Screen('sentiment'));

echo 'Training ...' . PHP_EOL;
$estimator->setLogger($logger);

$estimator->train($dataset);

Expand All @@ -73,7 +73,7 @@
->toCSV(['scores', 'losses'])
->write('progress.csv');

echo 'Progress saved to progress.csv' . PHP_EOL;
$logger->info('Progress saved to progress.csv');

if (strtolower(trim(readline('Save this model? (y|[n]): '))) === 'y') {
$estimator->save();
Expand Down
9 changes: 6 additions & 3 deletions validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

use Rubix\ML\Other\Loggers\Screen;
use Rubix\ML\Datasets\Labeled;
use Rubix\ML\PersistentModel;
use Rubix\ML\Persisters\Filesystem;
Expand All @@ -11,7 +12,9 @@

ini_set('memory_limit', '-1');

echo 'Loading data into memory ...' . PHP_EOL;
$logger = new Screen();

$logger->info('Loading data into memory');

$samples = $labels = [];

Expand All @@ -26,7 +29,7 @@

$estimator = PersistentModel::load(new Filesystem('sentiment.model'));

echo 'Making predictions ...' . PHP_EOL;
$logger->info('Making predictions');

$predictions = $estimator->predict($dataset);

Expand All @@ -41,4 +44,4 @@

$results->toJSON()->write('report.json');

echo 'Report saved to report.json' . PHP_EOL;
$logger->info('Report saved to report.json');

0 comments on commit 7ca1c40

Please sign in to comment.