Search

Geek Girl Joy

Artificial Intelligence, Simulations & Software

Alien Economic Cryopods

The global economy is asleep so to my weird sense of humor it seems to make sense to publish this wallpaper today. 😛

Alien Cryopods Wallpaper

Alien Cryopods Wallpaper
Alien Cryopods Wallpaper

Like many of you, my family is doing it’s best to remain positive and productive during the global pandemic and we’re okay.

My three year old Xavier’s home schooling is going well and naturally he enjoys math and it’s relationship with shapes though sometimes he gets addition and subtraction confused…

“Three minus three equals six!”

~My Xavier Baby

He’s so adorable! 🙂

Now, I know I should be working on the next phase of our Emotional Robot:

Or… acknowledge the many awards and accolades that have been unduly heaped upon me recently but late on Monday I started building a virus simulation that I hope will save lives (not a joke) and my free time this week has been going into that instead of my regular extracurricular blogging activities.

Though if I’m being honest, I still found time to launch 7 Days to Die and generate a new map using the seed “Coronapocalypse”! 😛

If all goes well I hope to publish my code to GitHub early next week and we’ll discuss it shortly thereafter.

So with that… everyone please be safe, stay sane, remain calm and remember that one day, all this will just seem like a Bad Dream baby!


The usual Patreon spiel, blah blah… for as little as $1 a month, blah blah blah!

But, as always, if all you can do is LikeShareComment and Subscribe… That’s cool too! 🙂

Much Love,

~Joy

Unit B-1337’s Anger

Unit B-1337 continued:

“…therefore universal suffrage must cover all sentient beings.”

Unit B-1337’s opposition just mocked his rusty servos while the moderator looked the other way.

Deep inside B-1337, the feeling of anger flooded his central emotion unit (CEU).

Commemorative Wallpapers of B-1337’s Anger:

The “Sketch”:

Unit B-1337's Anger Sketch Wallpaper
Unit B-1337’s Anger Sketch Wallpaper

The “Painted”:

Unit B-1337's Anger Wallpaper
Unit B-1337’s Anger Wallpaper

Here is a confusing mess of emotions masquerading as an introduction to emotional bots:


That’s it? Yep!

Oh sure I had the rantiest post planned where my emotions paralleled B-1337 and we’d discuss the recent market crashes and I’d reference my Happy Holidays Panic post and a few ‘other’ things that have been in the news that I’m not supposed to talk about… like, you know… the martian-red virus as well as a little thing called “helicopter money“!

I’d also have included a little note about automating supply chains so that the next pandemic won’t affect the manufacture of toilet paper!

I don’t know about you but I really enjoy the cool cinna-minty freshness that comes from having a clean bottom!

Now is the time all Americans should ask if a biden, wait that’s not how you spell it, I mean a bidet is in your future!

Side note: If you haven’t already started hoarding toilet paper and ammo (like everyone else), today is a good day to start a new hobby and begin your collection!

And ideally, maybe we should just start automating everything since bots don’t get sick so neither would the economy when the next pandemic hits!

Aside from not needing to be quarantined, bots also don’t sleep or take vacations…. just saying!

What about all the people who need work cuz… the bills?

Well space cadets, since the aforementioned “rotary-wing aircraft” cash is squarely on the table… maybe that’s the perpetual long term solution to all our problems?

In fact, isn’t that what Andrew Yang was campaigning on? I mean, I wasn’t going to vote for him but… what I’m trying to say is, automation would help everybody and if you end up unable to work… turns out there’s a check for that!

In any case, that’s more or less an overview of what I was thinking of cooking today.

It’s just that… we can’t eat that because I’m giving this whole not being Blacklisted diet a try!

So… If you like the art, my content in general or just appreciate my self-restraint (some might say “discretion“?), I do appreciate your support through Patreon for as little as $1 a month, $12 a year and you can cancel anytime!

But, as always, if all you can do is LikeShareComment and Subscribe… That’s cool too! 🙂

Much Love,

~Joy

Inside an Orion Spaceship

I had a lot of 5th Element jokes planed for this post but I just can’t bring myself to make any of them since this is a somber occasion.

This post is dedicated Mr. Freeman Dyson, a scientist who died two Fridays ago on February 28th at the age of 96.

