AI-MXNet
view release on metacpan or search on metacpan
lib/AI/MXNet/Initializer.pm view on Meta::CPAN
my $class = shift;
return $class->$orig(name => $_[0]) if @_ == 1;
return $class->$orig(@_);
};
# Base class for Initializers
package AI::MXNet::Initializer;
use Mouse;
use AI::MXNet::Base qw(:DEFAULT pzeros pceil);
use AI::MXNet::NDArray;
use JSON::PP;
use overload "&{}" => sub { my $self = shift; sub { $self->call(@_) } },
'""' => sub {
my $self = shift;
my ($name) = ref($self) =~ /::(\w+)$/;
encode_json(
[lc $name,
$self->kwargs//{ map { $_ => "".$self->$_ } $self->meta->get_attribute_list }
]);
},
fallback => 1;
lib/AI/MXNet/Initializer.pm view on Meta::CPAN
# in the case of LSTMCell the forget gate is the second
# gate of the 4 LSTM gates, we modify the according values.
my $num_hidden = int($arr->shape->[0] / 4);
$arr->slice([$num_hidden, 2*$num_hidden-1]) .= $self->forget_bias;
}
__PACKAGE__->register;
package AI::MXNet::FusedRNN;
use Mouse;
use JSON::PP;
extends 'AI::MXNet::Initializer';
=head1 NAME
AI::MXNet::FusedRNN - Custom initializer for fused RNN cells.
=cut
=head1 DESCRIPTION
Initializes parameters for fused rnn layer.
lib/AI/MXNet/Symbol.pm view on Meta::CPAN
}
method STORABLE_freeze($cloning)
{
return $self->tojson();
}
method STORABLE_thaw($cloning, $json)
{
my $handle = check_call(
AI::MXNetCAPI::SymbolCreateFromJSON(
$json
)
);
$self->handle($handle);
}
method stringify($other=, $reverse=)
{
my $name = $self->name;
sprintf("<%s %s>", ref($self), $name ? $name : 'Grouped');
lib/AI/MXNet/Symbol.pm view on Meta::CPAN
load : Used to load symbol from file.
=cut
method save(Str $fname)
{
check_call(AI::MXNetCAPI::SymbolSaveToFile($self->handle, $fname));
}
=head2 tojson
Save the symbol into a JSON string.
See Also
--------
load_json : Used to load symbol from JSON string.
=cut
method tojson()
{
return scalar(check_call(AI::MXNetCAPI::SymbolSaveToJSON($self->handle)));
}
method _get_ndarray_inputs(
Str $arg_key,
HashRef[AI::MXNet::NDArray]|ArrayRef[AI::MXNet::NDArray] $args,
ArrayRef[Str] $arg_names,
Bool $allow_missing=0
)
{
my ($arg_handles, $arg_arrays) = ([], []);
lib/AI/MXNet/Symbol.pm view on Meta::CPAN
method Group(ArrayRef[AI::MXNet::Symbol] $symbols)
{
my @handles = map { $_->handle } @{ $symbols };
my $handle = check_call(AI::MXNetCAPI::SymbolCreateGroup(scalar(@handles), \@handles));
return __PACKAGE__->new(handle => $handle);
}
=head2 load
Load symbol from a JSON file.
You can also use Storable to do the job if you only work with Perl.
The advantage of load/save is the file is language agnostic.
This means the file saved using save can be loaded by other language binding of mxnet.
You also get the benefit being able to directly load/save from cloud storage(S3, HDFS)
Parameters
----------
fname : str
The name of the file, examples:
lib/AI/MXNet/Symbol.pm view on Meta::CPAN
sym : Symbol
The loaded symbol.
See Also
--------
AI::MXNet::Symbol->tojson : Used to save symbol into json string.
=cut
method load_json(Str $json)
{
my $handle = check_call(AI::MXNetCAPI::SymbolCreateFromJSON($json));
return __PACKAGE__->new(handle => $handle);
}
method zeros(Shape :$shape, Dtype :$dtype='float32', Maybe[Str] :$name=, Maybe[Str] :$__layout__=)
{
return __PACKAGE__->_zeros({ shape => $shape, dtype => $dtype, name => $name, ($__layout__ ? (__layout__ => $__layout__) : ()) });
}
method ones(Shape :$shape, Dtype :$dtype='float32', Maybe[Str] :$name=, Maybe[Str] :$__layout__=)
{
lib/AI/MXNet/Visualization.pm view on Meta::CPAN
package AI::MXNet::Visualization;
use strict;
use warnings;
use AI::MXNet::Base;
use AI::MXNet::Function::Parameters;
use JSON::PP;
=encoding UTF-8
=head1 NAME
AI::MXNet::Vizualization - Vizualization support for Perl interface to MXNet machine learning library
=head1 SYNOPSIS
use strict;
( run in 0.993 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )