2perspectivepackagedbgetdata4dbremove5formrequest5msg6perspectiveapikey6printprogress7prspexpmodels7prspmodels7prspscore8prspstream9specifydecimal11unnestscores11Index13perspectivepackagepeRspective ID: 892706
Download Pdf The PPT/PDF document "PackagepeRspectiveJuly142021TitleInterfa..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
1 Package`peRspective'July14,2021TitleInte
Package`peRspective'July14,2021TitleInterfacetothePerspectiveAPIVersion0.1.1DescriptionInterfacetothePerspectiveAPI,whichcanbefoundatthefollowingURL:https://github.com/conversationai/perspectiveapi#perspective-comment-analyzer-api.ThePerspectiveAPIusesmachinelearningmodelstoscoretheperceivedimpactacom-mentmighthaveonaconversation(i.e.TOXICITY,INFLAMMATORY,etc.).peRspectiveprovidesaccesstotheAPIandreturnstidydataframeswithresultsofthespeci-edmachinelearningmodel(s).URLhttps://favstats.github.io/peRspective/,https://github.com/favstats/peRspectiveBugReportshttps://github.com/favstats/peRspectiveDependsR(=3.5.0)LicenseMIT+leLICENSEEncodingUTF-8LazyDatatrueRoxygenNote7.1.1Importscrayon,dplyr,glue,httr,jsonlite,magrittr,purrr,rlang,rlist,stringr,tibbleSuggeststestthat(=2.1.0),covr,badger,DBI,RSQLiteNeedsCompilationnoAuthorFabioVotta[aut,cre]MaintainerFabioVottaྫi;o.vo;tta@;gmai;l.co;m000;RepositoryCRANDate/Publication2021-07-1407:10:02U
2 TCRtopicsdocumented:perspective-package.
TCRtopicsdocumented:perspective-package.....................................2db_append..........................................41 2perspective-packagedb_get_data.........................................4db_remove.........................................5form_request........................................5msg.............................................6perspective_api_key.....................................6print_progress........................................7prsp_exp_models......................................7prsp_models.........................................7prsp_score..........................................8prsp_stream.........................................9specify_decimal.......................................11unnest_scores........................................11Index13 perspective-packagepeRspective:InterfacetothePerspectiveAPI DescriptionProvidesaccesstothePerspectiveAPI(http://www.perspectiveapi.com/).PerspectiveisanAPIthatusesmachinelearningmodelstoscoretheperceivedimpactacommentmighthaveonaconvers
3 ation.peRspectiveprovidesaccesstotheAPIu
ation.peRspectiveprovidesaccesstotheAPIusingtheRprogramminglanguage.ForanexcellentdocumentationofthePerspectiveAPIseehere.GetAPIKeyFollowthesestepsasoutlinedbythePerspectiveAPItogetanAPIkey.SuggestedUsageofAPIKeypeRspectivefunctionswillreadtheAPIkeyfromenvironmentvariableperspective_api_key.Youcanspecifyitlikethisatthestartofyourscript:Sys.setenv(perspective_api_key="**********")TostartRsessionwiththeinitializedenvironmentvariablecreatean.RenvironleinyourRhomewithalinelikethis:perspective_api_key="**********"TocheckwhereyourRhomeis,trynormalizePath("~").QuotaandcharacterlengthLimitsYoucancheckyourquotalimitsbygoingtoyourgooglecloudproject'sPerspectiveAPIpage,andcheckyourprojectsquotausageatthecloudconsolequotausagepage.Themaximumtextsizeperrequestis3000bytes. perspective-package3ModelsinProductionsThefollowingproduction-readymodelsarerecommendedforuse.Theyhavebeentestedacrossmultipledomainsandtrainedonhundredsofthousandsofcommentstaggedbythousandsofhu-manmoderators.TheseareavailableinEnglish(en),Spanish,(es),French(fr
4 ),German(de),Portuguese(pt),Italian(it),
),German(de),Portuguese(pt),Italian(it),Russian(ru).TOXICITY:rude,disrespectful,orunreasonablecommentthatislikelytomakepeopleleaveadiscussion.ThismodelisaConvolutionalNeuralNetwork(CNN)trainedwithword-vectorinputs.SEVERE_TOXICITY:Thismodelusesthesamedeep-CNNalgorithmastheTOXICITYmodel,butistrainedtorecognizeexamplesthatwereconsideredtobe'verytoxic'bycrowd-workers.Thismakesitmuchlesssensitivetocommentsthatincludepositiveusesofcurse-wordsforexample.Alabelleddatasetanddetailsofthemethodologycanbefoundinthesametoxicitydatasetthatisavailableforthetoxicitymodel.ExperimentalmodelsThefollowingexperimentalmodelsgivemorene-grainedclassicationsthanoveralltoxicity.Theyweretrainedonarelativelysmalleramountofdatacomparedtotheprimarytoxicitymodelsaboveandhavenotbeentestedasthoroughly.IDENTITY_ATTACK:negativeorhatefulcommentstargetingsomeonebecauseoftheiridentity.INSULT:insulting,inammatory,ornegativecommenttowardsapersonoragroupofpeople.PROFANITY:swearwords,cursewords,orotherobsceneorprofanelang
5 uage.THREAT:describesanintentionto
uage.THREAT:describesanintentiontoinictpain,injury,orviolenceagainstanindividualorgroup.SEXUALLY_EXPLICIT:containsreferencestosexualacts,bodyparts,orotherlewdcon-tent.FLIRTATION:pickuplines,complimentingappearance,subtlesexualinnuendos,etc.Formoredetailsonhowtheseweretrained,seetheToxicityandsub-attributeannotationguidelines.NewYorkTimesmoderationmodelsThefollowingexperimentalmodelsweretrainedonNewYorkTimesdatataggedbytheirmodera-tionteam.ATTACK_ON_AUTHOR:Attackontheauthorofanarticleorpost.ATTACK_ON_COMMENTER:Attackonfellowcommenter.INCOHERENT:Difculttounderstand,nonsensical.INFLAMMATORY:Intendingtoprovokeoriname.LIKELY_TO_REJECT:OverallmeasureofthelikelihoodforthecommenttoberejectedaccordingtotheNYT'smoderation.OBSCENE:Obsceneorvulgarlanguagesuchascursing.SPAM:Irrelevantandunsolicitedcommercialcontent.UNSUBSTANTIAL:Trivialorshortcomments. 4db_get_dataDon'tforgettoregainyourspiritsAnalyzingtoxiccommentscanbedishearteningsometimes.Feelfreetolooka
6 tthispictureofcutekittenswheneveryouneed
tthispictureofcutekittenswheneveryouneedto: db_appendSQLDatabaseAppend DescriptionThisisahelperfunctionthatwillwriteadataframetoaSQLdatabaseUsagedb_append(path,tbl,data)ArgumentspathpathtoSQLdatabasetblnameofthetableinSQLdatabasedatatheobjectdataframethatgoesintotheSQLdatabase db_get_dataSQLDatabaseRetrieve DescriptionThisisahelperfunctionthatwillretreiveadataframetoaSQLdatabaseUsagedb_get_data(tbl_dat,path="sql_data/omdata.db")Argumentstbl_datwhichtablefromtheSQLdatabasedoyouwanttoretrievepathpathtodatabase db_remove5 db_removeSQLDatabaseRemove DescriptionThisisahelperfunctionthatwillremoveadataframefromaSQLdatabaseUsagedb_remove(path,datasets=NULL,remove_cleaned_data=T)ArgumentspathpathtodatabasedatasetswhichtablefromtheSQLdatabasedoyouwanttoremoveremove_cleaned_databooleanremovealldatasetsthatarecreatedthroughthecleaningscript form_requestCreateaGETrequestforPerspectiveAPI DescriptionFormoredetailssee?peRspectiveorPerspectiveAPIdocumentationUsageform_request(score_model,text,score_sentences,languages,doNotStore=F)Argum
7 entsscore_modelSpecifywhatmodeldoyouwant
entsscore_modelSpecifywhatmodeldoyouwanttouse(forexampleTOXICITYand/orSEVERE_TOXICITY).Specifyacharactervectorifyouwantmorethanonescore.SeepeRspective::prsp_models.textacharacterstring.score_sentencesAbooleanvaluethatindicatesiftherequestshouldreturnspansthatdescribethescoresforeachpartofthetext(currentlydoneatpersentencelevel).DefaultstoFALSE.languagesAvectorofISO631-1two-letterlanguagecodesspecifyingthelanguage(s)thatcommentisin(forexample,"en","es","fr","de",etc).Ifunspecied,theAPIwillautodetectthecommentlanguage.Iflanguagedetectionfails,theAPIreturnsanerror. 6perspective_api_keydoNotStoreWhethertheAPIispermittedtostorecommentfromthisrequest.Storedcom-mentswillbeusedforfutureresearchandcommunitymodelbuildingpurposestoimprovetheAPIovertime.PerspectiveAPIalsoplanstoprovidedashboardsandautomatedanalysisofthecommentssubmitted,whichwillapplyonlytothosestored.DefaultstoFALSE(requestdatamaybestored).Importantnote:Thisshouldbesettotrueifdatabeingsubmittedisprivate(i.e.notpubliclyaccessible),orifthedatasubmittedcontainscont
8 entwrittenbysomeoneunder13yearsold.Value
entwrittenbysomeoneunder13yearsold.Valueatibble msgSendafancymessage DescriptionPrintabeautifulmessageintheconsoleUsagemsg(type,type_style=crayon::make_style("red4"),msg)Argumentstypewhatmessageshouldbedisplayedinthebeginningtype_stylecrayoncolororstylemsgwhatmessageshouldbeprintedExamples##Sendamessagetotheworldmsg("MESSAGE",crayon::make_style('blue4'),"Thisisamessagetotheworld") perspective_api_keyCheckifAPIkeyispresent DescriptionCheckifAPIkeyispresentUsageperspective_api_key(test=F) print_progress7Argumentstestnecessarywheninatestenvironment.DefaultstoFALSE. print_progressPrintprogressinpurrr::imapenvironment DescriptionProvideiteratornumberandtotallengthofitemstobeiteratedoverUsageprint_progress(x,total,print_prct=F)Argumentsxiteratornumber.totallengthofitemstobeiteratedover.print_prctonlyprintpercentageprogress(defaultstoFALSE).ValueachrExamples##Printprogress(1outof100)print_progress(1,100)##Onlyprintpercentageprint_progress(1,100,print_prct=TRUE) prsp_exp_modelsAllvalidexperimentalPerspectiveAPImodels DescriptionA
9 llvalidexperimentalPerspectiveAPImodels
llvalidexperimentalPerspectiveAPImodels prsp_modelsAllvalid(non-experimental)PerspectiveAPImodels DescriptionAllvalid(non-experimental)PerspectiveAPImodels 8prsp_score prsp_scoreAnalyzecommentswithPerspectiveAPI DescriptionProvideacharacterstringwithyourtext,yourAPIkeyandwhatscoresyouwanttoobtain.Usageprsp_score(text,text_id=NULL,languages=NULL,score_sentences=F,score_model,sleep=1,doNotStore=F,key=NULL)Argumentstextacharacterstring.text_idauniqueIDforthetextthatyousupply(required).languagesAvectorofISO631-1two-letterlanguagecodesspecifyingthelanguage(s)thatcommentisin(forexample,"en","es","fr","de",etc).Ifunspecied,theAPIwillautodetectthecommentlanguage.Iflanguagedetectionfails,theAPIreturnsanerror.score_sentencesAbooleanvaluethatindicatesiftherequestshouldreturnspansthatdescribethescoresforeachpartofthetext(currentlydoneatpersentencelevel).DefaultstoFALSE.score_modelSpecifywhatmodeldoyouwanttouse(forexampleTOXICITYand/orSEVERE_TOXICITY).Specifyacharactervectorifyouwantmorethanonescore.SeepeRspective::prsp_models.sle
10 ephowlongshouldprsp_scorewaitbetweeneach
ephowlongshouldprsp_scorewaitbetweeneachcalldoNotStoreWhethertheAPIispermittedtostorecommentfromthisrequest.Storedcom-mentswillbeusedforfutureresearchandcommunitymodelbuildingpurposestoimprovetheAPIovertime.PerspectiveAPIalsoplanstoprovidedashboardsandautomatedanalysisofthecommentssubmitted,whichwillapplyonlytothosestored.DefaultstoFALSE(requestdatamaybestored).Importantnote:Thisshouldbesettotrueifdatabeingsubmittedisprivate(i.e.notpubliclyaccessible),orifthedatasubmittedcontainscontentwrittenbysomeoneunder13yearsold.keyYourAPIkey(seeheretosetupanAPIkey). prsp_stream9DetailsFormoredetailssee?peRspectiveorPerspectiveAPIdocumentationValueatibbleExamples##Notrun:##GETTOXICITYSCORESforacommentprsp_score("Hello,Iamatestcomment!",score_model="TOXICITY")##GETTOXICITYandSEVERE_TOXICITYScoresforacommentprsp_score("Hello,Iamatestcomment!",score_model=c("TOXICITY","SEVERE_TOXICITY"))##GETTOXICITYandSEVERE_TOXICITYScoresforeachsentenceofacommentprsp_score("Hello,Iamatestcomment!IamasecondsentenceandIwill(hopefully)bescoredseperately"
11 ,score_model=c("TOXICITY","SEVERE_TOXICI
,score_model=c("TOXICITY","SEVERE_TOXICITY"),score_sentences=T)##End(Notrun) prsp_streamStreamcommentscoreswithPerspectiveAPI DescriptionThisfunctionwrapsprsp_scoreandloopsoveryourtextinput.Provideacharacterstringwithyourtextandwhichscoresyouwanttoobtain.Makesuretokeeptrackofyourratelimitwithonthecloudconsolequotausagepage.Usageprsp_stream(.data,text=NULL,text_id=NULL,...,safe_output=F,verbose=F,save=F,dt_name="persp") 10prsp_streamArguments.dataadatasetwithatextandtext_idcolumn.textacharactervectorwithtextyouwanttoscore.text_idauniqueIDforthetextthatyousupply(required)...argumentspassedtoprsp_score.Don'tforgettoaddthescore_modelargu-ment(seepeRspective::prsp_modelsforlistofvalidmodels).safe_outputwrapsthefunctionintoapurrr::safelyenvironment(defaultstoFALSE).Loopwillrunwithoutpauseandcatch+outputerrorsinatidytibblealongwiththeresults.verbosenarratesthestreamingprocedure(defaultstoFALSE).saveNOTUSABLEYETsavesdataintoSQLitedatabase(defaultstoFALSE).dt_nameNOTUSABLEYETwhatisthenameofthedataset?(defaultstopersp).DetailsFormo
12 redetailssee?peRspectiveorPerspectiveAPI
redetailssee?peRspectiveorPerspectiveAPIdocumentationValueatibbleExamples##Notrun:##Createamocktibbletext_sampletibble(ctext=c("Youwrotethis?Wow.Thisisdumbandchildish,pleasegof****yourself.","Idon'tknowwhattosayaboutthisbutit'snotgood.Thecommenterisjustanidiot","Thisgoesevenfurther!","Whatthehellisgoingon?","Please.Idon'tgetit.Explainitagain","Annoyingandirrelevant!I'dratherwatchthepaintdryingonthewall!"),textid=c("#efdcxct","#ehfcsct","#ekacxwt","#ewatxad","#ekacswt","#ewftxwd"))##GETTOXICITYandSEVERE_TOXICITYScoresforadatasetwithatextcolumntext_sample--50;%%prsp_stream(text=ctext,text_id=textid,score_model=c("TOXICITY","SEVERE_TOXICITY"))##SafeOutputargumentmeanswillnotstoponerrorprsp_stream(text=ctext,text_id=textid,score_model=c("TOXICITY","SEVERE_TOXICITY"),safe_output=T) specify_decimal11##verbose=Tmeansyougetprettynarrationofyourscoringprocedureprsp_stream(text=ctext,text_id=textid,score_model=c("TOXICITY","SEVERE_TOXICITY"),safe_output=T,verbose=T)##End(Notrun) specify_decimalSpecifyadecimal Description
13 SpecifyadecimalUsagespecify_decimal(x,k)
SpecifyadecimalUsagespecify_decimal(x,k)ArgumentsxanumbertoberoundedkroundtowhichpositionafterthecommaExamples##specify2decimalsofanumberspecify_decimal(1.0434,2) unnest_scoresUnnestscorescomingoutofPerspectiveAPI DescriptionFormoredetailssee?peRspectiveorPerspectiveAPIdocumentationUsageunnest_scores(Output,score_model,score_sentences,text) 12unnest_scoresArgumentsOutputcomesoutoftheGETcall.score_modelSpecifywhatmodeldoyouwanttouse(forexampleTOXICITYand/orSEVERE_TOXICITY).Specifyacharactervectorifyouwantmorethanonescore.SeepeRspective::prsp_models.score_sentencesAbooleanvaluethatindicatesiftherequestshouldreturnspansthatdescribethescoresforeachpartofthetext(currentlydoneatpersentencelevel).DefaultstoFALSE.textacharacterstring.Valueatibble Indexdatasetsprsp_exp_models,7prsp_models,7db_append,4db_get_data,4db_remove,5form_request,5msg,6peRspective(perspective-package),2perspective-package,2perspective_api_key,6print_progress,7prsp_exp_models,7prsp_models,7prsp_score,8,9,10prsp_stream,9specify_decimal,11unnest_scores,111