Showing posts with label ngram art generation. Show all posts
Showing posts with label ngram art generation. Show all posts

Tuesday, January 31, 2023

Understanding the ngram

 Ngrams are complicated, especially for those without a formal understanding of computer data objects. I wanted to post about ngrams and why they're special, interesting, and for as simple as they are, so powerful.

How do we store data in a computer? We have variables for that. However, assigning one name to every variable makes it clunky to recall. For that reason, we want to organize the data into chunks. One of the very earliest and simplest data types is the linked list.

The linked list is a 1-dimensional line of variables connected to each other. The list doesn't actually have to "exist" as its own separate object. Each of the elements of the list point to other elements in the list. So, the first object points to the second object and the second object points to the third and back to the first object. So, all you need to start a list is a first object. 

I have a list:

  1. Hieronymus 
  2. Sofonisba
  3. Grant 
  4. Blastonymus
Instead of numbers, which you don't have, you have something like this:

Hieronymus-Sofonisba-Grant-Blastonymus

So, if we want to get to Blastonymus, we must first pass Hieronymus, Sofonisba, and Grant, taking three steps. We can also move back on the list by calling the pointers that link the objects to one another. The most important thing to understand here is that you can only move back or forth. That means that you're in a one-dimensional space or on a line. That's the most important thing. Imagine yourself as a little car driving down the street trying to get to your friend Blastonymus's house but you're currently hanging out with Hieronymus. You must now drive three houses down. Your entire universe is those four houses.

Binary trees

The garden of forking paths is your binary tree. Every time you make a choice, you're presented with another one until the space ends. The sense of organizing information like this is that it allows you to issue directions in either left- or right-hand turns. This space still makes sense to us. Even when we're presented with three or four choices. We can still move back and forth in a way that doesn't entirely mess with our sense of direction. Once we get to ngrams that will stop.

Ngrams

Linked lists are one-dimensional data objects. You can only go back and forth. Binary trees are two-dimensional data objects because they bifurcate and offer more paths. Ngrams are n-dimensional data objects and they cause problems.

Imagine that you're at Hieronymus's house and you go to Blastonymus's house. So, now you're there, but gosh, you forgot your important object. So, now you must go back. The road you took is not the same road you need to take back. In fact, that road is gone. Worse, there may be no way to get from Blastonymus' house to Hieronymus's house. 

Further, instead of one direction, you have an indefinite number of dimensions that are continually added as we accrue ngrams. While it's certainly possible you could find your way back, it's also possible that way does not exist. 

With a linked list or a binary tree, you can always work your way back. With ngrams, you can end up on an island in a universe with no exits. 

Demonstration

"The first dog demanded that the second dog be more of a dog."

This is our sentence. An ngram algorithm will take this sentence and return the following data:

  • The->first(1), second(1)
  • Dog->demanded(1), be(1), .(1)
  • First->dog(1)
  • Demanded->that(1)
  • ...
In this case, the data for the ngram "The" will produce the links "first" and "second". The numbers represent the weight, or how many times the two terms come in sequence. Once you go from "The" to "first", there's no way back to "The". The ground collapses behind you. But that's not the problem spatially.

Even if you could get back from "first" to "The" the same roads won't be awaiting you.

So, let's say we drive from Hieronymus' house to Sofonisba's house. Sofonisba's house could be connected to Hieronymus's house or hundreds even thousands of other houses that suddenly appear once we're at Sofonisba's. So, even if there's a link back to our house, it's one of the thousands of others that lead elsewhere.

The ngram behaves like a multi-dimensional spatial object akin to the Hypercube.

Wednesday, January 25, 2023

Fun and Necromancy with AI Art

 You can practically raise the dead


What isn't to love about being able to resurrect your favorite artist, long dead of course. It's always better to pick a dead artist, especially for acts of necromancy. So, today we're going to pick three dead white male artists. As a human, you don't want to stray too far from home when it comes to borrowing art. The lived experience of other cultures is not yours to borrow. For that reason, I gravitate toward paranoid European males with religious excitation. Obviously, Hieronymus Bosch is my favorite painter. 

What can the AI do? There are serious limitations. I don't know exactly how this algorithm works, but I can guess that items or objects in a painting are tagged and named. Hence, you will never see a television set in a Bosch painting. Asking the AI to have Bosch paint a television is thus outside the realm of possibility. 

What is not outside the realm of possibility, however, is to use an image of a TV set as a template and run it through the algorithm with "Hieronymus Bosch" as one of the imputs. The algorithms I use (Stable Diffusion) do really well with Bosch, and all my Bosch-style stuff is super creepy, which I like. 

Now, it would be boring just to replicate various things in Bosch's style, although, it is worthwhile because Bosch is awesome. So, you're going to end up with some great creepy images. But you'll get bored after a bit. So you say, "I must find another painter to place into the algorithm to give me some variety."

Who do you choose? Caravaggio. That guy sounds like a kick. We need one more and it would be boring to limit ourselves to standard representative art, so let's add Picasso. 

Now, all we need is a really cool image to inspire some art. Remember what I said before. No television sets. In this case, let's keep it straightforward. We know at some point, all three men painted scenes of battle. So, we'll do, "action painting, battlefield, battle," + "Hieronymus Bosch, Caravaggio, Pablo Picasso." The results are below:





