AI & LLMs

Generative AI Explained: From Text Generation to Image Generation

In six months, DALL·E 2, Midjourney and Stable Diffusion have turned text-to-image generation from a research curiosity into something anyone can use. Together with GPT-3 and Copilot, they have given a name to a new category: generative AI. We explain how text and image generators work, and the questions businesses should ask before using them.

By EthicalHat Research · · 3 min read
Infographic: 2022: the year generative AI went visual

This year, "AI art" went from niche to everywhere. In April, OpenAI unveiled DALL·E 2, which turns text descriptions into strikingly realistic images. Google followed with Imagen in May. Midjourney opened its public beta in July, and its images flooded social media. On 22 August, Stability AI and its collaborators released Stable Diffusion with openly available weights, so anyone with a decent graphics card can generate images on their own computer.

Earlier this month, an image made with Midjourney won first prize in a digital art category at the Colorado State Fair, prompting a heated debate about what counts as art.

Add GPT-3 for text and GitHub Copilot for code (generally available since June), and a new category has a name: generative AI.

What "generative" means

Most machine learning you have used is discriminative: it classifies or predicts. Is this email spam? What is the demand forecast? Generative models instead produce new content that resembles their training data, such as sentences, images, code or audio.

How text generation works

Text generators like GPT-3 are autoregressive language models. Given some text, they predict a probability distribution over the next token, pick one, append it and repeat.

flowchart LR
  P["Prompt: 'A short poem about the sea'"] --> M[Language model]
  M --> T1["token 1"] --> M
  M --> T2["token 2"] --> M
  M --> TN["… until done"]

Settings such as temperature control randomness: low values give predictable text, high values give more varied (and more error-prone) text.

How image generation works: diffusion

The big leap in image generation this year comes from diffusion models:

  1. Training: take real images and gradually add random noise over many steps until only noise remains. Train a neural network to predict and remove the noise at each step.
  2. Generation: start from pure noise and run the network repeatedly, removing a little noise each time, until an image appears.
  3. Text conditioning: guide each denoising step with an encoding of the text prompt, often from a model like CLIP that has learned how images and captions relate.
flowchart LR
  N[Random noise] --> D1[Denoise step] --> D2[Denoise step] --> Dn[… ×50] --> I[Image]
  T["Text prompt<br/>'a lighthouse at dusk, oil painting'"] --> E[Text encoder]
  E -.guides.-> D1
  E -.guides.-> D2
  E -.guides.-> Dn

Stable Diffusion adds an efficiency trick: it runs the diffusion process in a compressed latent space rather than on full-resolution pixels. That is why it runs on consumer GPUs rather than only in large data centres.

Generating an image with the open-source diffusers library takes a few lines:

python
import torch
from diffusers import StableDiffusionPipeline

pipe = StableDiffusionPipeline.from_pretrained(
    "CompVis/stable-diffusion-v1-4", torch_dtype=torch.float16
).to("cuda")

image = pipe("an isometric illustration of a secure data centre, soft lighting").images[0]
image.save("datacentre.png")

What people are using it for

  • Concept art and mood boards for design, games and advertising.
  • Marketing and social content drafts.
  • Product mock-ups and illustrations.
  • Text: drafting copy, summarising, classifying and answering questions (GPT-3).
  • Code: autocomplete and generation from comments (Copilot).

The hard questions

Copyright and training data. These models were trained on huge numbers of images and texts from the web, often without the creators' explicit consent. Whether that is lawful, and who owns generated outputs, is unresolved and likely to be tested in court.

Artists' livelihoods. Models can imitate the style of living artists by name, which many artists see as exploitation of their work.

Bias. Outputs reflect biases in training data, such as whose faces appear for "a CEO" or "a nurse".

Misuse. Realistic fake images, non-consensual imagery and disinformation. DALL·E 2 and Midjourney apply content filters; openly released models are harder to control.

Quality and reliability. Image models still struggle with hands, text within images and precise spatial instructions. Text models still make things up.

Questions for businesses

Before adopting generative AI tools, ask:

  1. What are the licence terms of the model and its outputs? Can we use results commercially?
  2. What data do we send to the provider, and is it retained or used for training?
  3. How do we review outputs for accuracy, bias and brand safety?
  4. Are we comfortable with the provenance of the training data, given our industry and reputation?
  5. How will we disclose AI-generated content to customers where appropriate?

The bottom line

Generative AI has crossed from research into everyday tools remarkably quickly. The underlying ideas (predicting the next token and removing noise step by step) are simple to state and extraordinarily powerful at scale. The technology is ready for experimentation. The legal, ethical and quality questions around it are not yet settled, and deserve as much attention as the demos.

Our agentic AI security team helps organisations explore generative AI with clear guardrails for data, licensing and review.

EthicalHat Research

The EthicalHat research team: penetration testers, SOC analysts and engineers writing about security, software engineering and AI.

Want an expert opinion on your own systems?

Email info@ethicalhat.com or call +1-844-838-4422. Our security engineers are happy to talk it through.