Far scrivere un romanzo a GPT-3

La copertina (generata dall'AI) di "La Porta del Tempo: battaglia contro il Signore dei Sogni"

Si fa un gran parlare (e sparlare…) di ChatGPT e delle potenzialità della sua Intelligenza Artificiale.

Ho visto tanti esempi, buoni e cattivi, allarmati o eccitati, di usare questa potentissima tecnologia. Ma quasi tutti erano solo chiacchierate con ChatGPT, oppure poco più.

Ho voluto provare qualcosa in più: usare le API (Application Programming Interface) di ChatGPT spingendo un po’ più in là il confine dell’esplorazione. Visto che sicuramente la capacità di questo LLM (Large Language Model) è tutta sulla linguistica, mi è parso naturale esplorare la possibilità di fargli scrivere un romanzo in autonomia. E, vista la mia passionaccia per la narrativa, ho scelto di provare a fargli usare come “stile di scrittura” il mio.

Beh, to make a long story short: successo pieno! Se volete vedere il risultato, ecco qui il link al PDF: https://bit.ly/PortaDelTempo

Impressionante no? Vi voglio dettagliare i passaggi.

  1. Ho creato uno script di una sessantina di linee di codice e gli ho passato in input un unico spunto iniziale: “Il protagonista Jon Doe è un pluriassassino ed è stato condannato ad essere proiettato tre secoli nel futuro. Si risveglia nel futuro ma non ha cognizione del suo stato e dovrà ricostruire la sua identità“.
  2. Con lo script ho fatto generare una quarantina di passaggi della trama del romanzo con un tecnica di “proponi – riassumi – proponi…” in cui non ho dato nessun contributo umano alla generazione del testo.
  3. Ho usato l’ultimo riassunto ottenuto per far generare (sempre via API) sia il titolo (“La Porta del Tempo: battaglia contro il Signore dei Sogni“) che l’immagine di copertina (quella che trovate in testa all’articolo) e alcune illustrazioni (qui ho usato la API images/generations cioè quella di DALL-E).

Qui il passaggio più complesso: addestrare un modello al mio stile di scrittura. Ho proceduto così:

  1. Ho raccolto una buona fetta di mia “produzione letteraria” (circa 150.000 parole, cioè 600.000 caratteri) e ho spezzettato il testo in 300 “chunk” da una pagina circa (by the way: codice Python scritto mediante ChatGPT, tanto per gradire).
  2. Con un altro script ho dato in pasto i trecento prompt a GPT-3 chiedendo di estrarne una sintesi minimale. Ho impacchettato il tutto usando le sintesi come “prompt” e i testi originali come “completion” e ho addestrato in fine-tuning un nuovo modello di GPT-3 (per i curiosi si chiama “davinci:ft-andrea-bonvicini:stileab-2023-01-15-14-50-14“)
  3. Ho preso il primo spunto del romanzo suggerito da GPT-3 al passo 2 e gli ho fatto generare la prima pagina del romanzo, intitolata “La stanza era vuota“. Beh, vi posso giurare che lo stile collima con il mio in maniera davvero impressionante…

Al termine dell’elaborazione (nota da ricordare: l’unico input umano sono poche righe di testo per lo spunto iniziale) ho tutto direttamente in un documento Word generato in automatico e quel che mi basta è formattarlo con qualche click, impaginare le immagini… et voilà! (ecco qui di nuovo il link al PDF: https://bit.ly/PortaDelTempo)

A questo punto avrei potuto continuare il loop e fargli generare le altre pagine ma mi è bastato, anche perché usare le API di GPT-3 ha un costo. Già, il costo: meno di 35 dollari… di cui la gran fetta (32-33$ dollari circa) per addestrare il modello linguistico.

In buona sostanza, una volta addestrato il modello con il mio personale stile di scrittura, potrei generare romanzi “a manetta” al costo di un paio di dollari l’uno…

Lesson learned, ora:

  • la potenza degli strumenti è davvero impressionante;
  • per sfruttarla ChatGPT è una bella interfaccia semplice e intuitiva, ma le API possono dare ottime soddisfazioni in termini di automazione e di settaggio fine del risultato;
  • se vuoi ottenere testi consistenti è necessario il fine-tuning di un modello;
  • fare il fine-tuning è piuttosto semplice (GPT-3 mette a disposizione una serie di strumenti CLI che velocizzano il tutto e non è male l’idea di coinvolgere sempre GPT-3 nel processo di definizione prompt-completion);
  • bastano (e probabilmente avanzano) 300 coppie prompt-completion per addestrare il modello.

Ringraziamenti

Spunti di programmazione li ho trovati in due esperti, uno italiano e uno statunitense:

A loro i miei più sentiti ringraziamenti!

Far scrivere un romanzo a GPT-3

2.333 commenti su “Far scrivere un romanzo a GPT-3

  1. Автор предлагает практические рекомендации, которые могут быть полезны в реальной жизни для решения проблемы.

  2. naturally like your web site however you need to take a look at the spelling on several of your posts. A number of them are rife with spelling problems and I find it very bothersome to tell the truth on the other hand I will surely come again again.

  3. This is really interesting, You�re a very skilled blogger. I�ve joined your feed and look forward to seeking more of your magnificent post. Also, I�ve shared your site in my social networks!

  4. Amazing! I recently read your blog post and I’m absolutely amazed. Your perspective on this topic is extremely valuable. It really made me think and can’t wait to see your next post. Your work is inspiring!

  5. Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.儿童色情

  6. Wow! I recently read your article and I’m thoroughly impressed. Your insight on the topic is extremely valuable. I’ve gained a new perspective and can’t wait to see what you write next. Your work is inspiring!

  7. Я оцениваю тщательность и качество исследования, представленного в этой статье. Автор предоставил надежные источники и учел различные аспекты темы. Это действительно ценный ресурс для всех интересующихся.

  8. Incredible! I just read your post and I’m blown away. Your analysis on this topic is spot-on. It really made me think and am eager to see what you write next. Your work is inspiring!

  9. Incredible! I just finished reading your blog post and I’m absolutely amazed. Your insight on this subject is spot-on. It really made me think and am eager to see your next post. Your work is inspiring!

  10. Hey there outstanding website! Does running a blog like this require a large amount of work?
    I’ve virtually no understanding of programming but I was hoping to start my own blog in the near future.

    Anyhow, should you have any suggestions or techniques for new blog
    owners please share. I understand this is off topic however I just needed to ask.
    Cheers!

    Have a look at my web blog … vpn coupon code 2024

  11. This is really interesting, You�re a very skilled blogger. I�ve joined your feed and look forward to seeking more of your magnificent post. Also, I�ve shared your site in my social networks!

  12. You’re so awesome! I don’t believe I have read a single thing like that before. So great to find someone with some original thoughts on this topic. Really.. thank you for starting this up. This website is something that is needed on the internet, someone with a little originality!

  13. Amazing! I just read your article and I’m absolutely amazed. Your analysis on this subject is extremely valuable. I’ve learned so much and can’t wait to see what you write next. Keep up the great work!

  14. Amazing! I just finished reading your blog post and I’m thoroughly impressed. Your analysis on this subject is incredibly insightful. It really made me think and am eager to read more. Your work is inspiring!

  15. Очень хорошо организованная статья! Автор умело структурировал информацию, что помогло мне легко следовать за ней. Я ценю его усилия в создании такого четкого и информативного материала.

  16. Amazing! I just finished reading your post and I’m absolutely amazed. Your perspective on this subject is extremely valuable. I’ve learned so much and can’t wait to read more. Your work is inspiring!

  17. Важно отметить, что автор статьи предоставляет информацию с разных сторон и не принимает определенной позиции.

  18. Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across.国产线播放免费人成视频播放

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

Torna su