How to use Spintax to create content and ad copy in Python

Although Spintax was mainly used for the production of low quality articles, and emails from Nigerian princes, it can also use it for legitimate purposes...

How to use Spintax to create content and ad copy in Python
Picture by Burst, Pexels.
13 minutes to read

If you’ve never heard of Spintax, you’ll definitely be aware of its typical usages. This text string replacement “language” is most commonly used for text spinning or article spinning, but has also been used for the creation of spam emails, social network bot messages, plagiarised school homework, and annoying LinkedIn InMails from business development managers.

Spintax (or spin syntax) is fairly simple. It comprises a piece of text containing placeholders containing synonyms which are chosen at random. For example, "{father|brother|cousin} of Nigerian {astronaut|biochemist|major|general|prime minister|ambassador}" could create dozens of unique permutations that search engines used to see as non-duplicates.

Rogetising…

The Spintax technique allowed writers to quickly create a single document and “spin” it into dozens of near duplicate permutations that differed because of the random mix of synonyms used. For several years, the article spinning or “Rogetising” technique worked, and most marketing agencies used the strategy.

In the late noughties, article spinning was the scourge of SEO. It gave rise to thousands of dodgy-looking sites (somewhat magniloquently described as “article marketing” websites) containing poor quality content designed purely for search engines, rather than people.

It then gave rise to thousands of Google algorithm penalties when the Panda algorithm update came out, effectively killing off Spintax. However, it’s still actually pretty useful for some things, including creating ad copy and content for split tests, and automated report commentary.

Load the packages

In this project, we’re going to write a function to parse Spintax text and produce random permutations of the copy. Our Spintax function is going to be written in pure Python, but we’ll use a few core packages to help with certain tasks. Open a Jupyter notebook and import re, random, and itertools.

import re
import random
import itertools

Create a Spintax function

Next, we’ll create a Spintax function. This allows nested Spintax, so we can include multiple sets of synonyms, and can return a single random permutation, or all of the unique random permutations possible from the Spintax text.

This uses a Python regular expression to parse the text and identify each block of Spintax synonyms, which by convention get stored inside curly braces and are separated by the pipe character. These are then split up at the pipe into a list of parts.

Itertools is then used to iterate over these to create all possible random permutations. Setting the single argument to False returns the full list of all permutations rather than a single random permutation.

def spintax(text, single=True):
    """Return a list of unique spins of a Spintax text string.
    
    Args:
        text (string): Spintax text (i.e. I am the {President|King|Ambassador} of Nigeria.)
        single (bool, optional): Optional boolean to return a list or a single spin.
    
    Returns:
        spins (string, list): Single spin or list of spins depending on single.
    """
    
    pattern = re.compile('(\{[^\}]+\}|[^\{\}]*)')
    chunks = pattern.split(text)
    
    def options(s):
        if len(s) > 0 and s[0] == '{':
            return [opt for opt in s[1:-1].split('|')]
        return [s]
    
    parts_list = [options(chunk) for chunk in chunks]
    
    spins = []
    
    for spin in itertools.product(*parts_list):        
        spins.append(''.join(spin))

    if single:
        return spins[random.randint(0, len(spins)-1)]
    else:  
        return spins

Create content from Spintax

To create your Spintax, write out your string and enclose it in triple quotes. For each of the synonyms you want to randomly replace, or Rogetise, enter a pair of curly braces, and some pipe separated synonyms.

email = """I am Dr. {Bakare|George|Mutassim|John} Tunde, the {son|father|brother|cousin}
 of Nigerian {astronaut|biochemist|major|general|prime minister|ambassador} {Abacha} Tunde."""

To generate a single random permutation, simply pass the email string to the spintax() function and display the output.

spin = spintax(email)
spin
'I am Dr. John Tunde, the son of Nigerian biochemist Abacha Tunde.'

To obtain all the random permutations possible from your Spintax, set the single argument to False. This returns a list containing every unique permutation.

