Description Usage Arguments Value Examples
Trains a supervised model, following the method layed out in Bag of Tricks for Efficient Text Classification using the fasttext implementation.
See FastText text classification tutorial for more information on training supervised models using fasttext.
1 2 3 4 5 6 | build_supervised(documents, targets, model_path, lr = 0.05, dim = 100,
ws = 5, epoch = 5, minCount = 5, minCountLabel = 0, neg = 5,
wordNgrams = 1, loss = c("ns", "hs", "softmax", "ova", "one-vs-all"),
bucket = 2e+06, minn = 3, maxn = 6, thread = 12,
lrUpdateRate = 100, t = 1e-04, label = "__label__", verbose = 2,
pretrainedVectors = NULL)
|
documents |
character vector of documents used for training |
targets |
vector of targets/catagory of each document. Must have same length as |
model_path |
Name of output file without file extension. |
lr |
learning rate |
dim |
size of word vectors |
ws |
size of the context window |
epoch |
number of epochs |
minCount |
minimal number of word occurences |
minCountLabel |
minimal number of label occurences |
neg |
number of negatives sampled |
wordNgrams |
max length of word ngram |
loss |
= c('softmax', 'ns', 'hs', 'ova'), loss function ns, hs, softmax, one Vs all. one Vs all loss is usefull for multi class when you need to apply a threshold for each class score. |
bucket |
number of buckets |
minn |
min length of char ngram |
maxn |
max length of char ngram |
thread |
number of threads |
lrUpdateRate |
change the rate of updates for the learning rate |
t |
sampling threshold |
label |
text string, labels prefix. Default is "label" |
verbose |
verbosity level |
pretrainedVectors |
path to pretrained word vectors for supervised learning. Leave empty for no pretrained vectors. |
path to new model file as a character
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | ## Not run:
library(fastrtext)
model_file <- build_supervised(documents = train_sentences[["text"]],
targets =train_sentences[["class.text"]],
model_path = 'my_model',
dim = 20, lr = 1, epoch = 20, wordNgrams = 2)
model <- load_model(model_file)
predictions <- predict(model, test_sentences[["text"]])
mean(sapply(predictions, names) == test_sentences[["class.text"]])
# ~0.8
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.