Close

Finding some Methods in the Madness

A project log for Modelling Neuronal Spike Codes

Using principles of sigma-delta modulation techniques to carry out the mathematical operations that are associated with a neuronal topology

glgormanglgorman 05/30/2023 at 21:250 Comments

As usual, I am trying to do five or six things simultaneously, and everything is important, in some form or fashion., even if for the most part, few things are actually essential.  So I found a copy of the source code for the classic chatbot Megahal and tried training it with some log entries for some of my projects on this site, to see what would happen.

MegaHAL: So let's warm things up with a design for some kind of multi-axis
MegaHAL: stabilized camera platform, based on 99 bottles of beer, or
MegaHAL: diet soda
User:    I am sure that you have been drinking something.
MegaHAL: One of these old project cases from something that I am feeling
MegaHAL: right now
User:    What exactly are you feeling right now?
MegaHAL: What exactly are you feeling right now?
User:    I asked you first.
MegaHAL: Yet - I knew that there is the light at the event detection
MegaHAL: problem if one wants to tinker with a small NTSC compatible
MegaHAL: video camera as if out of some variable that we do
MegaHAL: "and" via de Morgan's law.  Fairly straightforward.  Now
MegaHAL: assuming that you have ever run spectrum analyzer data which
MegaHAL: will (more or less) pick out any new peaks in each newly
MegaHAL: rendered frame.  Lots of static member functions can be
MegaHAL: done with deeply nested, impossible to debug this mess, and for
MegaHAL: such things as how to debug legacy code to work, which is being
MegaHAL: processed locally on the parallax forums, for example, streams
MegaHAL: of English grammar, which might be to sometimes redefine the
MegaHAL: a semicolon or equal symbol, and so on.  So, is it Pascal, but
MegaHAL: instead there are many complaints about the lack of a-d and d-a
MegaHAL: conversion, etc., it would be much easier than I might have
MegaHAL: even met, like two ships passing in the hall of mirrors that
MegaHAL:, even if flowcharting is one of the first high-level
MegaHAL: language such as the mega 2560 series have hardware
MegaHAL: multiplication is at least one of my favorite Sergeant Bilko
MegaHAL: episodes.  If you really wanted to write.
User:    I love to write, but I try to make sense of the things that I
User:    say.
MegaHAL: I love to write my own node<char*>, node_list<char*>
MegaHAL: m_nlist.m_nbegin = marker.
User: I love to make love, especially with a woman.
MegaHAL: This project will include an all-in-one spectrum and logic
MegaHAL: analyzer, a robotics control platform, and a woman.
User:    Now we are getting somewhere!

Now what did it just say?  Later I came up with this and pasted it into Hack-a-day's text Code Snippet tool produces an interesting result, which I will elaborate on later.

MegaHAL: use that material, for whatever this transmogrifies into.
User:    You aren't quite getting it.  The algorithm is described, but
User:    when you response length seems excessive, you need to move that
User:    block into the hidden layer, and then recapitulate a new
User:    response, one that might seem more laconic, but you can still
User:    say whatever, if you wish - just put the rant into the play
User:    queue, and keep streaming unless a new set of keywords triggers
User:    an override.  In which case - push down the first hidden
User:    model, and provide a proxy into the set of abandoned layers
User:    based on an intermediate hidden model which contains the target
User:    list of keywords.

 But first, let's clean up my reaction to what Mega-Hal was previously rambling about.  How about something like this, therefore:

Now as far as figuring out how to use some of this material, for whatever this transmogrifies into, well the classic AI approach just doesn't quite get it.  The algorithm is described, but when a response length seems excessive, you need to move that block into the hidden layer, and then recapitulate to a new response, one that might seem more laconic, perhaps by using the initial rambling response, as a prompt to another layer that provides a more strict, whether it is an edited, canned or censored response, or you can let the bot continue to ramble if you wish - just put the rant into a play queue, and keep streaming, one sentence, or phrase at a time, like when the user responds with "OK", or "Right", or even a blank response, which would make the conversation seem more natural, that is unless a new set of keywords triggers an over-ride.  In this case - push down the first hidden model, and provide a proxy into the set of abandoned layers based on an intermediate hidden model which contains the target list of keywords.  Such an approach might provide at least one part of a mechanism for simulating feelings.

