Use a fitted stylest_model to predict the most likely speaker of a text. This function may be used on in-sample or out-of-sample texts.

stylest_predict(model, text, prior = NULL)

Arguments

model

stylest_model object

text

Text vector. May be a corpus_frame object

prior

Prior probability, defaults to NULL

Value

stylest_predict object containing: model the fitted stylest_model object used in prediction, predicted the predicted speaker, log_probs matrix of log probabilities, log_prior matrix of log prior probabilities

Examples

data(novels_excerpts) speaker_mod <- stylest_fit(novels_excerpts$text, novels_excerpts$author) stylest_predict(speaker_mod, "This is an example text, who wrote it?")
#> $model #> A S3 stylest_model object containing: 3 unique authors and 1043 unique terms. #> $predicted #> [1] Austen, Jane #> Levels: Austen, Jane Eliot, George Gaskell, Elizabeth Cleghorn #> #> $log_probs #> 1 x 3 Matrix of class "dgeMatrix" #> Austen, Jane Eliot, George Gaskell, Elizabeth Cleghorn #> [1,] -0.3211882 -1.405527 -3.524201 #> #> $log_prior #> Austen, Jane Eliot, George #> -1.098612 -1.098612 #> Gaskell, Elizabeth Cleghorn #> -1.098612 #> #> attr(,"class") #> [1] "stylest_predict"