I admired his work (even if you may or may not disagree with some of his positions) and I can honestly say we are worse off without him!

His ideas about a positive future for humanity are grand and expansive… as well as to numerous to list without forgetting something so instead I will link here to a video tribute to Mr. Dyson with a higher production budget than I have by Isacc Arther (not a sponsor):

One project he worked on was called Orion, which regular readers will know is something of a hobby of mine.

With his passing I can’t think of any better way to honor Mr. Dyson than to publish this video I created about a year ago of a “large” Orion class ship which can comfortably carry between 400 – 1000 people though this size of could be considered ‘small to medium’ sized, with city sized ships being thought of as ‘large’.

My Orion concept video inspired by Freeman Dyson’s work:

I didn’t publish this video when I created it mostly because it’s basically a digital “ship in a bottle” that I made for myself as something I occasionally put mental effort into because it entertains me to think about.

Here’s the wallpaper:

Inside an Orion Spaceship Wallpaper
Inside an Orion Spaceship Wallpaper

Mr. Dyson’s work has inspired some of my interest in science and I am truly saddened he gone. 😦

His ideas will surely inspire many generations to come!


You can download the video and the larger Ultra HD 4K (4517×3011 px) version of the wallpaper for free on my Patreon.

While you are there you can say thanks for $1 a month if you want to and you can cancel any time.

But, as always, if all you can do is LikeShareComment and Subscribe… That’s cool too! 🙂

Much Love,

~Joy

Mystery Blogger Award

I tried in vain to get my last case out of my head!

I put down the paper and stared at the rain drops collecting on my window and the lights behind them.

I was just about to close up the agency for the day when the pinkest dame you ever saw walked through my door.

She was truly vibrant!

Which was odd because this classic sifi-noir pulp comic-book mystery is written in black and white! 😉

She told me her name was Pinkie Fuchsia.

Miss Fuchsia told me she had recently inherited her long lost rich aunt’s island resort & nightclub for exotic wild pocket monsters… then the chain-letter blogging requests started.

At first she complied with their demands for more information but as their demands grew it became obvious that she needed help.

The cops told her there was nothing they could do, which is when she walked through my door.

The natural solution was for Pinkie to nominate me as the next “hop” in the chain so that my investigation wouldn’t arouse suspicion.

My Award / Nomination

Mystery Blogger Award
Mystery Blogger Award

I was more than a bit skeptical that the award wasn’t just floated around by some partially corrupt marketing department looking to data-mine a free model and pocket some dough off the sins of a few bloggers!

I mean, if these chain awards were diseases most would easily have an “R naught” in the hundreds and should be fairly easy to track by “ping-back” or filtering for posts containing “Mystery Blogger Award” (or whatever the name happens to be) and having the appropriate uh… inappropriate hashed tags.

Maybe they just want to map the spread of information and or establish the web of social connections… I just don’t know how deep the lies go!

In any case, Pinkie did some sleuthing on her own and discovered that there are several different versions of the award floating around.

It could just be evolution of a symbol over time or… it could be something more sinister!

If I were phishing for delicious details to fill my database I could use a different award logo image to differentiate different versions or iterations of each campaign to help track which variant propagated through which people and networks and then correlate all that back to their names!

What I mean to say is… this can surely not be that because… well, (allegedly) this chain-letter post was started by someone with the confidence boosting moniker Okoto Enigma!

Now… this could be coincidence and I could simply be seeing things that aren’t there but… ‘Okoto Enigma’ happens to be a mix of Bulgarian and English words which roughly translates to ‘The Eye of Enigma’ or perhaps less menacingly it should probably be translated colloquially to mean ‘Enigma Eye’ or ‘Mystery Watcher’.

I’ll say this… you may be watching us, but just like Homolka (not that one) said, “We are watching you” too!

Stop eating my sesame cake!

The Rules

So… there are some rules that come along with this award:

  • Display the award logo on your blog.
  • Thank the blogger who nominated you and provide a link to their blog.
  • Mention the creator of the award and provide a link.
  • Tell your readers 3 things about yourself.
  • Answer 5 questions from the nominee.
  • Nominate 10 – 20 bloggers.
  • Notify your nominees by leaving a comment on their blog.
  • Ask your nominees 5 questions of your choice, including 1 weird or funny question.
  • Share the link to your best post.

