How do you check n-gram synonym overlap for a target query?

Anyone here actually using n-gram matching to check if Google is treating a synonym phrase as equivalent to your primary query? I'm looking for a reliable way to audit coverage, maybe in Python, for cases like 'cheap flights' vs 'inexpensive flights.' For client sites, I've seen weird rank swings when synonyms are swapped in headers, so trying to get more data-driven about it. What workflows are you using or is there a tool that shows n-gram agreement between SERP results and your target phrase?

Asked by mohsinnouman

2 Answers

Yeah, you can check n-gram synonym overlap by scraping the top 10 or 20 Google SERPs for both variants like 'cheap flights' and 'inexpensive flights', then tokenize the content (titles, meta, maybe body snippets) into n-grams and compare sets. In Python, I usually use requests and BeautifulSoup to grab SERP HTML, then NLTK or spaCy for the n-gram/token work. If you compare bigrams/trigrams between results, you get a feel for overlap or divergence. Jaccard similarity or simple percent overlap gives you a quant number. If you see low overlap, Google probably treats them differently. I also check if the same domains pop up for both queries with similar rankings, which can hint at synonym treatment. For a tool workflow, nothing out of the box, most SEOs I know hack this in Colab or a Jupyter notebook. If you want to get fancy, you can toss in OpenAI embeddings via API and measure cosine similarity of SERP snippet clusters, but stick with n-gram Jaccard for a quick answer. This helped me show a client last year why swapping 'affordable' for 'cheap' actually dropped them from page one, they weren't as synonymic as expected in Google's eyes.

Answered by hasnain

I use Python and a little bit of pandas to check n-gram synonym overlap for queries like that, mostly by scraping the top 10 SERPs for each query (like 'cheap flights' and 'inexpensive flights'), grabbing the snippets and titles, then breaking them down into unigrams, bigrams, etc. For roofing stuff, I do this for city+service combos, less for synonyms, but the idea's the same. You can run nltk's ngram extraction on both sets of results, then compare the sets with Jaccard similarity or simple overlap counts. If you've got a list of synonyms (WordNet can help), just look at how often those terms and combos appear across the two SERPs. I haven't found an off-the-shelf tool that does this all in one, but it doesn't take long to script. Run it monthly, track changes when you swap synonyms in your headers or H1s, and you'll see quickly if Google treats them as totally interchangeable or not. I keep a spreadsheet of this for my main keywords.