Hailo

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

        * Match "#1" and "#1234" as single tokens
        * Match </foo> as a single token

    - Depend on MouseX::Getopt 0.33 to fix test failures

0.68 2011-05-03 13:16:05

    - Speed up the learning of repetitive sentences by caching more

    - Added Hailo::Engine::Scored, which generates multiple replies (limited
      by time or number of iterations) and returns the best one. Based on
      code from Peter Teichman's Cobe project.

    - Fixed a bug which caused the tokenizer to be very slow at capitalizing
      replies which contain things like "script/osm-to-tilenumbers.pl"

    - Speed up learning quite a bit (up to 25%) by using more efficient SQL.

    - Add --train-fast to speed up learning by up to an additional 45% on
      large brains by using aggressive caching. This uses a lot of memory.
      Almost 600MB with SQLite on a 64bit machine for a brain which

TODO  view on Meta::CPAN

        storage_class => 'SQLite',
        storage_dbh => sub {
            DBI->connect("dbi:SQLite:dbname=:memory:", "", "" { sqlite_unicode => 1 });
        },
    );
    

* Add a looping ->reply() Engine backend

Extend the Default engine so that it supports a looping
backend. MegaHAL loops for 1 second and cobe loops for 5 iterations
(with token scoring).

This will generate more surprising replies. Sometimes we spit the
input string unmodified or almost unmodified at the user.

* Markov order range

In the future we should modify Hailo to use Markov orders
1..$max_order. I.e. if the user sets $max_order to 5, expressions of
all lengths up to and including 5 should be created. This should

lib/Hailo/Engine/Scored.pm  view on Meta::CPAN

use List::Util qw<sum>;
use List::MoreUtils qw<any>;
use Time::HiRes qw<gettimeofday tv_interval>;

extends 'Hailo::Engine::Default';

after BUILD => sub {
    my ($self) = @_;
    my %args = $self->arguments;

    if (defined $args{iterations} && defined $args{interval}) {
        die __PACKAGE__.": You can only specify one of 'iterations' and 'interval'\n";
    }
    return;
};

sub reply {
    my $self   = shift;
    my $tokens = shift // [];

    # see if we recognize any of the input tokens
    my $token_cache = $self->_resolve_input_tokens($tokens);

lib/Hailo/Engine/Scored.pm  view on Meta::CPAN

    # let's select potential pivot tokens from the input
    if (keys %$token_cache) {
        # we only want the ones with normal spacing (usually normal words)
        @token_counts = map {
            $token_cache->{$_}[0] == 0 ? [$_, $token_cache->{$_}[2]] : ()
        } keys %$token_cache;
    }

    my $token_probs = $self->_get_pivot_probabilites(\@token_counts);
    my @started = gettimeofday();
    my $iterations = 0;

    my $done;
    my %args = $self->arguments;
    if (!defined $args{iterations} && !defined $args{interval}) {
        # construct replies for half a second by default
        $args{interval} = 0.5;
    }

    if (defined $args{iterations}) {
        $done = sub {
            return 1 if $iterations == $args{iterations};
        };
    }
    else {
        $done = sub {
            my $elapsed = tv_interval(\@started, [gettimeofday]);
            return 1 if $elapsed >= $args{interval};
        };
    }

    my (%link_cache, %expr_cache, $best_score, $best_reply);
    while (1) {
        $iterations++;
        my $reply = $self->_generate_reply($token_probs, \%expr_cache);
        return if !defined $reply; # we don't know any expressions yet

        my $score = $self->_evaluate_reply(\@input_token_ids, $reply, \%link_cache);

        if (defined $best_reply && $self->_too_similar(\@input_token_ids, $reply)) {
            last if $done->();
            next;
        }

lib/Hailo/Engine/Scored.pm  view on Meta::CPAN


It generates multiple replies and applies a scoring algorithm to them, then
returns the best one, similar to MegaHAL.

=head1 ATTRIBUTES

=head2 C<engine_args>

This is a hash reference which can have the following keys:

=head3 C<iterations>

The number of replies to generate before returning the best one.

=head3 C<interval>

The time (in seconds) to spend on generating replies before returning the
best one.

You can not specify both C<iterations> and C<interval> at the same time. If
neither is specified, a default C<interval> of 0.5 seconds will be used.

=head1 AUTHORS

Hinrik E<Ouml>rn SigurE<eth>sson, hinrik.sig@gmail.com

This module was based on code from Peter Teichman's Cobe project.

=head1 LICENSE AND COPYRIGHT

t/lib/Hailo/Test/TimToady.trn  view on Meta::CPAN

currently specced, but I'm sure not implemented
is do_something not idempotent?
should be doing them sequentially
possibly a scoping problem?
so you're starting over somehow?
how does the second iteration learn of the first iteration's results?
what is your board stored in?
declared where and how?
how is the board declared, in in what scope?
which declarator are you using?
you might print out .WHICH on the two iterations to see if you're really modifying the same object
with 'has', I presume
if you're sure you're dealing with the same Board each time through, then the problem would be on the setting and sticking end, I suppose
I doubt that rakudo would be trying to do any concurrency
asciiville: a class name has to be predeclared before you can use it, but you can put class Foo {...} with the ... stub
that would serve as a forward declaration
alternately, you can say ::Foo for a not-yet-defined ref
(though not in a declarative context, alas)
we should probably separate those concepts...
but currently, if you need sub foo (::Foo $bar) you have to use class Foo {...} instead
since the ::Foo would mean to capture the type of the $bar parameter en passant



( run in 0.604 second using v1.01-cache-2.11-cpan-71847e10f99 )