A quick SEO win for most websites is to include the top ranked keyword in the missing title tags.

Think about it for a minute.

If a page already has a ranking for a keyword and that keyword is not in the title, that page could rank higher if we add that term naturally

If we also add keywords to meta descriptions, they can also be highlighted in bold in the search results.

Automated title tag optimization using deep learning

Now if you are working on a site with hundreds, thousands, or millions of pages, doing it manually can become quick, time-consuming, and prohibitively expensive!


Read on below

Maybe we could teach a machine to do this for us.

It could be even better and faster than a data entry team.

Let's find out.

Reintroduction of Ubers Ludwig & Google's T5

We are going to combine some technologies that I covered in the previous columns:

  • About Ludwig
  • Google's T5 (Text to Text Transfer Transformer)

I first introduced Ludwig in my article Automated Intent Classification Using Deep Learning.

In summary, it is an open source Auto ML tool that allows you to train state-of-the-art models without writing any code.

I first saw T5 in the How to Generate Titles and Meta Descriptions Automatically article.

Automated title tag optimization using deep learning

Google describes T5 as a superior version of BERT models.


Read on below

If you remember my article on classifying intentions, BERT was perfect for this task since our target outputs / predictions are classes / labels (the intentions).

In contrast, T5 can summarize (as I showed in my article on meta tag generation), translate, answer questions, classify (like BERT), etc.

It's a very powerful model.

Now, as far as I know, T5 has not been trained on title tag optimization.

Maybe we can do it!

We would need:

  • A training dataset with an example that includes:
    • Original title without our target keywords
    • Our target keywords
    • Optimized title tags with our target keywords
  • T5 fine-tuning code and tutorial follow
  • A number of unoptimized titles that we can test our model with

We'll start with a dataset that I already compiled from SEMrush data that I pulled from HootSuite. I will give instructions on how to compile such a dataset together.

The authors of T5 have generously put together a detailed Google Colab notebook that you can use to tweak T5.

As you go through it, you can use it to answer any trivia question. I actually did this during my SEJ eSummit presentation in July.

Automated title tag optimization using deep learning

They also contain a section that explains how you can optimize it for new tasks. However, when you look at the code changes and data prep required, it seems like a lot of work figuring out if our idea would actually work.


Read on below

Maybe there is an easier way!

Fortunately, Uber released Ludwig version 0.3 a few months ago.

Version 0.3 from Ludwig is delivered with:

  • A mechanism for optimizing hyperparameters that affects the additional performance of models.
  • Code-free integration with Hugging Face's Transformers repository so users can access state-of-the-art pre-built models such as GPT-2, T5, Electra, and DistilBERT for natural language processing tasks, including text classification, sentiment analysis, and named entity recognition, question answering, and more .
  • A new, faster, modular and expandable backend based on TensorFlow 2.
  • Support for many new data formats including TSV, Apache Parquet, JSON, and JSONL.
  • Ready-to-use k-fold cross-validation function.
  • An integration with Weights and Biases to monitor and manage multiple model training processes.
  • A new vector data type that supports noisy labels for poor surveillance.

The release is packed with new features, but my favorite feature is integration with Hugging Face's Transformers library.

I featured Hugging Face pipelines in my article on Title and Meta Description Generation.


Read on below

Pipelines are great for making predictions about models that have already been trained and are available in the Model Hub. But at the moment there are no models that do what we need, so Ludwig is very practical here.

Fine-tune T5 with Ludwig

Training T5 with Ludwig is so easy it should be illegal!

Hiring an AI engineer to do the equivalent would cost us serious dollars.

Here are the technical steps.

Open a new Google Colab notebook and change the runtime to use the GPU.

Download the HootSuite record I compiled by entering the following.

! wget url https://gist.githubusercontent.com/hamletbatista/5f6718a653acf8092144c37007f0d063/raw/84d17c0460b8914f4b76a8699ba0743b3af279d5/hootsuite_titles.csv

Next we install Ludwig.

! pip install ludwig! pip install ludwig (text)

Let's load the training dataset I downloaded into a pandas data frame to review and see what it looks like.

Import pandas as pddf = pd.read_csv ("data.csv")

df.head ()

Automated title tag optimization using deep learning

Most of the work is to create an appropriate configuration file.


Read on below

I figured one out that works by starting with the documentation for T5 and a bit of trial and error.

You can find the Python code for creating it here.

Let's look at the major changes.


– –

Name: Original_Title

insert text

Level: word

Encoder: t5

redu_output: null

– –

Name: Keyword

insert text

Level: word

bound_weights: original_title

Encoder: t5

redu_output: null


– –

Name: Optimized_Title

Type: Sequence

Level: word

Decoder: generator

I define the input to the model as the original title (without the target keyword) and the target keyword.

For the output / forecast I define the optimized title and the decoder as a generator. A generator instructs the model to create a sequence. We need this to generate our beautiful titles.

Now we come to the typically difficult part that was made very easy with Ludwig: training T5 on our data set.

! ludwig train –dataset hootsuite_titles.csv –config config.yaml

You should get a printout like the following.

Automated title tag optimization using deep learning

Be sure to check the input and output function dictionaries to ensure that your settings have been applied correctly.


Read on below

For example, Ludwig should use "t5-small" as a model. It's easy to change it for larger T5 models in the Model Hub and possibly improve the generation.

Automated title tag optimization using deep learning

I trained the model for about 1 hour and got a very impressive validation accuracy from 0.88.

