James Bond Film Title Generator

15 Feb 2021

“My name is Bond… James Bond."

James Bond is a fictional British secret agent created by Ian Fleming in 1953. Originally the subject of novels and short stories, James Bond has featured in a hugely successful franchise of films spanning decades. I grew up on a regular diet of James Bond films and fondly remember the excitement of the customary TV showing on Boxing Day.

Sean Connery, the original Bond [1]

The film titles are quite distinctive, and something about them makes them “feel” like a James Bond film title:

I started to think about what it was that made these film titles distinctive, and if I knew the answer to that, whether I could generate random film titles befitting of a James Bond film. Here’s a short journey to creating that generator. I’ve avoided delving into any code so that non-programmers can following along too, however I’ve linked to relevant lines in a separate gist of easy-to-follow Clojure code along the way. Source code for the final generator is shared at the end.

First Steps

Rather than diving in head first with Natural Language Processing and Machine Learning techniques, let’s start with some simple analysis. One intuition is that the titles employ several words repeatedly, such as “Live”, “Die”, “Never”, etc. Let’s explore that…

The first step is to split the titles into their constituent words[gist], also known tokenising. Some titles are compound words whereby two words have been joined together to form a single word, for example, “Skyfall”. These can be split into their component words for our purposes, in this example, “Sky” and “Fall”. Ordinarily you might automate the searching and splitting of compound words, but with only 26 short titles to play with, we can do this by hand.

Here’s our tokenised lower cased set of words:

dr no from russia with love gold finger thunder ball you only live twice on her majesty’s
secret service diamonds are forever live and let die the man with the golden gun the spy
who loved me moon raker for your eyes only octo pussy never say never again a view to a
kill the living day lights licence to kill golden eye tomorrow never dies the world is not
enough die another day casino royale quantum of solace sky fall spectre no time to die

There’s a total of 86[gist] words here where 68[gist] of them are unique. Incidentally, the frequencies of words appearing twice or more in our film titles is as follows[gist]:

the=5, to=3, never=3, die=3, live=2, golden=2, only=2, kill=2, day=2, with=2, no=2, a=2

Some of these words are stopwords, common words which don’t add much meaning to a title, such as “the” and “a”. If we ignore them, we’re left with[gist]:

never=3, die=3, live=2, golden=2, only=2, kill=2, day=2, no=2

So we have eight “distinctive” words[gist] out of 68 unique words. These words are repeated across several titles amounting to 18 occurrences[gist] of distinctive words out of a total of 86 words. That might not seem like a large number, but the number of titles containing the distinctive words is 13[gist]. That’s half of all our titles, so our intuition was pretty good:

Title Generation

We have our tokenised words, and our intuition about the importance of some of these words. Now it’s time to generate some titles…

The naive approach would be to take our set of words and throw them together randomly. The shortest titles are one word long, and the longest six[gist], so let’s create random titles of between one to six words inclusive[gist]:

Clearly this is nonsensical, though we may get lucky, such as with Dr Ball! The problem is that we’re not taking into account grammatical rules and sentence structure. We could dive into analysing the sentence structure of our titles, but again, let’s start with something much simpler. We already have perfectly good existing titles with template sentence structures that we’re happy with, so let’s try substituting words between two titles. This will preserve sentence structure.

For example, starting with these two titles:

We then do the following…

  1. Take “Diamonds are Forever” as our template title.
  2. Pick a random word from this title to substitute, for example, “Diamonds”.
  3. Then pick a random word from “For Your Eyes Only”, for example, “For”.
  4. Finally, substitute the word “Diamonds” with “For” to give the new title: For Are Forever.

Unfortunately this title doesn’t seem quite right! Let’s try another example…

  1. Take “For Your Eyes Only” as our template title.
  2. Pick a random word from this title to substitute, for example, “Eyes”.
  3. Then pick a random word from “Diamonds Are Forever”, for example, “Diamonds”.
  4. Finally, substitute the word “Eyes” with “Diamonds” to give the new title: For Your Diamonds Only.

Much better! But why did this work better than the first example? The answer is “Part of Speech”.

Part of Speech

Each part of speech describes a category of words which have the same grammatical properties. Most of us will have learnt about the core ones in school, for example:

Words from these parts of speech are combined to form full sentences, such as: The (article) blue (adjective) frog (noun) ate (verb) the (article) fly (noun).

In school we’re usually taught that there are about eight parts of speech, however for more complex analysis, some classifications have 70 or 80 parts of speech. For our purposes, let’s use the 36 parts of speech used in the Penn Treebank, a large body of text annotated with parts of speech, and used for linguistic research. In the Penn Treebank, each part of speech is given a code, for example, NNP represents a plural noun, and RB represents an adverb. The annotation of text is usually called “tagging”, and tagged text often looks like this:

Diamonds/NNP/ Are/VBP/ Forever/RB/
For/IN/ Your/PRP$/ Eyes/NNP/ Only/RB/

Back to our title generation, when we substitute words between titles, all we need to do is ensure that we substitute words with the equivalent part of speech. In our example, that would give:

Not perfect, but much better! So now we have everything we need to generalise this to a fully fledged title generator.

The Full Generator

Step 1

Build a tokenised set of words based on the existing titles grouped by part of speech, with some poetic licence:

Step 2

Select one of the “template” film titles at random. For example: Never/RB/ Say/VPB/ Never/NN/ Again/RB/.

Step 3

Select one of the words in the template title at random, and note its part of speech. In our example, let’s choose Never which is tagged NN, a singular noun.

Step 4

Finally, substitute the word Never for another word tagged NN selected at random from the set we created in Step 1. For example, Love. This gives us a generated title of: Never Say Love Again. Not bad!

Some other examples:

Where next?

This method of generation is a good first start, but the following improvements could be considered:

Source Code

The full source can be found here. As a bonus, the same generation technique has been applied to Star Wars film titles, Harry Potter film/book titles, Power Rangers Dino Charge series episode titles, and Famous English proverbs and sayings.

[1] Photo by Irv P on Unsplash