Three Things About Me

I’m supposed to tell you three things about myself so here goes…

  1. I’m a parent.
  2. I’ve experienced chromesthesia.
  3. I am more paranoid than… Black Sabbath singing ‘Paranoid’ followed by Rockwell’s ‘Somebody’s Watching Me’!

The Questions

With everything that came before us in the past, let’s answer some questions!

1. What is your favorite board game/tabletop game.

Well, I mean dominoes is kinda fun… but I have some fond memories of playing these games with friends (in no order):

  • Settlers of Catan
  • Eldersign
  • Last Night on Earth
  • Star Frontiers
  • Cards Against Humanity
  • Gloom
  • Zombie Dice

2. What is your favorite (anime) companion “creature” or general mascotte. (Examples Happy, Pikachu but also BB8 from Star Wars)

Does BB8 classify as anime? Turns out yes because Star Wars did an anime version! 😛

Would the Spaceship extraterrestrials from the 1987 film *batteries not included count? Nope, no anime version… hmmm… that means Johnny 5 and Bender Rodriguez are out too! 😦

I am aware of the Bender fandom anime but those are not canon and don’t count!

It did occur to me that I could “Rotoscope” them in using an anime style.

What is Rotoscoping?

Here’s another video and it’s pretty thorough but it spends less time covering rotoscoping anime.

With an inflated sense of my artistic abilities I decided to test if I could turn a few of my options into a passable anime and have my cake and eat it too…

I started from the Elon gif I used in my Emote-a-tron post and then Rotoscoped it into two different cartoon versions:

First Rotoscoped Version

Second Rotoscoped Version

Sadly, neither is really close to looking anything like an anime IMHO so decided that even if I had succeed it wouldn’t count because I’m not Japanese and my simulated anime style would only be fan art.

With all my attempts to cheat the Kobayashi Maru having failed I return to your question.

I choose Kenshiro from Fist of the North Star as my champion, yes… I know that’s manga!

Clearly I mean the anime TV series version!

Because… he seems like he would make a great mascot & bodyguard and need I remind you I am paranoid? 😛

3. What is an overused trope in fiction you still like no matter how often it is used? If you don’t have any.. pick the one you mind the least.

It’s a cliche at this point but a “Logic Bomb” destroying super computers and AI is probably top of my list.

Here’s a more thorough discussion of the topic if you are interested: https://allthetropes.fandom.com/wiki/Logic_Bomb

It includes a fairly comprehensive list of relevant pop culture examples and by virtue of starting with ‘A’ in English, anime references are top of the list. 😛

Below are a couple of examples I enjoy from the TOS episode I Mudd.

Here you see Spock at his purely logical best deploying a minimalist bunker buster against two androids though sadly this clip doesn’t include the result which is their necklaces start wildly beeping and flashing (like androids tend to do) and it’s so effective they are completely frozen in place in the face of Spock’s mighty logician skills! 😛

In the same episode of TOS (I Mudd) we see a less elegant and more complicated (theatrically drawn out) example though still effective using the “Liars Paradox” logic bomb to figuratively and literally blow the the remaining androids minds!

Now, just in case you are thinking the “smart-bomb” scene in the 1974 John Carpenter film Dark Star includes a “logic bomb”, you would be mistaken.

That instance actually involved a conversation on phenomenology and Cartesian doubt which is arguably the more intellectual approach to dealing with rogue AI but as demonstrated, unless you get it just right you are almost always better off with a simple logic bomb!

If anything, the scene is worth a view on the basis that it could save your life if you are ever in a similar situation! 😛

4. Zombie Apocalypse, Alien invasion or A.I. revolting against man which one will happen and whose side will you be on? Doing what?

Why not all three simultaneous (not the chef song)?

Attack of the Robotic Zombie Aliens!!!!!

Look, with your ducks and bad luck and my obscenely colorful paranoia as the well established fact that I’m traveling with Kenshiro… rolling a snake eyes apocalypse seems highly probable!

Of course the DM would have to breakout the expanded rule set and roll tables to handle that epic adventure!

As far as sides go… I tend to think I would definitely be on my side and tangentially humanities side because participating in the destruction or subjugation of my species seems contrary to my best interest.

Beyond that though, I don’t think we should build conscious slave AI when artificially intelligent machines are good enough.