Please also note that Ludwig has automatically selected other important measurements for text generation: perplexity and processing distance.

They are both low numbers which in our case are good.


Read on below

Optimize titles with our trained model

Now for the exciting part. Let's put our model to the test!

First, download a test dataset of unoptimized HootSuite titles that the model won't see during training.

! wget url https://gist.githubusercontent.com/hamletbatista/1c4cfc0f24f6ac9774dd18a1f6e5b020/raw/7756f21ba5fbf02c2fe9043ffda06e525a06ea34/hootsuite_titize_to_

You can check the record with this command.

! head hootsuite_titles_to_optimize.csv

Automated title tag optimization using deep learning

With the next command we can generate predictions.

! Ludwig forecast –dataset hootsuite_titles_to_optimize.csv –model_path results / experiment_run / model /

Automated title tag optimization using deep learning

It runs for less than a minute and saves the predictions in a CSV in the results directory.


Read on below

You can check the optimized titles with this command:

! cat /content/results/Title_predictions.csv | sed & # 39; s /, / / ​​g & # 39;

Automated title tag optimization using deep learning

Check out how beautiful and dramatically cohesive the titles are!

Very impressive what Ludwig and T5 can get by with a small training set and no advanced hyperparameter tuning.

However, our correct test is about whether our target keywords are mixed correctly.

Let's look at some examples from the test dataset:

Line: 798
Original title: 20 Creative Instagram news ideas to engage your followers,
Target Keyword: What to Post? instagram story
T5 Optimized Title: 20 Creative Instagram story Ideas to motivate your followers


Read on below

Now tell me there is no serious sorcery going on here! 🤓

Here is another one.

Line: 779
Original title: how to create a Social media idea in 8 easy steps (free template)
Target Keyword: social strategy
T5 Optimized Title: How to Create One Social media strategy in 8 easy steps (free template)


And here's another one:

Line: 773
Original title: 20+ creative Social media show Ideas and examples,
Target Keyword: Competition ideas
T5 Optimized Title: 20+ Creative Social media contest ideas and examples

The full list I predicted can be found here.

Creating an app to optimize title tags with Streamlit

Automated title tag optimization using deep learning

The primary users of such a service are likely to be content writers.


Read on below

Wouldn't it be cool to pack this into an easy-to-use app that takes very little effort to put together?

That is possible with Streamlit!

I used it briefly in my article, Briefly Generating Structured Data Using Computer Vision.

Install it with:

! pip install streamlit

I created an app that uses this model. You can find the code here. Download it and save it as title_optimizer.py.

You need to run it from the same location that you trained the model or download the trained model to the location where you want to run the script.

You should also have a CSV file with the titles and keywords to optimize.

You can start the app with:

streamlit run title_optimizer.py

Open your browser at the given URL. Usually http: // localhost: 8502

Automated title tag optimization using deep learning

You should see a webpage like the one shown above.


Read on below

To run the model, all you have to do is provide the path to the CSV file with the titles and keywords to be optimized.

The CSV column names should match the names you used when training Ludwig. In my case I used: Simplified_Title and Keyword. I called the optimized title Title.

The model doesn't optimize all of the titles properly, but it does get a decent number.

If you are still on your way to learning Python, I hope this makes you excited enough to get started! 🐍🔥

How to Create Custom Data Sets for Exercising

I've trained this model on HootSuite titles and it probably doesn't work well for websites in other industries. It could hardly work for competitors.

It's a good idea to create your own dataset. Here are some tips for doing this.

  • Use your own data via the Google Search Console or the Bing Webmaster Tools.
  • Alternatively, you can get competitor data from SEMrush, Moz, Ahrefs, etc.
  • Write a script to get title tags and share titles with and without your target keywords.
  • Take the titles with keywords and replace the keywords with synonyms or use similar techniques to "de-optimize" the titles.


Read on below

These steps will provide you with a training set of basic truth data from which the model can learn.

For your test data set, you can use titles for which no keywords are available (from step 3). Then manually check the quality of the predictions.

Writing the code for these steps should be fun and do interesting homework.

Resources to learn more

The acceptance of Python in the community remains strong.

The best way to learn is to do interesting and relevant work.

My team at RankSense started writing and sharing practical scripts in the form of Twitter tutorials back in July.

We call them RSTwittorials.

A few months ago I asked the community to join us and share their own scripts and then do walkthrough video with me every week.

💥 I'm really excited to see so many # Python # SEEOs sharing their brilliant scripts and journeys in the coming weeks.

We are booked with weekly #RStwittorial sessions until March (3 places still available)! 🐍🔥 # DONTWAIT Fill out this form and provide a date 🤓https: //t.co/Wf2Pt6f8KV pic.twitter.com/IOsEfUMWKR

– Hamlet Batista (@hamletbatista) November 18, 2020


Read on below

At first I thought I would do one of these once a month and planned to have my team do the rest every week.

We're booked up with amazing Twittorials and Walkthroughs every week through May (as of this writing)!

💥 If you are trying to learn or master #Python, share your experience with us and accelerate your learning!

We have 2 slots open for #RSTwittorials and webinars for March and April 2021. Opening dates for May soon! #DONTWAIT 🐍🔥 https://t.co/rfnoZ25KPq pic.twitter.com/9gIiI4u8WX

– Hamlet Batista (@hamletbatista) December 1, 2020

So many cool tricks and learning trips already. #DONTWAIT

More resources:

Photo credit

All screenshots by the author, December 2020


Please enter your comment!
Please enter your name here