Game of Thrones season 8 Kit Harington
The popular TV series is based on George RR Martin's books HBO

A neural network has just predicted and written the first five chapters of the next book in George RR Martin's A Song Of Ice And Fire series, on which the popular Game of Thrones TV series is based.

Zack Thoutt, a software engineer and fan of the series, reportedly grew tired of waiting for George RR Martin to complete the book and created a recurrent neural network (RNN) – a type of neural network that can make use of internal memory to process arbitrary sequences of inputs.

Thoutt fed the first five books – that is 5,376 pages of information – into the network, which was then able to generate five chapters of the next book based on the information that the RNN collected.

Of the notable "predictions" that this AI has made, one that really stands out is that Sansa Stark is actually of House Baratheon.

In a statement, Thoutt said he is trying to write a new book and that the model is not perfect. "A perfect model would take everything that has happened in the books into account and not write about characters being alive when they died two books ago," he said.

While the RNN is trying to take all the happenings from previous books into account and not simply rework events that have gone by, he admitted that a perfect text generator does not yet exist.

On the process of creating the chapters, Thoutt says that he only uses a prime word and then instructs the RNN with the number of words to generate for a chapter.

The prime word chosen for each chapter is a name of a character in the story. The RNN would then pick up on the name and come up with a story.

The original books make use of a similar approach where chapters are seen through the eyes of different characters.

Apart from providing the RNN with the prime words, Thoutt claims that there is no other editing that he personally does.

Thoutt adds that the system's grammar is not perfect and that it is merely predicting words. It is not actually doing real long-term story building, but "the network is able to learn the basics of the English language and structure of George RR Martin's style on its own".

The last book published by Martin was in 2011 and fans have been waiting for a follow-up, called The Winds Of Winter, ever since.

Martin has written five books in the series so far – A Game Of Thrones (1996), A Clash Of Kings (1998), A Storm Of Swords (2000), A Feast For Crows (2005) and A Dance With Dragons (2011).

The Winds Of Winter's release date is still anybody's guess. The last time he spoke about was July of this year where he mentioned in his live journal that he is still working on the book.

"I am still months away (how many? good question). I still have good days and bad days, and that's all I care to say," he wrote.