predict.Rcpp_fastrtext: Get predictions (for supervised model)

Description Usage Arguments Value Examples

View source: R/API.R

Description

Apply the trained model to new sentences. Average word embeddings and search most similar label vector.

Usage

1
2
3
4
## S3 method for class 'Rcpp_fastrtext'
predict(object, sentences, k = 1,
  simplify = FALSE, unlock_empty_predictions = FALSE, threshold = 0,
  ...)

Arguments

object

trained fastText model

sentences

character containing the sentences

k

will return the k most probable labels (default = 1)

simplify

when TRUE and k = 1, function return a (flat) numeric instead of a list

unlock_empty_predictions

logical to avoid crash when some predictions are not provided for some sentences because all their words have not been seen during training. This parameter should only be set to TRUE to debug.

threshold

used to limit number of words used. (optional; 0.0 by default)

...

not used

Value

list containing for each sentence the probability to be associated with k labels.

Examples

1
2
3
4
5
6
library(fastrtext)
data("test_sentences")
model_test_path <- system.file("extdata", "model_classification_test.bin", package = "fastrtext")
model <- load_model(model_test_path)
sentence <- test_sentences[1, "text"]
print(predict(model, sentence))

fastrtext documentation built on Oct. 30, 2019, 11:32 a.m.