8
$\begingroup$

I am currently working on the automation of recurring reports (weekly 30-50 pages reports for around 100 districts). Those reports have a mostly fixed form : maps, graphs, data tables and small zone of text.

Apart for some discussion around colors and legends, it isn't difficult to automate the production of maps / graphs / tables. (I work with Rmarkdown if you want to know)

However, for the text, a simple approach like writing 'r value' in markdown to produce a variable value inside of the text feel 'too automated'. The reports end up having ten sentences like 'During the last quarter (QX 201X) total result was XXX (a +X% growth compared to the same quarter the previous year).'

I'd like to get automatic variations of that phrase without modyfiying it's meaning. I've ended up writing half a dozen variations myself. But (1) it still feels repetitive and unnatural, and (2) doing it for every phrase of the report may take a lot of time.

We have seen a lot of extraordinary things in transfering things for visual representation (see : https://en.wikipedia.org/wiki/Neural_Style_Transfer). So I was wondering if we have similar things for NLP, that would allow a text to be rewritten using a different 'style' (a neutral style -or an absence of style- in my case), keeping it's main content. The main paper I found on the subject is titled 'What is wrong with style transfer for texts?' and shows why style transfer doesn't really work for texts. Given (1) the constraint (keeping the same meaning) and (2) it's formalism (I know which number should be shown), I feel like the problem may be simpler than the whole style transfert.

Any idea where to start to automatically write variations of a text while keeping it's meaning constant ?

$\endgroup$
3
  • 2
    $\begingroup$ actually what you are asking for is something that will KILL all ad firms that rely on generating text copy. We tried something with GPT/GPT2 by giving it different starting points but it generates gibberish. You could try a machine translation approach where you could use one sentence as SRC and the other synonymous sentence as TGT (but this will need tons of data) OR you could write a simple parser that calculates that prob of a word following the prior X words. You then use it to recursively generate another sentence. Though how grammatically accurate its going to be needs to be validated. $\endgroup$ Jan 18, 2020 at 12:03
  • $\begingroup$ @VikramMurthy: Is there no way to leverage GPT2 to get synonyms ? $\endgroup$ Jan 24, 2020 at 20:12
  • $\begingroup$ sadly GPT2 and it predecessor is used more for sentence completion. Actually, do this ..go to talktotransformer.com (gpt implementation by huggingface) and type in these 2 "during the last quarter the total revenue" and copy the output and "the revenue for the last quarter" and compare it. It generates a very meaningless output for the first and a somewhat decent one for the 2nd. Maybe, just maybe, if you can try enough samples by playing with the order of words and creating your own "dictionary" of alternate sentences, you could use them randomly. $\endgroup$ Jan 25, 2020 at 10:01

2 Answers 2

3
+100
$\begingroup$

Text summarization can be divided into two categories 1. Extractive Summarization and 2. Abstractive Summarization

  1. Extractive Summarization: These methods rely on extracting several parts, such as phrases and sentences, from a piece of text and stack them together to create a summary. Therefore, identifying the right sentences for summarization is of utmost importance in an extractive method.
  2. Abstractive Summarization: Abstractive methods select words based on semantic understanding, even those words did not appear in the source documents. It aims at producing important material in a new way. They interpret and examine the text using advanced natural language techniques to generate a new shorter text that conveys the most critical information from the original text.

What you are looking for is abstractive summarisation. Since you are working in R there is a nice library called lexRank taking an example from here would look something like

#load needed packages
library(xml2)
library(rvest)
library(lexRankr)

#url to scrape
monsanto_url = "https://www.theguardian.com/environment/2017/sep/28/monsanto-banned-from-european-parliament"
   
#read page html
page = xml2::read_html(monsanto_url)
#extract text from page html using selector
page_text = rvest::html_text(rvest::html_nodes(page, ".js-article__body p"))

#perform lexrank for top 3 sentences
top_3 = lexRankr::lexRank(page_text,
                          #only 1 article; repeat same docid for all of input vector
                          docId = rep(1, length(page_text)),
                          #return 3 sentences to mimick /u/autotldr's output
                          n = 3,
                          continuous = TRUE)

#reorder the top 3 sentences to be in order of appearance in article
order_of_appearance = order(as.integer(gsub("_","",top_3$sentenceId)))
#extract sentences in order of appearance
ordered_top_3 = top_3[order_of_appearance, "sentence"]

> ordered_top_3
[1] "Monsanto lobbyists have been banned from entering the European parliament after the multinational refused to attend a parliamentary hearing into allegations of regulatory interference."
[2] "Monsanto officials will now be unable to meet MEPs, attend committee meetings or use digital resources on parliament premises in Brussels or Strasbourg."                                
[3] "A Monsanto letter to MEPs seen by the Guardian said that the European parliament was not “an appropriate forum” for discussion on the issues involved."  

EDIT: How I like to think about abstractive summarisation: Y

Using encoder-decoder architecture (extendended with transformers) for seq2seq problems you can essentially get an embeding of your text, where same sentences can be embedded differently in different context, giving same/similiar output.

$\endgroup$
1
  • 1
    $\begingroup$ Thanks for the clarification and the R package. However, the code you provide seems to perform extractive summary. I'll thinker with it a bit to see if its possible to perform abstractive summary. $\endgroup$ Jan 19, 2020 at 11:02
1
$\begingroup$

Paper list for style transfer in text:

$\endgroup$
1
  • $\begingroup$ Thanks for the link. As is, your answer is a bit too stale to be acceptable. Maybe you can explain where to start in the list of 50+ papers you linked ? $\endgroup$ Jan 19, 2020 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.