🔒 Locked
Chatbot article
Advertisement
Original Post
I've been thinking about writing a smallish article on building your own small-mediumish chatbot. Its just that i've made so many (i've actually got two code eg's (ie. fully commented, debugged, ect.) which i could reuse for this, PREMADE.) And it looks good once it's done (so what its a little (ok a lot, but its <100 lines of vb, so !!!) Dumb), but its nice nonetheless. The beginnings of one, are simple (very simple, parrotbot...), and so it shouldn't be hard to explain as an article... Would it be worth writing one (Maybe more, once i can simplify some of my routines for things like the nets.... but synonym searches shouldn't be too bad) article on how to build a (simple) chatbot? From, Nice coder
Ok then. I'll try to get it written up on the weekend (when i have time [grin])
Does anybody else want this?
From,
Nice coder
Does anybody else want this?
From,
Nice coder
If you have knowledge you can share then share! [wink] That's what this site and these forums are all about.
tia
CipherCraft
tia
CipherCraft
Ok, its only going to be a very VERY simple chatbot. (as in, something which is fun, but takes <10 minutes to build from scratch)
I'll try to get it written tonight (GAH!!! don't you hate it when things pop out of the woodwork that STOP YOU FROM DOING ANYTHING!). But its very simple (hence why i chose it... it's my first tutorial)
From,
Nice coder
I'll try to get it written tonight (GAH!!! don't you hate it when things pop out of the woodwork that STOP YOU FROM DOING ANYTHING!). But its very simple (hence why i chose it... it's my first tutorial)
From,
Nice coder
ok, i've got the thing written (its very very short).
I've got a choise,
do I use the (terible to talk to, but easy to understand, well commented) Single Question to responce code or do i use the (nicer to talk to, harder to understand, not commented) Single quesiton Multiple responce code or should i put in both?
From,
Nice coder
I've got a choise,
do I use the (terible to talk to, but easy to understand, well commented) Single Question to responce code or do i use the (nicer to talk to, harder to understand, not commented) Single quesiton Multiple responce code or should i put in both?
From,
Nice coder
Quote:
Original post by DMINATOR
Offcourse :). I made one myself using modified Markov algorithm, and I am already working on next version with improved capabilities. It would be great to find out anything new that I can use to improve my version .
I would like to know what how you did this if possible.
Quote:
Original post by Themonkster Quote:
Original post by DMINATOR
Offcourse :). I made one myself using modified Markov algorithm, and I am already working on next version with improved capabilities. It would be great to find out anything new that I can use to improve my version .
I would like to know what how you did this if possible.
Well it's not completely Markov's algorithm, I modified and simplified it, so
the technique is simple. For example you have this sentence
Quote:
Hello how are you today
The bot reads all the words and saves them in array
+ it saves link to next word in array
0 - word is the end of line
word num| word | next words
0. | . |0
1. | Hello |2
2. | how |3
3. | are |4
4. | you |5
5. | today |0
Now if we read another line
Quote:
where are you , it's so dark here ?
Our arrays have the following look
Note the worlds now have multiple links.
word num| word | next words
0. | . |0
1. | Hello |2
2. | how |3
3. | are |4
4. | you |5 7
5. | today |0
6. | where |4
7. | , |8
8. | it's |9
9. | so |10
10. | dark |11
11. | here |12
12. | ? |0
Now This is how the sentences generation works. We actually need one word
If word is found then we just move through the links and form the sentence. The next link is chosen randomly.
for example
Quote:
trigger word ->
sentence generation:
you (4 - position)
-> (5)
-> (7)
we select 5
you + today + (0)
you + today + .
we receive this sentence as a responce :
you today .
So it's clear that the program doesn't generate a good and clear sentence. But sometimes the result is good. It depends also by the ammount of words bot knows.
Here is the working version of my IRC chatbot q2clanbot It already knows about 1000 words. But if you wan't to clear them just download librar.rar . And replace the original files
If you are interested I can give you a source code, Borland Builder C++ 6.0
/me waits for the article impatiently
Here is the source:
source
I tryed to commented everything but don't be so sure about them, the version have been changed hundreds time, but it is stable now, I haven't seen a bug for a long time. This version is build with Builder C++ 6.0 .
The part are you looking for is in unit1.cpp . The class Library does all the job.
Here is the structures within it
I didn't wan't to use pointers instead I used linking by words position. So I created 2 arrays
words - is the word + it points to position in the links array;
links - each element holds number of links to other words in words array and also holds position of the same word in words array.
Why did i do that. Well because:
1. link array is stack system. All links here have a constant value, so I can always call 1 (AnsiString Library::ShowWord(int wpos))element and I am sure it's going to be the same.
2. words array is actually a sorted array. This means I can use binary search (int Library::Find(AnsiString word))to quickly find needed element. (I use custom void QSorter(int L ,int R) ).
Overall my realisation method wasn't simple as the theory . If you have a problem understanding some part of the code, feel free to contact me.
source
I tryed to commented everything but don't be so sure about them, the version have been changed hundreds time, but it is stable now, I haven't seen a bug for a long time. This version is build with Builder C++ 6.0 .
The part are you looking for is in unit1.cpp . The class Library does all the job.
Here is the structures within it
Quote:
// links to other words
class Links
{
public:
//link to word
int wlink;
//to other words
DynamicArraylinks;
};
//word structure
class Words
{
public:
//a word
AnsiString word;
//link to other words
int llink ;
};
I didn't wan't to use pointers instead I used linking by words position. So I created 2 arrays
Quote:
DynamicArraywords;
DynamicArraylinks;
words - is the word + it points to position in the links array;
links - each element holds number of links to other words in words array and also holds position of the same word in words array.
Why did i do that. Well because:
1. link array is stack system. All links here have a constant value, so I can always call 1 (AnsiString Library::ShowWord(int wpos))element and I am sure it's going to be the same.
2. words array is actually a sorted array. This means I can use binary search (int Library::Find(AnsiString word))to quickly find needed element. (I use custom void QSorter(int L ,int R) ).
Overall my realisation method wasn't simple as the theory . If you have a problem understanding some part of the code, feel free to contact me.
Quote:
Original post by DMINATOR Quote:
Original post by Themonkster Quote:
Original post by DMINATOR
Offcourse :). I made one myself using modified Markov algorithm, and I am already working on next version with improved capabilities. It would be great to find out anything new that I can use to improve my version .
I would like to know what how you did this if possible.
Well it's not completely Markov's algorithm, I modified and simplified it, so
the technique is simple. For example you have this sentenceQuote:
Hello how are you today
The bot reads all the words and saves them in array
+ it saves link to next word in array
0 - word is the end of line
word num| word | next words
0. | . |0
1. | Hello |2
2. | how |3
3. | are |4
4. | you |5
5. | today |0
Now if we read another lineQuote:
where are you , it's so dark here ?
Our arrays have the following look
Note the worlds now have multiple links.
word num| word | next words
0. | . |0
1. | Hello |2
2. | how |3
3. | are |4
4. | you |5 7
5. | today |0
6. | where |4
7. | , |8
8. | it's |9
9. | so |10
10. | dark |11
11. | here |12
12. | ? |0
Now This is how the sentences generation works. We actually need one word. And we look throguh all the words in array until we find the exact one.
If word is found then we just move through the links and form the sentence. The next link is chosen randomly.
for exampleQuote:
trigger word ->
sentence generation:
you (4 - position)
-> (5)
-> (7)
we select 5
you + today + (0)
you + today + .
we receive this sentence as a responce :
you today .
So it's clear that the program doesn't generate a good and clear sentence. But sometimes the result is good. It depends also by the ammount of words bot knows.
Here is the working version of my IRC chatbot q2clanbot It already knows about 1000 words. But if you wan't to clear them just download librar.rar . And replace the original files
If you are interested I can give you a source code, Borland Builder C++ 6.0
thanks I was wondering where to start with mine. With this method you could get the bot to learn but it would be dependent on who it was learning from.
have your thought about feeding it scripts from a stage play or part of books with good dialogue.
do you discount any words? like if the first sentence contained "the" that could link to almost any other word.
I have played with a system where the using certain words the bot can tell you if you are using a statement or asking a question this would mix quite nicely.
Quote:
Original post by Themonkster
thanks I was wondering where to start with mine. With this method you could get the bot to learn but it would be dependent on who it was learning from.
have your thought about feeding it scripts from a stage play or part of books with good dialogue.
do you discount any words? like if the first sentence contained "the" that could link to almost any other word.
I have played with a system where the using certain words the bot can tell you if you are using a statement or asking a question this would mix quite nicely.
Well It was my actuall point, to learn some sort of natural language :), that is actually spoken, besides with all these flaws, some people couldn't realise that they were talking with bot, until I pointed at that. It seems interesting how some people can be fooled, not all though :)
Yep I tryed that, by result was not really good, I think it does produce better results, when learning user chat.
Early in testing It, I encountered a really bad problem, when word linked to another word and form a loop with it, so these word would eventually repeat many times, that's why I made a decision, that in one sentence there can not be any repeats of any word.
About "the", yep it does link to any word that can follow it, this is the problem I am trying to solve in my future chat bot versions.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement