Skip to contents

Configures a model to use supplied embeddings, such as Poincare embeddings or embeddings from a foundation model.

Usage

setCustomEmbeddingModel(
  embeddingFilePath,
  modelSettings = setTransformer(numBlocks = 3, dimToken = 16, dimOut = 1, numHeads = 4,
    attDropout = 0.2, ffnDropout = 0.1, dimHidden = 32, estimatorSettings =
    setEstimator(learningRate = "auto", weightDecay = 1e-04, batchSize = 256, epochs = 2,
    seed = NULL, device = "cpu"), hyperParamSearch = "random", randomSample = 1),
  embeddingsClass = "CustomEmbeddings"
)

Arguments

embeddingFilePath

Path to a PyTorch file containing a dictionary with concept_ids, a PyTorch long tensor, and embeddings, a PyTorch float tensor.

modelSettings

Settings for a model with an embedding layer named embedding. The supplied embeddings replace that layer.

embeddingsClass

Embedding implementation, either "CustomEmbeddings" or "PoincareEmbeddings".

Value

A modelSettings object configured to initialize custom embeddings.

Examples

if (FALSE) { # \dontrun{
# Requires Python and the package's Python dependencies, including PyTorch.
# See vignette("Installing") for setup instructions.
embeddingFilePath <- tempfile(fileext = ".pt")

# Toy embeddings: one row per concept ID, with eight values per row.
conceptIds <- c(1L, 2L, 3L)
embeddings <- list(
  concept_ids = torch$tensor(conceptIds, dtype = torch$long),
  embeddings = torch$randn(length(conceptIds), 8L, dtype = torch$float)
)
torch$save(embeddings, embeddingFilePath)

modelSettings <- setCustomEmbeddingModel(
  embeddingFilePath = embeddingFilePath,
  modelSettings = setDefaultTransformer()
)

# Clean up this example's file. In real use, keep it until training finishes:
# modelSettings stores its path, not the embedding tensors themselves.
unlink(embeddingFilePath)
} # }