Back to Case Studies

GPT-2 Article Generator for a Tech Media Portal

Russian-Language Text Generation Before ChatGPT

ProductionResearchMedia, Marketing & Language ServicesSep 2020 – Jan 2021NLP, Knowledge Systems & Generative AI
+8%
More articles a day, per the client
10%
Articles needing almost no editing
~32k
Russian tech articles for training
~300
Training experiments in Russian

My Role

Role
Solo engineer, end to end
At HeyML
Team
Solo, with the CEO
Stage reached
Handed over; published at COLINS-2021
Key decisions
  • GPT-2 medium (355M) after testing all four sizes
  • Russian literature first, then tech articles
  • Separate title model chained with the article model

Approach at a Glance

Details
  1. 1Choosing the Model
  2. 2Dataset from Russian Tech Portals
  3. 3Training on Google Cloud TPUs
  4. 4Fixing "Looping"
  5. 5Two Models: Titles and Articles
  6. 6Web App and REST API
  7. 7Telegram Support Chatbot

Executive Summary

A text-generation platform that helped the editors of a Russian-language tech and crypto media portal write articles on topics like technology, blockchain and artificial intelligence. An editor enters a title, or nothing at all, and the system writes a draft article that the editor then shapes into the finished piece.

This was 2020. GPT-2 was the most capable model we could train ourselves, it knew almost only English, and models couldn't follow instructions yet. They could only continue a text. Out of the box, GPT-2 produced gibberish in Russian. So the model first had to learn Russian, then learn to write about technology. We trained our own GPT-2 medium (355M) models on classical Russian literature so they learned the language, then fine-tuned them on 31,686 articles scraped from large Russian-language portals. A second model, tuned on article titles, generates headlines, and the two together produce a full article from scratch.

The editorial team published 8% more articles per day, as reported by the client, and 10% of generated articles needed almost no editing. The same model also powered a Telegram support chatbot. I was the only engineer, working with our CEO, and built everything from data collection and training on Google Cloud TPUs to the web app and REST API. The research behind the project was published at COLINS-2021.


Client Profile

The client was a Russian-language online media portal covering technology and crypto. Its business depends on publishing a steady flow of articles, and every one of them had to be written from scratch by its editors.

In 2020, AI help for that was hard to get:

  • No model for Russian: GPT-2 had been trained almost entirely on English text. In Russian it looped and produced meaningless text.
  • No instructions: models of that generation could only continue a given text. You couldn't ask for "an article about blockchain".
  • General, not technical: the few Russian-language generators available wrote in a general, literary style, drifted off topic and looped on specialised subjects.

Technical Approach

  1. Choosing the Model – I tested all four GPT-2 sizes (124M to 1.5B parameters) for quality, memory and speed, and chose the 355M "medium" model as the best balance. We trained our own models on a corpus of classical Russian literature first, so the model knew the language before it learned the domain.

  2. Dataset from Russian Tech Portals – I surveyed about 18 Russian-language portals across technology, machine learning and cryptocurrencies, and built the dataset from the two largest archives:

    • Scraping: a parallelized scraper downloaded the portals' monthly archives with BeautifulSoup and Selenium, 8x faster than sequential downloads.
    • Cleaning: each page was reduced to its title and body text, without embedded posts, dates, authors or tags. That gave about 74,000 articles.
    • Format: of six layouts tested, one file with special service tokens separating articles and their titles worked best. The tokens also let the model learn where an article starts and ends.
    • Filtering: keeping articles up to 3,000 words left 31,686, which made generated articles longer and more coherent.
  3. Training on Google Cloud TPUs – One training epoch took 65 seconds on CPU, 32 on GPU and 2.3 on a TPU, so training ran on a Google Cloud TPU v2-8.

  4. Fixing "Looping" – In about 300 experiments, roughly 80% of models fell into "looping": repeating the same sentence over and over. The fixes:

    • around 1,000 training epochs, with real progress only after the 800th;
    • gradual unfreezing: training as many layers as possible first, then progressively fewer;
    • tuned generation settings: temperature 0.8 and top-k 40. Lower temperatures looped, and higher ones lost coherence.
  5. Two Models: Titles and Articles – A second model, the article model further tuned on headlines, generates titles. Chained together, the title model proposes a headline and the article model writes the text.

  6. Web App and REST API – A Flask web app lets editors generate an article from a title, or with no input, and adjust temperature and top-k. An open REST API generates titles, articles by title and free articles for other applications. Everything was deployed on Google Cloud.

  7. Telegram Support Chatbot – The same Russian GPT-2 was adapted to conversation and used in a Telegram chatbot that answered users' questions.


Business Outcome

The portal's editors got a writing assistant in Russian years before such tools were common. Instead of starting every article from a blank page, they started from a generated draft on the right topic and edited it into the final piece. The team published 8% more articles per day, as reported by the client. In a test run of 500 generated articles, the texts were on topic and easy to read, and 10% needed almost no editing. The same model was reused for a Telegram support chatbot, and the platform was handed over to the client.

The research was published as Towards Russian Text Generation Problem Using OpenAI's GPT-2 at COLINS-2021 (CEUR Workshop Proceedings, Vol. 2870). It showed what was already possible in 2020: by adapting an English-only model first to the language and then to the domain, it could become a useful Russian-language writing tool for a specialised publication.

Technologies

GPT-2 (355M)Transfer LearningGoogle Cloud TPUWeb ScrapingBeautifulSoupSeleniumTensorFlowPyTorchFlaskREST APITelegram Bot API

Planning something similar?

Tell me about it on a short call. New projects can start within 2 weeks