Skip to content

Commit 829d255

Browse files
committed
much faster when getting the vocabulary by converting to utf8 before passing to R
1 parent 63eddea commit 829d255

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

R/layer-text_vectorization.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ layer_text_vectorization <- function(object, max_tokens = NULL, standardize = "l
9393
#' @seealso [set_vocabulary()]
9494
#' @export
9595
get_vocabulary <- function(object) {
96-
object$get_vocabulary()
96+
python_path <- system.file("python", package = "keras")
97+
tools <- import_from_path("kerastools", path = python_path)
98+
tools$get_vocabulary$get_vocabulary(object)
9799
}
98100

99101
#' Sets vocabulary (and optionally document frequency) data for the layer
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
def get_vocabulary (layer):
3+
vocab = layer.get_vocabulary()
4+
return([x.decode("UTF-8") for x in vocab])
5+

0 commit comments

Comments
 (0)