41

Pizza maker: A Tutorial on Building Twitterbots

Embed Size (px)

Citation preview

Page 1: Pizza maker: A Tutorial on Building Twitterbots
Page 2: Pizza maker: A Tutorial on Building Twitterbots

CreateanaccountonTwitter,logintoTwitterwiththisaccount,thenvisitCheapBotsDoneQuick.comandSignin.

Page 3: Pizza maker: A Tutorial on Building Twitterbots

Openyourgrammarwitha{intheJSONwindow…

ThemainruleofyourTracerygrammariscalled“origin.”Thenameofeachruleisanon-terminalsymbolthatcanbeexpandedusingtheright-hand-side.Werefertonon-terminalsbyencasingthemin#…#ontheright-handsideofarule.

Page 4: Pizza maker: A Tutorial on Building Twitterbots

Next,writerulestoexpandthenon-terminals#meat#and#veggie#inourearlierruleformakingapizza

Addasmanyoptionsasyouwanttotheright-hand-sideofeachrule;allareequallylikely

Page 5: Pizza maker: A Tutorial on Building Twitterbots

Dittoforthenon-terminals#cheese#and#sauce#Addasmuchvarietyasyourimaginationwillallow…

WhenTraceryexpandsarule(togenerateapizza,say),itrandomlypicksfromtheright-hand-sideoptionsforeachnon-terminal.

Page 6: Pizza maker: A Tutorial on Building Twitterbots

Wenowwritearuleforthelastnon-terminal,#base#,andclosethenourgrammarwithafinal}

Everynon-terminalineveryrulenowhasitsownexplicitruledefinition,soourgrammarisreadytostartgenerating.

Page 7: Pizza maker: A Tutorial on Building Twitterbots

Thishandybuttononthebottomrightallowsyoutotestthegrammar,andtweettheresultsyoulike…

Usethisdrop-downmenutoselectthefrequencywithwhichyourbotwilltweet

theoutputsofitsTracerygrammar.

Page 8: Pizza maker: A Tutorial on Building Twitterbots

Finally,saveyourbotonCheapBotsDoneQuick.com

BotPizzaKitchen

Choosetomakeyourgrammarvisibletousersofthesite.

Page 9: Pizza maker: A Tutorial on Building Twitterbots

Now,whatifwewantourgrammartogiveanametoeachpizza?

Icanthinkofafew…

Page 10: Pizza maker: A Tutorial on Building Twitterbots

Wecanmakeanamebyjoiningtwonamelets

Butournamesbearnospecificrelationtotheirpizzas

Page 11: Pizza maker: A Tutorial on Building Twitterbots

Ifonlytheexpansionsof#Meat#,#Cheese#andtheotheringredientswereinfluencedbytheexpansionsfor#Prefix#and#Suffix#

ButTracerygrammarsareContext-Free:everynon-terminallike#Meat#isexpandedinanullcontext,

independentlyofallothers.NoContext,NoInfluence!

Page 12: Pizza maker: A Tutorial on Building Twitterbots

Here’swhatweaimfor:theCavewallprefixsuitsQuorn,whileCowboyisaptforRanchsauce.Thenameinfluencestheingredients.

Here’sanaïvesolution:writespecificpizzarulesthathardcoderelationsacrossnon-terminals.So#Prefix_A#generatesnamesthatgowith#Meat_A#,andsoon.

Page 13: Pizza maker: A Tutorial on Building Twitterbots
Page 14: Pizza maker: A Tutorial on Building Twitterbots

*&$^$%

Flippin’Nora!

Page 15: Pizza maker: A Tutorial on Building Twitterbots

Pre-NameIngredientsPrefix SuffixPost-NameIngredients

Sosplitthegeneratorintotwoself-containedcomponents

Page 16: Pizza maker: A Tutorial on Building Twitterbots

MeatPrefix SuffixVegetableonCheese&SauceonBase

Meat&VegetablePrefix SuffixonCheese&SauceonBase

Meat&VegetableonCheesePrefix SuffixonSauceonBase

Meat&VegetableonCheese&SaucePrefix SuffixonBase

We’llneedfourhigh-levelrulesforfourdifferentkindsofsplit.

Page 17: Pizza maker: A Tutorial on Building Twitterbots

SuffixVegetableonCheese&SauceonBase

SuffixVegetableonCheese&SauceonBase

SuffixVegetableonCheese&SauceonBase

SuffixVegetableonCheese&SauceonBase

Eachself-containedcomponenthasinternalagreementthatcanvaryinthenumberofdependencypairings

MeatPrefix

1Possibility 4AgreementPossibilities

Yeah!

Page 18: Pizza maker: A Tutorial on Building Twitterbots

Ournewtop-levelrulesarebelow,andproducenamedpizzasasabove.Intotal,thenewgrammarhas100rules.

Page 19: Pizza maker: A Tutorial on Building Twitterbots

YoucandownloadthegrammarandthisspreadsheetfromourGithubrepository

Allthedataforourgrammarisstoredinaspreadsheet

Page 20: Pizza maker: A Tutorial on Building Twitterbots

Whatagreatflippin’pantry!

Page 21: Pizza maker: A Tutorial on Building Twitterbots

CheapBotsDoneQuickallowsustomakeourbotsresponsivetotweetsthatexplicitly@mentionthem.Solet’smakeourbot

deliverpizzarecommendationsthatmatchspecifictastes.

Icouldmurderaseafoodpizza!

Page 22: Pizza maker: A Tutorial on Building Twitterbots

First,weneedtoaddanewcolumntoourDB…

Page 23: Pizza maker: A Tutorial on Building Twitterbots

Thetypeofapizzaisafunctionofthetypeofitsingredients.Soforeachqualificationoningredients,generatenewrulesforpizzasandtheirelements.

Page 24: Pizza maker: A Tutorial on Building Twitterbots
Page 25: Pizza maker: A Tutorial on Building Twitterbots

MakerSpecialized

NamerPizza-specific

CombinedGrammar

Page 26: Pizza maker: A Tutorial on Building Twitterbots

Thenamed-pizzamakerhas100rules.Thisjumpsto800ruleswhenweaddqualifications,andto1500ruleswhenweaddnegativequalificationsaswell.

Page 27: Pizza maker: A Tutorial on Building Twitterbots

Yourpizza,M’lord.

ButourTracerygrammarstillfitsintoCheapBotsDoneQuick.comsolet’spressonwiththedeliveryofspecialitypizzas.

ChoosetheReplyoptionforyourbot(stillinBeta)soyoucanconfigurehowitwillreplyto@mentionsfromothers.

Page 28: Pizza maker: A Tutorial on Building Twitterbots

{ “.”: “#pizza#” }

ResponsegrammarsuseasimplerJSONformat,withjustoneelementontheright-hand-side.

ButyouCANrefertonon-terminalsinthemaingrammarhere.

Theleft-hand-sideofaresponseruleisnotanon-terminal,butastringthatmustliterallymatchpartofan@mention

Page 29: Pizza maker: A Tutorial on Building Twitterbots

Eachqualificationofaningredientislistedontheleft.Thecorrespondingpizzanon-terminalison

theright.

Theseresponserulesareappliedinthegivenorder,soitisimportantthatthenegativequalifications(e.g.“nomeat”)arelistedbeforethepositives(e.g.“meat”).

Page 30: Pizza maker: A Tutorial on Building Twitterbots

Eachleft-hand-sidecanalsobearegularexpression.Use“.”tomatchanystring.Use[x|X]forachoicebetween“x”and“X”,asinthecase-insensitivetextsabove.

Page 31: Pizza maker: A Tutorial on Building Twitterbots

YourF**kingWine,Sir.

Let’sconsiderhowourpizzabotmightusefullyinteractwithothers.Howaboutanotherbotthatsuggestswinepairingsforournewlyinventedpizzas?

Page 32: Pizza maker: A Tutorial on Building Twitterbots

Weneedtowhipupacocktailofcomplementary

grammars.

Onewillmapfromfoodstowines,andanotherwilllistenforthetriggerstoexploitthismapping.

Page 33: Pizza maker: A Tutorial on Building Twitterbots

Tostart,weshouldcodifyourwine-pairingknowledgeinanexplicitform,asinthisveryspreadsheet…

Page 34: Pizza maker: A Tutorial on Building Twitterbots

Eachfood-feature-rule(non-terminalsoftheform“featurebev”)mapsontoitsownspecialist

listofrecommendations

Addaseparateruleforeachfeatureofthefoodonwhichawinepairingcanbepredicated…

Page 35: Pizza maker: A Tutorial on Building Twitterbots

Now,weneedameansofinvokingeachfood-feature-rule,soforeachfoodfeature,addastimulus:responsepairtotheresponsegrammar.

Page 36: Pizza maker: A Tutorial on Building Twitterbots

Nowweneedtogetthebicameralpartsofthegrammartotalktoeachother.

Wemustmakesurethateverypizzacreatedbyourbotmentionsthenameofarecommendationbot,suchasitself

Page 37: Pizza maker: A Tutorial on Building Twitterbots

Nowourrecommendercanbetriggeredbyanymentionofspecificingredients

(orawholeclassofingredients)inourpizzadescriptions…

…andrespondaccordingly,asbelow.

Page 38: Pizza maker: A Tutorial on Building Twitterbots

Butour

winegrammarofferspairingsonthebasisofjustasingleingredient!

Fancyadrinkwithyourpizza?

Flippin’heck,you’reright!

Page 39: Pizza maker: A Tutorial on Building Twitterbots

Solution:considerall

pairwisecombosofingredientsthatsuggestthesamewine!

Foreach

combo,addanexplicitrecomm-endationruletotheresponsegrammar.

Page 40: Pizza maker: A Tutorial on Building Twitterbots

Noticetheuseofthewildcardcharacters.+here.Thedot.matchesanycharacterwhilethe+meansoneormoreuses

Page 41: Pizza maker: A Tutorial on Building Twitterbots

Nowourresponse

grammarcanrecommendwineforapairingofingredients.