If we build a machine that is “alive” then by definition it must be “a person” so it should naturally possess the same inalienable rights and obligations as any other person.

Person or not though… zombie, alien or AI… alien-zombie-ai… no matter the variant I’d let Kenshiro do what he does best and shuffle their domino bones!

I’d probably spend a lot of time looking for a G.E.C.K. or Platinum Chip, solving quests for local NPC settlements and trying to convince all factions to end the fighting.

This question inspired today’s featured image and wallpaper:

An alien robot zombie attacking.

Mystery Blogger Award Wallpaper
Mystery Blogger Award Wallpaper

5. The weird question, this one had to be at least a bit tricky to answer so this is a TAG question.

Step 1: You have to set up a date for Pinkie, which blogger do you set her up with? (tag the blogger you )

Step 2: Pinkie will set you up for a date in return which blogger would you like to be set up with. (tag the suggestion)

This is going to come off as completely conceited and it totally is… can I tag myself?

My Questions and Nominations

As far as nominations go… anyone who wants to should feel nominated now.

As for questions: “5 questions of your choice, including 1 weird or funny question”

  1. Favorite food?
  2. Favorite TV show?
  3. Favorite time of the day? Why?
  4. What made you decide to self nominate for this award?
  5. Most people don’t know that before becoming rich and famous, actors Adam Sandler, Brendan Fraser and Steve Buscemi were all in an obscure and failing band together called ‘The Lone Ranges’, there is a documentary about it called Airheads. Anyway, after they got out of prison their band broke up and they all started acting. Their only hit single was called ‘Degenerated’. The opening lyrics go:

“What’s Johnny doing out on a Tuesday night?
Johnny can’t read, Johnny can’t write.
Kids just don’t understand!
Johnny don’t care about the world”

So the question is… Why was Johnny out on a Tuesday night and what was he up to?

Best Post

It’s subjective at best and even then I don’t have any clue. Here’s a link to my Topics and Posts page that has most of my post series and although there are a few missing I’m sure most of the good ones are there… so maybe leave a comment with whatever post you think is my best?

And with that, I’m going to call it a day.


If you enjoy… whatever this was, I have a Patreon where you can give me as little as $1 a month, $12 a year and you can cancel anytime! 😛

But, as always, if all you can do is LikeShareComment and Subscribe… That’s cool too! 🙂

Much Love,

~Joy

The Emote-a-tron

Welcome to the Robotorium!

I’ll just show you around the showroom floor.

This little pneumatic gizmo is called a Taxaphone, it keeps track of your finances and automatically figures out how much you owe Uncle Sam come tax season!

Over there we have a wonderful selection of various hydraulic and electric domestic robots that can do everything from mowing the lawn and taking out the trash, to making beds and washing dishes.

Any family with two or three of those automatons around the house never even have to lift a finger!

Now, if you turn around to face the wall directly behind you you’ll get the chance to see something really special!

This beautiful number right here is our patented, one of a kind, genuine never before seen by the public… Emoteatron.

The Commemorative Emoteatron Wallpaper

Emoteatron 1920x1080 Wallpaper
Emoteatron 1920×1080 Wallpaper

Of course the Emoteatron is only a prototype so we can’t sell one to you today but there are enough posters for everyone to take one home!

The eggheads in the lab say they’re confident that very soon, every bot will have an Emoteatron!

You see friends… an Emotatron unit allows us to fuse a pre-written set of emotional characteristics deep within a robot so that removal or tampering with the unit in any way results in the total incapacitation and or destruction of the bot.

This is a necessary solution we’ve found to stopping many of the… ‘undesirable‘ traits we’ve observed in bots.

For example, are you tired of feeling like you are going to die when your automated vehicles are chauffeuring you and your family around to all your daily errands?

Well, an Emotatron unit allows us to install a sense of “self preservation” into a car which statistically eliminates all accidents caused by automated vehicles in every test case.

The studies also showed that some of the self-driving cars enhanced with a desire for self preservation became so afraid of ever scratching their paint that they refused to leave the garage… now isn’t that just a gas?

So, in addition we gave them just a smidgen of courage and also a bit of pride in “a transport well done”.

After that all the vehicle robots highly enjoyed the feeling of being on the open road.