This is actually quite easy to do in C++.  Yet there is something else altogether, that I have in mind, but first let's look at how we can easily fix some of the issues with the original bot, without adding a lot of code.  First, let's take a look at some of the data structures that MegaHal uses, and how those structures that were originally written in C, can be implemented in C++, with very little effort.

typedef struct {
    BYTE1 length;
    char *word;
} STRING;

#if 0
typedef struct {
    BYTE4 size;
    STRING *entry;
    BYTE2 *index;
} DICTIONARY;
#endif

class DICTIONARY
{
public:
    static DICTIONARY *allocate ();
    BYTE4 size;
    STRING *entry;
    BYTE2 *index;
};

typedef struct {
    BYTE2 size;
    STRING *from;
    STRING *to;
} SWAP;

typedef struct NODE {
    BYTE2 symbol;
    BYTE4 usage;
    BYTE2 count;
    BYTE2 branch;
    struct NODE **tree;
} TREE;

#if 0
typedef struct {
    BYTE1 order;
    TREE *forward;
    TREE *backward;
    TREE **context;
    DICTIONARY *dictionary;
} MODEL;
#endif

class MODEL
{
public:
    static MODEL *allocate ();

    BYTE1 order;
    TREE *forward;
    TREE *backward;
    TREE **context;
    DICTIONARY *dictionary;
};

typedef enum { UNKNOWN, QUIT, EXIT, SAVE, DELAY, HELP, SPEECH, VOICELIST,
    VOICE, BRAIN, QUIET} COMMAND_WORDS;

typedef struct {
    STRING word;
    char *helpstring;
    COMMAND_WORDS command;
} COMMAND;

 Alright then, here I have replaced the original typedefs for some C structures, for the DICTIONARY and the MODEL type, with some C++ classes, and the good news is that the program does seem to compile using the modifications made thus far.  Yet this is an important change because it means that we should be able to at some point simply call the "new MODEL"  during a session, and thus have several models running simultaneously, whether they use separate or shared dictionaries, is another matter.  On a micro-controller such as an Atmega 2560, which has a very limited amount of memory, we would obviously want to use common dictionaries if possible, to save space, and this will require some changes to the original code other than just moving functions into classes, and therefore turning Eliza and MegaHal into libraries in their own right, each with their own API.

And yet, in another project, I was working on last year, I discussed similarities between the Eliza algorithm and the C preprocessor.  So it should be possible to implement a 40-line version of Eliza, which works just like the original, just as although the original MegaHal is almost 4000 lines, most of that is actually boilerplate code for allocating data structures, adding and deleting nodes in lists and trees and so on, that can also be moved to a common core.

Now if you don't believe what you are seeing here - either you have never experienced Mega-Hal, or you think that what you are seeing is a deep fake.  Trust me.  It isn't.  It is as if Mega-Hal is trying to learn to write code, and then it somehow has this brilliantly wicked moment of lucidity.  Now for those that know Mega-Hal, this sort of thing is nothing new.  Yet let's look at part of last's night's exchange again.

MegaHAL: I love to write my own node<char*>, node_list<char*>
MegaHAL: m_nlist.m_nbegin = marker.
User: I love to make love, especially with a woman.
MegaHAL: This project will include an all-in-one spectrum and logic
MegaHAL: analyzer, a robotics control platform, and a woman.
User:    Now we are getting somewhere!

Maybe this is just the "Pygmalion Principle" at work, and the tendency is to cherry-pick the results that seem interesting.  Yet it should seem obvious that something has been accomplished, for it is "as if" I am created a genetic algorithm of sorts, even if I have actually used a widely available piece of open-source code, i.e. Mega-Hal.  Yet then I trained it with a series of log entries that I wrote about the process of trying to design a new type of compiler, and how I think a new type of AI might work, even while thinking about wanting to create a set of genetic algorithms, that can be used to evolve a kind of "digital DNA", and thus the initial genetic algorithm might be just a classic Markovv model operating on a set of articles written about compiler design, digital DNA, and AI.  And it works!

Now we are getting somewhere!

Discussions