GITTA (“Grammar Induction using a Template Tree Approach”) is een methode om uit enkele voorbeeldteksten contextvrije grammatica’s af te leiden.
Het werkt het best op teksten die verborgen sjablonen volgen, zoals forumtopics, schrijfprompts en de output van tekstgeneratoren die met sjablonen werken.
De grammatica’s die het vindt, kan je omzetten naar grammaticatalen zoals Tracery en Babbly.
Waarom sjablonen?
Wie tekstgeneratoren maakt, zoals Twitterbots, schrijft de grammatica vaak met de hand: een sjabloon zoals “<Hero> is going to <Action>”, met lijsten van namen, beroepen en acties om de slots in te vullen.
GITTA werkt andersom: geef het een paar teksten die zo’n grammatica schreef, en het zoekt de grammatica erachter.
De meeste algoritmen voor grammatica-inductie zoeken naar structuren zoals woordsoorten, maar generatieve grammatica’s zijn vooral sjablonen, dus zoekt GITTA naar sjablonen.
Hoe het werkt
GITTA ordent de teksten in een sjabloonboom: elke knoop is een sjabloon dat algemener is dan de sjablonen eronder, met onderaan de teksten zelf.
< A >
< B > world
hi < C >
< D > universe
hello world
hi world
hi universe
howdy universe
< A >
< B > world
hello world
hi world
hi < C >
hi world
hi universe
< D > universe
hi universe
howdy universe
Een sjabloonboom voor vier begroetingen. Elk sjabloon dekt de teksten eronder, dus hi world past zowel in <B> world als in hi <C>, en het bovenste dekt ze allemaal. Uit deze vier begroetingen leert GITTA een grammatica die ook hello universe en howdy world schrijft.
GITTA bouwt deze boom van onder naar boven: het combineert de twee teksten die het meest op elkaar lijken tot een sjabloon, met de woorden die ze delen en een slot waar ze verschillen, en blijft daarna de sjablonen combineren die het meest op elkaar lijken, tot er één alles dekt.
Dan voegt het slots met gelijkaardige waarden samen en vereenvoudigt het de boom, tot er niets meer verandert.
Doorloop de stappen voor vijf zinnen:
Stap
Combineer de meest gelijkende teksten, daarna de meest gelijkende sjablonen: de woorden die ze delen blijven, de rest wordt een slot.
< A >
I like my < B > and my < C >
< D > the < E > is < F >
I like my cat and my dog
I like my dog and my chicken
Alice the cat is jumping
Cathy the cat is walking
Bob the dog is walking
< G > the cat is < H >
< I > the < J > is walking
< A >
I like my < B > and my < C >
I like my cat and my dog
I like my dog and my chicken
< D > the < E > is < F >
< G > the cat is < H >
Alice the cat is jumping
Cathy the cat is walking
< I > the < J > is walking
Cathy the cat is walking
Bob the dog is walking
Slots
< A >
→
I like my < B > and my < C > | < D > the < E > is < F >
< B >
→
cat | dog
< C >
→
dog | chicken
< D >
→
< G > | < I >
< E >
→
cat | < J >
< F >
→
< H > | walking
< G >
→
Alice | Cathy
< H >
→
jumping | walking
< I >
→
Cathy | Bob
< J >
→
cat | dog
Voeg slots met gelijkaardige waarden samen: de dieren worden B, de namen G en de werkwoorden F.
< A >
I like my < B > and my < B >
< G > the < B > is < F >
I like my cat and my dog
I like my dog and my chicken
Alice the cat is jumping
Cathy the cat is walking
Bob the dog is walking
< G > the cat is < F >
< G > the < B > is walking
< A >
I like my < B > and my < B >
I like my cat and my dog
I like my dog and my chicken
< G > the < B > is < F >
< G > the cat is < F >
Alice the cat is jumping
Cathy the cat is walking
< G > the < B > is walking
Cathy the cat is walking
Bob the dog is walking
Slots
< A >
→
I like my < B > and my < B > | < G > the < B > is < F >
< B >
→
chicken | cat | dog
< F >
→
walking | jumping
< G >
→
Alice | Bob | Cathy
< C >
→
< B >
< D >
→
< G >
< E >
→
< B >
< H >
→
< F >
< I >
→
< G >
< J >
→
< B >
Vereenvoudig: een sjabloon dat niets toevoegt aan het sjabloon erboven, verdwijnt. Herhaal tot er niets meer verandert.
< A >
I like my < B > and my < B >
< G > the < B > is < F >
I like my cat and my dog
I like my dog and my chicken
Alice the cat is jumping
Cathy the cat is walking
Bob the dog is walking
< A >
I like my < B > and my < B >
I like my cat and my dog
I like my dog and my chicken
< G > the < B > is < F >
Alice the cat is jumping
Cathy the cat is walking
Bob the dog is walking
Slots
< A >
→
I like my < B > and my < B > | < G > the < B > is < F >
< B >
→
chicken | cat | dog
< F >
→
walking | jumping
< G >
→
Alice | Bob | Cathy
Wat overblijft, is een grammatica. Ze schrijft 27 zinnen, waarvan 22 nieuwe.
Grammatica
< S >
→
I like my < B > and my < B > | < G > the < B > is < F >
< B >
→
chicken | cat | dog
< F >
→
walking | jumping
< G >
→
Alice | Bob | Cathy
Alle 27 zinnen die ze schrijft
I like my chicken and my chicken
I like my chicken and my cat
I like my chicken and my dog
I like my cat and my chicken
I like my cat and my cat
I like my cat and my dog
I like my dog and my chicken
I like my dog and my cat
I like my dog and my dog
Alice the chicken is walking
Alice the chicken is jumping
Alice the cat is walking
Alice the cat is jumping
Alice the dog is walking
Alice the dog is jumping
Bob the chicken is walking
Bob the chicken is jumping
Bob the cat is walking
Bob the cat is jumping
Bob the dog is walking
Bob the dog is jumping
Cathy the chicken is walking
Cathy the chicken is jumping
Cathy the cat is walking
Cathy the cat is jumping
Cathy the dog is walking
Cathy the dog is jumping
De stappen van GITTA voor vijf zinnen, zoals in de lezing op ICCC 2020. De zinnen waaruit het leert, staan in het lichtblauw, en de slots die een stap veranderde, in het geel.
Zo ontdekt GITTA de patronen in een paar teksten, en schrijft het er veel gelijkaardige teksten mee.
Resultaten
Om het te testen, lieten we GITTA de grammatica van tien Twitterbots terugvinden die met Tracery gemaakt waren, uit 25, 50 of 100 van hun teksten, en telden we wat de gevonden grammatica’s konden schrijven.
Uit 25 teksten schreven de grammatica’s van zeven bots enkel teksten die de bot zelf had kunnen schrijven, en vaak veel meer dan GITTA gezien had: 648 voor @botdoesnot, en meer dan 3.000 voor @Whinge_Bot, met 6 foute.
Uit 100 teksten van @SkoolDetention vond het een grammatica die alle 224 mogelijke teksten van die bot schrijft, plus 29 die de bot niet kan schrijven.
GITTA had het moeilijk met slots vlak na elkaar, zeker als hun waarden erg verschillen in lengte: voor @hometapingkills schreven zijn grammatica’s vanaf 50 teksten meer foute dan juiste teksten.
Every time I think I’m ready to do a big documented release of my generative text grammar tools, I discover a directly-applicable new paper which changes my whole way of thinking about the API and feature set.arxiv.org/pdf/2009.04530…
Max Kreminski
@maxkreminski
great example of an approach that i find really promising in expressive-computation contexts: learning symbolic generative models that are interpretable & auditable by default https://t.co/tHHGdE7UdD
@article{winters2020gitta,
title={Discovering Textual Structures: Generative Grammar Induction using Template Trees},
author={Winters, Thomas and De Raedt, Luc},
journal={Proceedings of the 11th International Conference on Computational Creativity},
pages = {177-180},
year={2020},
publisher={Association for Computational Creativity}
}
Winters, T., & De Raedt, L. (2020). Discovering Textual Structures: Generative Grammar Induction using Template Trees. Proceedings of the 11th International Conference on Computational Creativity, 177–180.
Winters, T. and De Raedt, L. (2020) “Discovering Textual Structures: Generative Grammar Induction using Template Trees,” Proceedings of the 11th International Conference on Computational Creativity, pp. 177–180.
1.
Winters T, De Raedt L. Discovering Textual Structures: Generative Grammar Induction using Template Trees. Proceedings of the 11th International Conference on Computational Creativity. 2020;177–80.