View source: R/compute_transform.R
compute_transform | R Documentation |
Computes a transformation matrix, given a feature-co-occurrence matrix and corresponding pre-trained embeddings.
compute_transform(x, pre_trained, weighting = 500)
x |
a (quanteda) |
pre_trained |
(numeric) a F x D matrix corresponding to pretrained embeddings,
usually trained on the same corpus as that used for |
weighting |
(character or numeric) weighting options:
Recommended: use |
a dgTMatrix-class
D x D non-symmetrical matrix
(D = dimensions of pre-trained embedding space) corresponding
to an 'a la carte' transformation matrix. This matrix is optimized
for the corpus and pre-trained embeddings employed.
library(quanteda) # note, cr_sample_corpus is too small to produce sensical word vectors # tokenize toks <- tokens(cr_sample_corpus) # construct feature-co-occurrence matrix toks_fcm <- fcm(toks, context = "window", window = 6, count = "weighted", weights = 1 / (1:6), tri = FALSE) # you will generally want to estimate a new (corpus-specific) # GloVe model, we will use cr_glove_subset instead # see the Quick Start Guide to see a full example. # estimate transform local_transform <- compute_transform(x = toks_fcm, pre_trained = cr_glove_subset, weighting = 'log')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.