-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
183 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# @file CustomEmbeddingModel.R | ||
# | ||
# Copyright 2024 Observational Health Data Sciences and Informatics | ||
# | ||
# This file is part of DeepPatientLevelPrediction | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
#' Create default settings a model using custom embeddings | ||
#' | ||
#' @description A model that uses custom embeddings such as Poincare embeddings | ||
#' @param embeddingFilePath path to the saved Poincare embedding | ||
#' @param estimatorSettings created with `setEstimator` | ||
#' @param modelSettings for the model to use, needs to have an embedding layer | ||
#' | ||
#' @return settings for a model using custom embeddings:w | ||
#' | ||
#' @export | ||
setCustomEmbeddingModel <- function( | ||
embeddingFilePath, | ||
estimatorSettings = | ||
setEstimator( | ||
learningRate = "auto", | ||
weightDecay = 1e-4, | ||
batchSize = 256, | ||
epochs = 2, | ||
seed = NULL, | ||
device = "cpu" | ||
), | ||
modelSettings = setTransformer( | ||
numBlocks = 3, | ||
dimToken = 16, | ||
dimOut = 1, | ||
numHeads = 4, | ||
attDropout = 0.2, | ||
ffnDropout = 0.1, | ||
resDropout = 0.0, | ||
dimHidden = 32, | ||
estimatorSettings = estimatorSettings, | ||
hyperParamSearch = "random", | ||
randomSample = 1 | ||
) | ||
) { | ||
path <- system.file("python", package = "DeepPatientLevelPrediction") | ||
estimatorSettings$initStrategy <- | ||
reticulate::import_from_path("InitStrategy", | ||
path = path)$CustomEmbeddingInitStrategy() | ||
estimatorSettings$embeddingFilePath <- embeddingFilePath | ||
transformerSettings <- modelSettings | ||
|
||
attr(transformerSettings, "settings")$name <- "CustomEmbeddingTransformer" | ||
return(transformerSettings) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.