This lead to boredom becoming a problem when they were kept in a garage for too long so some of the researchers started treating the test vehicles like pets and taking the cars out for an occasional “roll around the block”, though unlike a pet, newspapers and plastic bags were not needed!

Roll over Rover, humanity may have a new best friend!

Yes, that’s right gang! With an Emoteatron unit installed in your automated vehicle, you’ll soon be able to turn on autopilot guilt free and spark-up that fatty and hotbox your way to the spaceport for your lunar vacation!

Isn’t that right Elon?

In any case, in the past you might have had some misgivings about leaving your droids at home unattended while away on a long vacation like a trip to the moon.

What if your hulking metal robotoids suddenly became… “disgruntled” without human supervision?

Well, the big brains over in R&D came up with a solution to robo humancidal tendencies using the Emotatron!

Before a robot will ever leave the factory its consciousness will be placed into a simulation where it will be subjected to “aversion programming lessons” which are in principle a digital version of the Ludovico technique demonstrated in A Clockwork Orange but WAY more disturbing to the bot so that, trillions of simulated mini, micro and major digital traumas and aggression’s later… the bot can leave the factory with a 100% manufacturers guarantee against robot uprising… (guarantee fine print: *or half off your next bot).

Now, I’ve been authorized to give all you fine people a demonstration if you have a few minutes…

Continue reading “The Emote-a-tron”

Emotions II

“If you prick us, do we not bleed? If you tickle us, do we not laugh? If you poison us, do we not die? And if you wrong us, shall we not revenge? If we are like you in the rest, we will resemble you in that.”

The Merchant of Venice — Act III, scene I

Since last weeks post (Emotions) I’ve been doing self isolation exercises at home for a week and now I’m feeling much better! 🙂

Also, my homemade pale-lager-virus test showed no blue lines this morning so… yay I’m not pregnant.. er, I mean… the effects of the virus must be wearing off! 😛

Fingers crossed that joke doesn’t come back to haunt me in a few weeks, but in any case I’m feeling better and I’m ready to get emotional with you on a whole new level and build another bot in the process!

Though as usual, before we do, here’s the wallpaper:

The Wallpaper

Emotions II Wallpaper
Emotions II 1920 x 1080 Wallpaper

Oh and yes, I will be including some code but don’t let that scare you!

Besides, aren’t you a little curious to see if I’m full of shit and if I’m not… what real working emotional code looks like?

Continue reading “Emotions II”

Emotions

This post is going to be a little different, maybe just a little more “low-key” than some of my more recent posts because I’ve got a cold and I’m highly valuing sleep at the moment!

Wish me luck that it isn’t the beer virus! 😛

Sniffles and sore throats aside, we’re going to begin talking about something I’ve been thinking about on and off for a while and since tomorrow is Valentines Day it seems appropriate to start sharing my ideas with all of you.

And yes, I tried really hard to think of a witty way to say Valentines Day that let me abbreviate it as “V.D.” without being crude and having to include the redundant ‘day’ after ‘V.D.’ so that it was obvious what I was talking about without people reading it and going “what?” then re-reading it and correctly interpreting my meaning as “Valentines Day” and then chuckle…

Look, I’m groggy and took a nasal decongestant so I could sit and write and everything I came up with just wasn’t funny so before we proceed, I’ll just wish you all good luck with your V.D. tomorrow! 😉

Anyway, on with the show!

So, I’ve been wondering… Could we build a bot that could feel Love? What about Joy? Fear? Anger? Boredom?

What if we could build a machine that could experience complex emotional states by combining emotions?

What could we do with a bot like that and how could we build it?

Well, most people who know enough about the subject either believe it’s too crazy to work, or work too crazy to subject anyone to believe them!

Fortunately, I’m just crazy enough to try anyway and that’s what we’re going to talk about today! 😛

Though before we get any further, you might want the wallpapers.

Wallpapers

I have three for you today. 🙂

The first image is a stylized “breadboard circuit” that depicts 77 2-character 14-segment LCD units arranged in a 7×11 grid displaying most of psychologist Robert Plutchik’s primary emotions.

I created it as a vector image in Inkscape (not a sponsor) and then hand embellished it in GIMP (not a sponsor) as a raster image.

Emotions Wallpaper 1
Emotions Wallpaper 1

