This is my custom chat bot! To chat with it, press space and enter your message. It does run off of preset inputs and outputs, but it's a lot more complicated than that may make it seem. Here's how it works (Might not be in perfect order as I originally made this in Scratch and moved it here, and it's been 2 years since I originally made it):
- All the Inputs and Outputs of the chat bot are shuffled, will be important for future steps, but the correlated Inputs and Outputs stick together as they only make sense together
- Punctuation is removed from the message, allowing words to be easily detected
- All words in the message are checked to see if they are a synonym, and if they are they are changed to the original synonym. Ex: "Hello, how are you?" is turned into "Hi, how are you?", where "Howdy, hello, sup" and other common greetings are changed into "Hi"
- The message sent by the user is then compared in word similarity to every Input provided, comparing how many words in the Input are the same as words in the list of Inputs. This allows for two messages, like "Hello, how are you?" and "Hey there, how are you doing?" to be similar to each other and letting the algorithm to compare them
- After every Input in the list is scanned, the most similar one will have it's associated output reply to the user
- The mixing up of the Inputs and Outputs allows for different responses for equally similar messages. When scanning for similarity, if two items have the same similarity level, the first one will be the one sent back to the user. If you type "What's your favorite letter?", that is not a possibility of an Input. So, the two possible ones, "What's your favorite number?" and "What's your favorite color?" will have an equal similarity, and by shuffling them around it will pick a different one almost every time, as the first one found is sent out, so it is not as repetitive.
- If no Input in the list has a high enough similarity to the provided Input, then a random message of a list will be sent back, including "Sorry, I don't understand that.", and "Hmm, okay." as predetermined 'error' messages
This code is pretty old and I now know more things that could improve the efficiency of this, or to make it better, like using Word2vec. Note that this was originally made before Chat-GPT was a thing, and I transferred it from Scratch to here because I thought I could improve it's efficiency, which I did by a lot with Snap!'s unique features.