2
基於text2vec包的小插圖,提供了一個用於創建文字嵌入的示例。將wiki數據標記化,然後創建術語共生矩陣(TCM),用於創建單詞使用包裝中提供的手套功能嵌入。 我想爲隨包提供的電影評論數據構建詞嵌入。我的問題是:準備word2vec中的文字嵌入R包
- 我是否需要將所有電影評論摺疊成一個長字符串,然後進行標記。
這將導致2條評論之間的邊界標記共現,這是沒有意義的。
**vignettes code:**
library(text2vec)
library(readr)
temp <- tempfile()
download.file('http://mattmahoney.net/dc/text8.zip', temp)
wiki <- read_lines(unz(temp, "text8"))
unlink(temp)
# Create iterator over tokens
tokens <- strsplit(wiki, split = " ", fixed = T)
# Create vocabulary. Terms will be unigrams (simple words).
vocab <- create_vocabulary(itoken(tokens))
vocab <- prune_vocabulary(vocab, term_count_min = 5L)
# We provide an iterator to create_vocab_corpus function
it <- itoken(tokens)
# Use our filtered vocabulary
vectorizer <- vocab_vectorizer(vocab,
# don't vectorize input
grow_dtm = FALSE,
# use window of 5 for context words
skip_grams_window = 5L)
tcm <- create_tcm(it, vectorizer)
fit <- glove(tcm = tcm,
word_vectors_size = 50,
x_max = 10, learning_rate = 0.2,
num_iters = 15)
我感興趣的開發的嵌入字爲能搞到的數據如下:
library(text2vec)
data("movie_review")
謝謝您的回答。這正是我所希望的。 – amitkb3