Learn R Programming

LilRhino (version 1.2.2)

Sentence_Vector: Function for extracting the sentence vector from an embeddings matrix.

Description

Function for extracting the sentence vector from an embeddings matrix in a fast and convenient manner.

Usage

Sentence_Vector(Sentence, emb_matrix, dimension, stopwords)

Arguments

Sentence

The sentence to find the vector of.

emb_matrix

The embeddings matrix to search.

dimension

The dimension of the vector to return.

stopwords

Words that should not be included in the averaging proccess.

Value

The sentence vector from an embeddings matrix.

Details

The function splits the sentence into words, eliminates all stopwords, finds the vectors of each word, then averages the word vectors into a sentence vector.

Examples

Run this code
# NOT RUN {
  emb = data.frame(matrix(c(1, 2, 3, 4, 5, 5,
  4, 3, 2, 1, 1, 5, 3, 2, 4), nrow = 3),
  row.names = c('sentence', 'in', 'question'))

  Sentence_Vector(c('this is the sentence in question'), emb, 5, c('this', 'is', 'the'))


# }

Run the code above in your browser using DataLab