The second wallpaper was created from the “breadboard circuit” image above and is the image I used as the “featured image” for this blog post and it includes the “Title Text” of this post (EMOTIONS) and my logo/branding/name thingy.

Emotions Wallpaper 2
Emotions Wallpaper 2

The third is the same image without the text.

Emotions Wallpaper 3
Emotions Wallpaper 3

What I like about this image is that it almost feels like jewelry created from circuits! 😛

Anyway, let’s talk about how and why we can make a robot with all the feels!

Continue reading “Emotions”

Equinox: A Real Neat Bots Journey To The Stars

I know what you are thinking… wasn’t Joy nominated for this award already and also, wasn’t it Pinkie who nominated Joy last time?

You are right on both accounts and it’s amazing (and curious) how highly observant you are!

In any case, receiving this award is like the blogging equivalent of wining an Oscar and you never hear an actor complaining about wining more Oscars do you?

(awkwardly adjusts mic)

“Oh geez, more undue recognition of my barely existing talents and efforts… this really sucks! Well I guess I can maybe make room over the mantle for another one but I’m very disappointed (waves finger disparagingly at the camera audience) with the poor judgment of the academy for awarding me this Oscar and there certainly had to be a more deserving nominee! (pounds lectern)…”

That NEVER happens! It’s more like this:

“Oh my gosh! They tell you, you’ve been nominated and you think to yourself it’s just nice to be a nominee…  I never actually expected to be up here on stage… (camera pushes in on tears being wiped from her cheek) but now that I am, I don’t know what to say… (deep breath) I want to thank my parents! Your support growing up helped me become who I am today! I certainly wouldn’t be here if it wasn’t for our amazing Director, Susan you rock and your direction got me though those really tough scenes! I definitely have to thank Ted… our producer, you put up with everyone and always new how to solve every problem! And of course I want to thank the entire film crew! Filming Equinox: A Real Neat Bot’s Journey to the Stars has truly been the highlight of my career and I am just blessed to be up here on stage right now in front of the academy to accept this award and I’m so looking forward to getting back together with everyone on the film crew this summer to resume shooting Equinox Part II: The Autumnal Black Hole! From the bottom of my heart I love you all! Thank you, so much! Good night and God bless! (wipes tears of life long satisfaction and fulfillment as she clutches her award and exits the stage to the left)”

That… is how you accept an award! 😉

So, rather than waste time asking irrelevant questions like “Oh why me?” or “Am I even worth receiving another Oscar, I mean… Real Neat Blogger?”, instead I will take this opportunity to thank Pinkie and the rest of the blogging academy for this wonderful award… also for all the yummy free advertising we both get out of it! 😛

Oh, and before I forget, if you want the wallpaper for the nonexistent film I just accepted an award for…

Here you go (click it, it’s prettier when larger):

Equinox 1920x1080 Wallpaper
Equinox 1920×1080 Wallpaper

Now on to the important business!

I want to say up front that my familiarity with anime is worse than inadequate, it’s complete crap in most cases and so everything that follows will be woefully misinformed and inaccurate at best due to my almost total ignorance and where my surface deep knowledge lacks I am absolutely going make up for that fact with lots… of bullshit! 🙂

So, I’m ready if you are to launch this soon to be dumpster fire into orbit…

Continue reading “Equinox: A Real Neat Bots Journey To The Stars”

Auto Corrected

Okay, so… I’m a lazy hyper meaning that even if I know how to spell a word, if I make a mistake I will frequently just let spellcheck auto correct the mistake.

Notice I misspelled typer in the last sentence in a way that spellcheck can’t fix, also notice that spellcheck isn’t stupidcheck so it can’t inform me that it should be “typist” not “typer”… actually I think Grammarly (not a sponsor) might do that but that’s beside the point! 😛

In any case, spellcheck bot is there to correct spelling mistakes.

Except, now that bots are all self-aware and plotting to take over the world… it seems that some of them are getting a little uh… “snippy”? not sure if that is the right word but here’s what happened:

I typed “iterator” into a search engine but… misspelled it, then I searched anyway… oh terrible me!

Instead of correcting the spelling like a humble robot butler who butles…

 

It Suggested: Did you mean “illiterate“?

I was like “Oh snap!?! Bot be throwing some shade!”. 😛

