get_gender_nn: Predict gender from Brazilian first names using a neural...

View source: R/get_gender_nn.R

get_gender_nnR Documentation

Predict gender from Brazilian first names using a neural network

Description

get_gender_nn uses a 2-layer bidirectional GRU neural network with attention pooling to predict gender from Brazilian first names. Unlike get_gender, this function can generalise to names not present in the IBGE census dataset.

Usage

get_gender_nn(
  names,
  prob = FALSE,
  threshold = 0.9,
  nn_size = NULL,
  device = NULL,
  encoding = "ASCII//TRANSLIT"
)

Arguments

names

A character vector specifying a person's first name. Names can also be passed to the function as a full name (e.g., Ana Maria de Souza). get_gender_nn is case insensitive.

prob

Report the proportion of female uses of the name? Defaults to FALSE.

threshold

Numeric indicating the threshold used in predictions. Defaults to 0.9. A single value sets the same threshold for both sexes; a vector with two values sets one threshold per sex, the first for females and the second for males (e.g., c(0.9, 0.8)). The two values can also be named, in any order (e.g., c(Female = 0.9, Male = 0.8) or c(F = 0.9, M = 0.8)). Because a name cannot be female and male at the same time, the two thresholds must sum to at least 1.

nn_size

Batch size for neural network inference. When NULL (the default), all names are classified at once. Set it to an integer to split a large input vector of first names into batches of that size, which avoids out-of-memory crashes when analyzing large datasets.

device

Device used for inference. When NULL (the default), the CPU is used. Set it to "cuda" or "mps" to run on a GPU (note that Apple Silicon's MPS shares system memory, so nn_size is what prevents memory crashes there).

encoding

(Deprecated) Previously used to strip accents via iconv. Accents are now removed with a platform-independent method and this argument is ignored. It will be removed in a future version.

Details

Model weights and vocabulary must be downloaded before first use with download_gender_model. If the files are not found in an interactive session, you will be prompted to download them. Subsequent calls within the same session use an in-memory cache.

Value

get_gender_nn may return three different values: Female, if the name provided is female; Male, if the name provided is male; or NA, if we can not predict gender from the name given the chosen threshold.

If the prob argument is set to TRUE, then the function returns the proportion of females uses of the provided name.

See Also

get_gender, download_gender_model

Examples

## Not run: 
get_gender_nn("Maria")
get_gender_nn(c("Maria", "Joao"), prob = TRUE)
get_gender_nn("Ana Maria de Souza")

## End(Not run)


genderBR documentation built on July 13, 2026, 1:06 a.m.