spin = spintax(email, single=False)
spin
['I am Dr. Bakare Tunde, the son of Nigerian astronaut Abacha Tunde.',
 'I am Dr. Bakare Tunde, the son of Nigerian biochemist Abacha Tunde.',
 'I am Dr. Bakare Tunde, the son of Nigerian major Abacha Tunde.',
 'I am Dr. Bakare Tunde, the son of Nigerian general Abacha Tunde.',
 'I am Dr. Bakare Tunde, the son of Nigerian prime minister Abacha Tunde.',
 'I am Dr. Bakare Tunde, the son of Nigerian ambassador Abacha Tunde.',
 'I am Dr. Bakare Tunde, the father of Nigerian astronaut Abacha Tunde.',
 'I am Dr. Bakare Tunde, the father of Nigerian biochemist Abacha Tunde.',
 'I am Dr. Bakare Tunde, the father of Nigerian major Abacha Tunde.',
 'I am Dr. Bakare Tunde, the father of Nigerian general Abacha Tunde.',
 'I am Dr. Bakare Tunde, the father of Nigerian prime minister Abacha Tunde.',
 'I am Dr. Bakare Tunde, the father of Nigerian ambassador Abacha Tunde.',
 'I am Dr. Bakare Tunde, the brother of Nigerian astronaut Abacha Tunde.',
 'I am Dr. Bakare Tunde, the brother of Nigerian biochemist Abacha Tunde.',
 'I am Dr. Bakare Tunde, the brother of Nigerian major Abacha Tunde.',
 'I am Dr. Bakare Tunde, the brother of Nigerian general Abacha Tunde.',
 'I am Dr. Bakare Tunde, the brother of Nigerian prime minister Abacha Tunde.',
 'I am Dr. Bakare Tunde, the brother of Nigerian ambassador Abacha Tunde.',
 'I am Dr. Bakare Tunde, the cousin of Nigerian astronaut Abacha Tunde.',
 'I am Dr. Bakare Tunde, the cousin of Nigerian biochemist Abacha Tunde.',
 'I am Dr. Bakare Tunde, the cousin of Nigerian major Abacha Tunde.',
 'I am Dr. Bakare Tunde, the cousin of Nigerian general Abacha Tunde.',
 'I am Dr. Bakare Tunde, the cousin of Nigerian prime minister Abacha Tunde.',
 'I am Dr. Bakare Tunde, the cousin of Nigerian ambassador Abacha Tunde.',
 'I am Dr. George Tunde, the son of Nigerian astronaut Abacha Tunde.',
 'I am Dr. George Tunde, the son of Nigerian biochemist Abacha Tunde.',
 'I am Dr. George Tunde, the son of Nigerian major Abacha Tunde.',
 'I am Dr. George Tunde, the son of Nigerian general Abacha Tunde.',
 'I am Dr. George Tunde, the son of Nigerian prime minister Abacha Tunde.',
 'I am Dr. George Tunde, the son of Nigerian ambassador Abacha Tunde.',
 'I am Dr. George Tunde, the father of Nigerian astronaut Abacha Tunde.',
 'I am Dr. George Tunde, the father of Nigerian biochemist Abacha Tunde.',
 'I am Dr. George Tunde, the father of Nigerian major Abacha Tunde.',
 'I am Dr. George Tunde, the father of Nigerian general Abacha Tunde.',
 'I am Dr. George Tunde, the father of Nigerian prime minister Abacha Tunde.',
 'I am Dr. George Tunde, the father of Nigerian ambassador Abacha Tunde.',
 'I am Dr. George Tunde, the brother of Nigerian astronaut Abacha Tunde.',
 'I am Dr. George Tunde, the brother of Nigerian biochemist Abacha Tunde.',
 'I am Dr. George Tunde, the brother of Nigerian major Abacha Tunde.',
 'I am Dr. George Tunde, the brother of Nigerian general Abacha Tunde.',
 'I am Dr. George Tunde, the brother of Nigerian prime minister Abacha Tunde.',
 'I am Dr. George Tunde, the brother of Nigerian ambassador Abacha Tunde.',
 'I am Dr. George Tunde, the cousin of Nigerian astronaut Abacha Tunde.',
 'I am Dr. George Tunde, the cousin of Nigerian biochemist Abacha Tunde.',
 'I am Dr. George Tunde, the cousin of Nigerian major Abacha Tunde.',
 'I am Dr. George Tunde, the cousin of Nigerian general Abacha Tunde.',
 'I am Dr. George Tunde, the cousin of Nigerian prime minister Abacha Tunde.',
 'I am Dr. George Tunde, the cousin of Nigerian ambassador Abacha Tunde.',
 'I am Dr. Mutassim Tunde, the son of Nigerian astronaut Abacha Tunde.',
 'I am Dr. Mutassim Tunde, the son of Nigerian biochemist Abacha Tunde.',
 'I am Dr. Mutassim Tunde, the son of Nigerian major Abacha Tunde.',
 'I am Dr. Mutassim Tunde, the son of Nigerian general Abacha Tunde.',
 'I am Dr. Mutassim Tunde, the son of Nigerian prime minister Abacha Tunde.',
 'I am Dr. Mutassim Tunde, the son of Nigerian ambassador Abacha Tunde.',
 'I am Dr. Mutassim Tunde, the father of Nigerian astronaut Abacha Tunde.',
 'I am Dr. Mutassim Tunde, the father of Nigerian biochemist Abacha Tunde.',
 'I am Dr. Mutassim Tunde, the father of Nigerian major Abacha Tunde.',
 'I am Dr. Mutassim Tunde, the father of Nigerian general Abacha Tunde.',
 'I am Dr. Mutassim Tunde, the father of Nigerian prime minister Abacha Tunde.',
 'I am Dr. Mutassim Tunde, the father of Nigerian ambassador Abacha Tunde.',
 'I am Dr. Mutassim Tunde, the brother of Nigerian astronaut Abacha Tunde.',
 'I am Dr. Mutassim Tunde, the brother of Nigerian biochemist Abacha Tunde.',
 'I am Dr. Mutassim Tunde, the brother of Nigerian major Abacha Tunde.',
 'I am Dr. Mutassim Tunde, the brother of Nigerian general Abacha Tunde.',
 'I am Dr. Mutassim Tunde, the brother of Nigerian prime minister Abacha Tunde.',
 'I am Dr. Mutassim Tunde, the brother of Nigerian ambassador Abacha Tunde.',
 'I am Dr. Mutassim Tunde, the cousin of Nigerian astronaut Abacha Tunde.',
 'I am Dr. Mutassim Tunde, the cousin of Nigerian biochemist Abacha Tunde.',
 'I am Dr. Mutassim Tunde, the cousin of Nigerian major Abacha Tunde.',
 'I am Dr. Mutassim Tunde, the cousin of Nigerian general Abacha Tunde.',
 'I am Dr. Mutassim Tunde, the cousin of Nigerian prime minister Abacha Tunde.',
 'I am Dr. Mutassim Tunde, the cousin of Nigerian ambassador Abacha Tunde.',
 'I am Dr. John Tunde, the son of Nigerian astronaut Abacha Tunde.',
 'I am Dr. John Tunde, the son of Nigerian biochemist Abacha Tunde.',
 'I am Dr. John Tunde, the son of Nigerian major Abacha Tunde.',
 'I am Dr. John Tunde, the son of Nigerian general Abacha Tunde.',
 'I am Dr. John Tunde, the son of Nigerian prime minister Abacha Tunde.',
 'I am Dr. John Tunde, the son of Nigerian ambassador Abacha Tunde.',
 'I am Dr. John Tunde, the father of Nigerian astronaut Abacha Tunde.',
 'I am Dr. John Tunde, the father of Nigerian biochemist Abacha Tunde.',
 'I am Dr. John Tunde, the father of Nigerian major Abacha Tunde.',
 'I am Dr. John Tunde, the father of Nigerian general Abacha Tunde.',
 'I am Dr. John Tunde, the father of Nigerian prime minister Abacha Tunde.',
 'I am Dr. John Tunde, the father of Nigerian ambassador Abacha Tunde.',
 'I am Dr. John Tunde, the brother of Nigerian astronaut Abacha Tunde.',
 'I am Dr. John Tunde, the brother of Nigerian biochemist Abacha Tunde.',
 'I am Dr. John Tunde, the brother of Nigerian major Abacha Tunde.',
 'I am Dr. John Tunde, the brother of Nigerian general Abacha Tunde.',
 'I am Dr. John Tunde, the brother of Nigerian prime minister Abacha Tunde.',
 'I am Dr. John Tunde, the brother of Nigerian ambassador Abacha Tunde.',
 'I am Dr. John Tunde, the cousin of Nigerian astronaut Abacha Tunde.',
 'I am Dr. John Tunde, the cousin of Nigerian biochemist Abacha Tunde.',
 'I am Dr. John Tunde, the cousin of Nigerian major Abacha Tunde.',
 'I am Dr. John Tunde, the cousin of Nigerian general Abacha Tunde.',
 'I am Dr. John Tunde, the cousin of Nigerian prime minister Abacha Tunde.',
 'I am Dr. John Tunde, the cousin of Nigerian ambassador Abacha Tunde.']

Further reading

  • Hallahan, K., 2013, March. Online Article Marketing – Professional and Ethical Challenges to Public Relations. In 16TH INTERNATIONAL PUBLIC RELATIONS RESEARCH CONFERENCE (p. 293).

  • Prentice, F.M. and Kinden, C.E., 2018. Paraphrasing tools, language translation tools and plagiarism: an exploratory study. International Journal for Educational Integrity, 14(1), pp.1-16.

  • Zhang, Q., Wang, D.Y. and Voelker, G.M., 2014, February. DSpin: Detecting Automatically Spun Content on the Web. In NDSS.

Matt Clarke, Saturday, March 13, 2021

Matt Clarke Matt is a Digital Director who uses data science to help in his work. He has a Master's degree in Internet Retailing (plus two other Master's degrees in different fields) and specialises in the technical side of ecommerce and marketing.

Joining Data with pandas

Learn to combine data from multiple tables by joining data together using pandas.

Start course for FREE

Comments