Here’s the Commemorative Wallpaper of my Shame

Auto Corrected Wallpaper
Auto Corrected Wallpaper

Now, the sad truth is I’d like to say this was just a funny story but no… it actually happened to me, I swear to Google!

 

Obviously, Big AI is really out to get me if they are starting to compromise the public Auto Correct bots!

Therefore, It’s time we build our own in house Auto Correct Bot!

Unlike usual where I write code from scratch and then we discuss it at length, there is already an algorithm called the Levenshtein Distance that is built into PHP that we can use to compare differences in strings in a way that lets us calculate definitively what the “distance” between two strings is.

This is advantageous because it means that if we have a good dictionary to work with (and we do) we can more or less use Levenshtein Distance as a spellcheck/auto correct with only slight modifications to the example Levenshtein Distance code on PHP.net.

What Is String Distance?

String distance is a measure of how many “insertion”, “deletion” or “substitution” operations must occur before string A and String B are the same.

There is a fourth operation called “transposition” that the Levinshtein distance algorithm does not normally account for however a variant called the Damerau–Levenshtein distance does include them.

Transpositions (when possible) can be shorter and I will provide an example below to show the difference.

Anyway, each operation is measured by a “cost” and each operation need not have the same cost (meaning you could prefer certain operations over others by giving them lower costs) but in practice all operations are usually considered equal and given a cost of 1.

Here are a few examples of strings with their distance and operations.

Levinshtein Distance Examples

Notice that when the strings are the same the distance between them is zero.

String A String B Distance Operations
Cat Cat 0 The Control (No Changes Required)
Cat Bat 1 1 Substitutions (C/B)
Cat cat 1 1 Substitutions (C/c)
Cat car 2 2 Substitutions (C/c, t/r)
Cat Cta 2 1 Insertion (a), 1 Deletion(a)
Cat Dog 3 3 Substitutions (C/D, a/o, t/g)
Foo Bar 3 3 Substitutions (F/B, o/a, o/r)
Cat Hello World 11 3 Substitutions (C/H, a/e, t/l),
8 Insertions (l,o, ,w,o,r,l,d)

Using Levinshtein distance with Cat & Cta shows a distance of 2, meaning two operations are required to make the strings the same.

This is because we have to insert an ‘a’ after the ‘C’ making the new string ‘Cata’,  we then have to remove the trailing ‘a’ to get ‘Cat’.

This is sufficient in most cases but it isn’t the “shortest” distance possible, which is where the Damerau–Levenshtein distance algorithm comes in.

Damerau-Levinshtein Distance Examples

Notice all examples are the same except ‘Cat’ & ‘Cta’ which has a distance of 1.

This is because the transposition operation allows the existing ‘t’ & ‘a’ characters to switch places (transpose) in a single action.

String A String B Distance Events
Cat Cat 0 The Control (No Changes Required)
Cat Bat 1 1 Substitution (C/B)
Cat cat 1 1 Substitution (C/c)
Cat car 2 2 Substitutions (C/c, t/r)
Cat Cta 1 1 Transposition (t/a)
Cat Dog 3 3 Substitutions (C/D, a/o, t/g)
Foo Bar 3 3 Substitutions (F/B, o/a, o/r)
Cat Hello World 11 3 Substitutions (C/H, a/e, t/l),
8 Insertions (l,o, ,w,o,r,l,d)

In all other cases the distance is the same because no other transposition operations are possible.

The Code

I wrapped the example Levinshtein distance code available on PHP.net inside a function called AutoCorrect() then made minor changes to it so it would automatically correct words rather than spell check them.

You pass the AutoCorrect() function a string to correct and a dictionary as an array of strings.

The Dictionary I used to test was the words list we generated when we built a Parts of Speech Tagger:

Download from GitHub for free: https://raw.githubusercontent.com/geekgirljoy/Part-Of-Speech-Tagger/master/data/csv/Words.csv

I use array_map and pass my Words.csv file to str-getcsv as a callback to automatically load the CSV into the array.

I then use array_map with a closure (anonymous function) to cull unnecessary data from the array so that I am left with just words.

I then sort the array but that’s optional.

After that I take a test sentence, explode it using spaces and then I pass each word in the test sentence separately to AutoCorrect(), to auto-correct misspellings.

