Make the computer randomely talk...

  • 4 Replies
  • 2273 Views
*

Mr.Fox

  • Bumblebee
  • **
  • 35
    • Dreamwalker Software
Make the computer randomely talk...
« on: July 31, 2016, 11:45:45 am »
OK, the title was a little misleading as I didn't know what to put, but basically the other day slightly tipsy and have A.I ideas floating around in my head, I decided, what if I run a program through random code to come up with legitimate words in English, then laughing to myself imagining scary results like "You will die in october" or something of that ilk, so I got to it. As a way for the program to understand what it a legitimate English word I downloaded a local text file and created the code.

It does this:

Loads the dictionary into memory
uses alphabetical characters a - z
runs a constant loop creating a random feed
generates a word size between 1 and 35 characters long
then, word size dependant, creates a random alphabetical character for each letter in the word
then, it compares the generated word to the dictionary, if it's valid, a log will be made (with time/date stamp) and continue, if not it'll just continue


Now, I am sure there are better ways to make this but I was tipsy when I coded it, I ran it through about 70,000,000 attempts and nothing! but, while statistically you may have more chance winning the lottery, it's still possibly to come up with a word, or several for that matter and I think it would be interested what the program/computer could say from completely randomly generated code.

I've zipped up the executable with dict http://www.filedropper.com/wordgenbycraigfox, please run it and give it a shot, could be interested results.

Let me know what you think, feel free to also make suggestions/improvements.

Code below:

Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Media;

namespace AI_word_gen
{
    class Program
    {
        static void Main(string[] args)
        {

            //---------------Load dict into mem------------------------------------
                 string dictionary = File.ReadAllText("wordsEn.txt");

           
            //---------------------generate random words---------------------------
            char[] alphabet = { 'a', 'b', 'c', 'd', 'e', 'f', 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
            int attempts = 0;

            while (true)
            {
                string sWord = " ";
               
                //random feed
                Random rnd = new Random();

                //generate a word size between 1 - 35
                int iwordSize = rnd.Next(1, 35);
               
                //perform a loop from word size generating a random alphabetical charater each iteration
                for (int i = 0; i < iwordSize; i++)
                {
                    int irandLetter = rnd.Next(1, 26);
                    sWord += alphabet[irandLetter];
                } sWord += " ";



                //--------------------compare words-------------------------------------
                if (dictionary.Contains(sWord))
                {
                    Console.WriteLine("Found: " + sWord + "on: " + DateTime.Now.ToString("dd-MM-yyyy @ HH:mm"));

                    System.IO.StreamWriter file = new System.IO.StreamWriter("results.txt");
                    file.WriteLine("Found: " + sWord + "on: " + DateTime.Now.ToString("dd-MM-yyyy @ HH:mm"));

                    file.Close();
                }

                Console.Title = "Attempts = " + attempts++ + " word = " + sWord;
            }



            Console.WriteLine("\nFINISHED");
            Console.ReadLine();
        }
       
    }
   
}


*

Freddy

  • Administrator
  • **********************
  • Colossus
  • *
  • 6856
  • Mostly Harmless
Re: Make the computer randomely talk...
« Reply #1 on: July 31, 2016, 11:07:00 pm »
Kind of like the room full of monkeys typing Shakespeare.  8)

I'm not great at maths but 26 (English) letters in the alphabet means a huge variety of combinations or permutations.

Say a 10 letter word, from 26 letters is 19,275,223,968,000 permutations.

I used this page to work that out : http://stattrek.com/online-calculator/combinations-permutations.aspx

For your test you did 70000000/19,275,223,968,000 = 0.0000036316 % which is clearly the very tip of the iceberg.

What you did not reveal is how long your test ran for 70 million attempts. If it took all day then we might need to wait a few years  :D

You could cheat a bit and do each letter from left to right, then use the odds of one letter following the previous one to weed out letters that rarely appear together perhaps. Hmm. Or again (thinking of efficiency) go left to right one letter at a time. And after each letter check whether that pattern actually exists in English - ie is it leading to a word or not. If it's not, just start again.

Cool idea though, I like it. :)




*

8pla.net

  • Trusty Member
  • ***********
  • Eve
  • *
  • 1302
  • TV News. Pub. UAL (PhD). Robitron Mod. LPC Judge.
    • 8pla.net
Re: Make the computer randomely talk...
« Reply #2 on: August 01, 2016, 09:06:04 pm »
Perhaps just randomly pick words from a dictionary.

Dictionary:

0.  Apple
1.  Banana
2.  Cherry
3.  Date Plum

random_pick = from 0 to 3.

print Dictionary[random_pick]


Or else, for (perhaps) more fun (than brute forcing millions), I think...

Make two lists for:

vowels: a,e,i,o,u,
consonants: b,c,d,f,g,h,j,k,l,m,n,p,q,r,s,t,v,w,x,y,z

And then do consonant-vowel-consonant, or vice-versa, etc.

There may be a greater probability of generating words from letters this way. 

What do you think?



« Last Edit: August 02, 2016, 03:27:32 am by 8pla.net »
My Very Enormous Monster Just Stopped Using Nine

*

Art

  • At the end of the game, the King and Pawn go into the same box.
  • Trusty Member
  • **********************
  • Colossus
  • *
  • 5865
Re: Make the computer randomely talk...
« Reply #3 on: August 02, 2016, 01:58:02 am »
Could help it but this banter reminds me of one of my favorite episodes...



In the world of AI, it's the thought that counts!

*

Don Patrick

  • Trusty Member
  • ********
  • Replicant
  • *
  • 633
    • AI / robot merchandise
Re: Make the computer randomely talk...
« Reply #4 on: August 02, 2016, 08:59:46 am »
In poetry generation, people usually go with semi-random words, rather than letters. And use N-grams to line up words with some plausibility. But still fail to say something sensible.
CO2 retains heat. More CO2 in the air = hotter climate.

 


OpenAI Speech-to-Speech Reasoning Demo
by MikeB (AI News )
March 31, 2024, 01:00:53 pm
Say good-bye to GPUs...
by MikeB (AI News )
March 23, 2024, 09:23:52 am
Google Bard report
by ivan.moony (AI News )
February 14, 2024, 04:42:23 pm
Elon Musk's xAI Grok Chatbot
by MikeB (AI News )
December 11, 2023, 06:26:33 am
Nvidia Hype
by 8pla.net (AI News )
December 06, 2023, 10:04:52 pm
How will the OpenAI CEO being Fired affect ChatGPT?
by 8pla.net (AI News )
December 06, 2023, 09:54:25 pm
Independent AI sovereignties
by WriterOfMinds (AI News )
November 08, 2023, 04:51:21 am
LLaMA2 Meta's chatbot released
by 8pla.net (AI News )
October 18, 2023, 11:41:21 pm

Users Online

218 Guests, 0 Users

Most Online Today: 262. Most Online Ever: 2369 (November 21, 2020, 04:08:13 pm)

Articles