These are three interesting offerings. It can be hard to pinpoint the style of any of the artists in the painted scene. It can be difficult to determine how much the AI weighted each of the names when it generated the images. Ultimately, there was a fourth, putrid, image that wasn't worth the effort of uploading. 

Let's look at the first image. It looks like you have a bunch of heavy infantry dug into a trench, and then some naked dudes wrestling. This seems like it's going to be hard to use as a template for future generation. 

Onto the second one. I love it. We have a creepy god-dude who looks like he's engaged with an angry skull man and then some human figures filling it out. In the background, you have a landscape that seems form-fitted around the foreground figures. There's a lot of promise here. 

The third image likewise has that creep factor we like to mine. You have one figure that looks vaguely demonic and two partial figures in various states of waste. Let's play with the second.

We're going to be boring and just throw the image through with the same inputs. We get three new images. The first is a repetition on our source image. In this case, the image is a bit better realized:


Hey. That might be ready for Instagram. 

Anyway, let's check out the next one:


Here we have various figures in apparent action poses. The overall sense of what they're doing is, I guess, striving. They may be in a battle, but not one of them is responding to any of the others. They are all engaged in their own personal strivings, yet pictured together. In the background, you have a human settlement that you see from afar without the humans. Evidence of community though. This is interesting and resonates on a number of levels. It's exactly the type of image we want to keep around. 

Lastly:


This is cool. The figures are interesting looking and you have a Bosch-ean figure who looks like he's just killed a man in a loincloth. So, a disturbing image of a murder. Interestingly, the murderer is a Bosch figure but the two victims are very Caravaggio. Picasso's influence can be seen in the layout of these paintings. Neither Bosch nor Caravaggio would have ever laid out a painting this way. 

Now, for my part, it's quite an honor to have been a part of a collaboration between so many great artistic minds. And when I add my poetry to the generation process, it's that much more rewarding. To wit: AI art generation is fun, rewarding, and potentially necromancy. 

Tuesday, January 24, 2023

What is it like making art with ai? And also "God as Chance"

Playing God

To answer the first question, it's like evolution, and you get to be God. Now, for a skeptic, God is no more than chance, coincidence, and random happenstance, if we even accredit that much substance to him. For others, the random happenstance and the successes and failures of life are evidence of God's favor and disfavor. We need only read the Book of Job to understand the human connection between good and bad life events and God himself. 

Growing up in a Catholic household, we're taught that God speaks to us through our experiences. We see signs as a matter of spirituality and these signs communicate things to us. They communicate things from God. At base, the skeptical approach to this would be to say, this is a fiction created out of chance to control that which is beyond our power to control, or at least place hardship into a context we can live with.

Today, methods of divination rely alternatively on chance or time. Astrology relies on time. I Ching relies on chance. Tarot relies on chance. Catholics rely on signs and happenstance. 

For skeptics, we all have life experiences that taught us valuable life lessons. But we don't attribute them to the workings of a conscious benefactor. 

As a writer working with ngram poetry, and now an artist working with ngram images, we rely on the random number generator to provide us with unique images each time through. There is no way to generate a random number ex nihilo. Instead, mathematicians create a "twister" algorithm that mimics the distribution of a randomly generated set. This algorithm would produce the same content over and over but for the fact that it takes one variable as a seed. Two seeds that are the same would produce the same set of numbers over and over. So, it looks like we have the same problem, right? We still can't generate a random number!

There are two ways around this problem. The first is to ask the user for a seed. The second is to generate the seed using the computer's unique timestamp. So, let's travel back to God. God is chance, and chance is Time. At least for those of us who use computer algorithms to generate poetry and images. 

Evolution

Now, how do animals evolve? Well, evolution gives us a testable if unsatisfying answer. If you throw poop at the wall enough times, eventually, you'll end up with a Picasso. Since you don't want to show your friends your crappy paintings, you only show them the Picasso. "Wow," they said. "That's like Picasso." The only major difference between you and Picasso is that Picasso is a painter and sculptor and you work in a different medium. 

Evolution keeps Picassos and throws away the rest. So, every new template is based on a previous Picasso. This recursive element is what allows the poop-throwing process to occasionally stick. We're always basing our next Picasso on a previous Picasso. 

To play God, you must be willing to cull. In fact, culling will be your most important act. In nature, the environment determines which are fittest. Some may see an invisible hand at play, but you don't need an invisible hand to describe what's happening. You only need the unpleasant metaphor I provided above. The artist thus becomes the equivalent of nature, selecting the fittest Picassos from the bunch. The vast majority of this will come down to chance. If you're a rabbit crossing an open field when an eagle happens to be flying by, it's the inverse of an artist noticing a particularly poignant representation and then selecting that for his Instagram or creating a sequence of images to tell a story, or alternatively, unfit for reproduction.

As a writer, you don't get to invent a lot of new words. You might get one or two if you're lucky. Ultimately, we're used to this. This mode of representation doesn't even feel new to us. This is our game. 

No pixels touched in the creation of these images

Each of the images presented in the series on this blog is untouched by image editing software. They were 100% generated by AI. Each pixel was laid by the AI. There was no human intervention other than selection and providing input. 

So, my creative contribution to this is still just language.