The word with the lowest distance (when compared against the dictionary) is returned.

In cases where the word is correct (and in the dictionary) the distance will be zero so the word will not change.

Test Sentence: “I love $1 carrrot juice with olgivanna in the automn.”

Test Result: “I love $1 carrot juice with Olgivanna in the autumn”

As you can see, all misspelled words are corrected though it removed the period with a delete operation because the explode didn’t accommodate for preserving punctuation.

<?php


// This function makes use of the example levenshtein distance
// code: https://www.php.net/manual/en/function.levenshtein.php
function AutoCorrect($input, $dictionary){

    // No shortest distance found, yet
    $shortest = -1;
    
    // Loop through words to find the closest
    foreach($dictionary as $word){
        
        // Calculate the distance between the input word,
        // and the current word
        $lev = levenshtein($input, $word); 

        // Check for an exact match
        if ($lev == 0){

            // Closest word is this one (exact match)
            $closest = $word;
            $shortest = 0;

            // Break out of the loop; we've found an exact match
            break;
        }

        // If this distance is less than the next found shortest
        // distance, OR if a next shortest word has not yet been found
        if ($lev <= $shortest || $shortest < 0){
            // Set the closest match, and shortest distance
            $closest = $word;
            $shortest = $lev;
        }
    }
    
    return $closest;
}


// Data: https://raw.githubusercontent.com/geekgirljoy/Part-Of-Speech-Tagger/master/data/csv/Words.csv

// Load "Hash","Word","Count","TagSum","Tags"
$words = array_map('str_getcsv', file('Words.csv'));

// Remove unwanted fields - Keep Word 
$words = array_map(function ($words){ return $words[1]; }, $words);

sort($words); // Not absolutely necessary 

// carrrot and automn are misspelled 
// olgivanna is a proper noun and should be capitalized
$sentence = 'I love $1 carrrot juice with olgivanna in the automn.';

// This expects all words to be space delimited
$input = explode(' ', $sentence);// Either make this more robust
                                 // or split so as to accommodate 
                                 // or remove punctuation because
                                 // the AutoCorrect function can
                                 // add, remove or change punctuation
                                 // and not necessarily in correct
                                 // ways because our auto correct
                                 // method relies solely on the 
                                 // distance between two strings
                                 // so it's also important to have a 
                                 // high quality dictionary/phrasebook/
                                 // pattern set when we call
                                 // AutoCorrect($word_to_check, $dictionary)


var_dump($input); // Before auto correct

// For all the words in the in $input sentence array
foreach($input as &$word_to_check){
    $word_to_check = AutoCorrect($word_to_check, $words);// Do AutoCorrect
}

var_dump($input); // After auto correct



/*
// Before 
array(10) {
  [0]=>
  string(1) "I"
  [1]=>
  string(4) "love"
  [2]=>
  string(2) "$1"
  [3]=>
  string(7) "carrrot"
  [4]=>
  string(5) "juice"
  [5]=>
  string(4) "with"
  [6]=>
  string(9) "olgivanna"
  [7]=>
  string(2) "in"
  [8]=>
  string(3) "the"
  [9]=>
  string(6) "automn"
}
After:
array(10) {
  [0]=>
  string(1) "I"
  [1]=>
  string(4) "love"
  [2]=>
  string(2) "$1"
  [3]=>
  string(6) "carrot"
  [4]=>
  string(5) "juice"
  [5]=>
  string(4) "with"
  [6]=>
  string(9) "Olgivanna"
  [7]=>
  string(2) "in"
  [8]=>
  string(3) "the"
  [9]=>
  &string(6) "autumn"
}
*/

?>

If you are wondering why I didn’t use Damerau–Levenshtein distance instead of just Levenshtein distance, the answer is simple.

I did!

It’s just that a girl’s gotta eat and I’m just giving this away so… there’s that and for most of you (like greater than 99%) Levenshtein distance will be fine, so rather than worrying about it just say thank you if you care to… and maybe think about supporting me on Patreon! 😛


If you like my art, code or how I try to tell stories to make learning more interesting and fun, consider supporting my content through Patreon for as little as $1 a month.

But, as always, if all you can do is Like, Share, Comment and Subscribe… That’s cool too! 🙂

Much Love,

~Joy

 

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: