step_lemma creates a specification of a recipe step that will extract the lemmatization of a tokenlist.

  role = NA,
  trained = FALSE,
  columns = NULL,
  skip = FALSE,
  id = rand_id("lemma")

# S3 method for step_lemma
tidy(x, ...)



A recipe object. The step will be added to the sequence of operations for this recipe.


One or more selector functions to choose variables. For step_lemma, this indicates the variables to be encoded into a tokenlist. See recipes::selections() for more details. For the tidy method, these are not currently used.


Not used by this step since no new variables are created.


A logical to indicate if the recipe has been baked.


A list of tibble results that define the encoding. This is NULL until the step is trained by recipes::prep.recipe().


A logical. Should the step be skipped when the recipe is baked by recipes::bake.recipe()? While all operations are baked when recipes::prep.recipe() is run, some operations may not be able to be conducted on new data (e.g. processing the outcome variable(s)). Care should be taken when using skip = TRUE as it may affect the computations for subsequent operations.


A character string that is unique to this step to identify it.


A step_lemma object.


An updated version of recipe with the new step added to the sequence of existing steps (if any).


This stem doesn't perform lemmatization by itself, but rather lets you extract the lemma attribute of the tokenlist. To be able to use step_lemma you need to use a tokenization method that includes lemmatization. Currently using the "spacyr" engine in step_tokenize() provides lemmatization and works well with step_lemma.

See also

step_tokenize() to turn character into tokenlist.

Other tokenlist to tokenlist steps: step_ngram(), step_pos_filter(), step_stem(), step_stopwords(), step_tokenfilter(), step_tokenmerge()


# \dontrun{ library(recipes) short_data <- data.frame(text = c("This is a short tale,", "With many cats and ladies.")) okc_rec <- recipe(~ text, data = short_data) %>% step_tokenize(text, engine = "spacyr") %>% step_lemma(text) %>% step_tf(text) okc_obj <- prep(okc_rec)
#> Found 'spacy_condaenv'. spacyr will use this environment
#> successfully initialized (spaCy Version: 2.3.1, language model: en_core_web_sm)
#> (python options: type = "condaenv", value = "spacy_condaenv")
#> # A tibble: 2 x 12 #> `tf_text_,` tf_text_. tf_text_a tf_text_and tf_text_be tf_text_cat #> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 1 0 1 0 1 0 #> 2 0 1 0 1 0 1 #> # … with 6 more variables: tf_text_lady <dbl>, tf_text_many <dbl>, #> # tf_text_short <dbl>, tf_text_tale <dbl>, tf_text_this <dbl>, #> # tf_text_with <dbl>
# }