Skip to content

Commit

Permalink
test dependencies fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnCoene committed Aug 23, 2019
1 parent 5c46b01 commit 2b8eab5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/testthat/test-dependencies.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
test_that("dependencies works", {
install_dependencies()
expect_output(install_dependencies())
})
11 changes: 11 additions & 0 deletions tests/testthat/test-models.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ test_that("models works", {
corpus_bow <- doc2bow(dictionary, docs)
corpus_mm <- serialize_mmcorpus(corpus_bow, auto_delete = FALSE)
mm <- read_serialized_mmcorpus(corpus_mm)
expect_type(mm, "environment")

# tfidf
tfidf_file <- model_tfidf(corpus_mm)
Expand All @@ -25,12 +26,14 @@ test_that("models works", {
# lsi
k <- 2L
lsi <- model_lsi(corpus_transformed_file, id2word = dictionary, num_topics = k)
expect_type(lsi, "environment")
wrapped_corpus <- wrap(lsi, corpus_transformed_file)
wrapped_corpus_docs <- get_docs_topics(wrapped_corpus)
expect_length(wrapped_corpus_docs, k * 2)

# fasttext
ft <- model_fasttext(size = 4L, window = 3L, min_count = 1L)
expect_type(ft, "environment")
ft$build_vocab(sentences = docs)
ft$train(sentences = docs, total_examples = length(docs), epochs = 10L)
sim <- ft$wv$most_similar(positive = c('computer', 'human'), negative = c('interface')) %>%
Expand All @@ -43,33 +46,39 @@ test_that("models works", {

# random projections
rp <- model_rp(corpus_transformed_file, id2word = dictionary, num_topics = k)
expect_type(rp, "environment")
wrapped_corpus <- wrap(rp, corpus_transformed_file)
wrapped_corpus_docs <- get_docs_topics(wrapped_corpus)
expect_length(wrapped_corpus_docs, k * 2)

# lda
lda <- model_lda(corpus_transformed_file, id2word = dictionary, num_topics = k)
expect_type(lda, "environment")
wrapped_corpus <- wrap(lda, corpus_transformed_file)
wrapped_corpus_docs <- get_docs_topics(wrapped_corpus)
expect_length(wrapped_corpus_docs, k * 2)

# ldamc
ldamc <- model_ldamc(corpus_mm, id2word = dictionary, num_topics = k)
expect_type(ldamc, "environment")
wrapped_corpus <- wrap(ldamc, corpus_transformed_file)
wrapped_corpus_docs <- get_docs_topics(wrapped_corpus)
expect_length(wrapped_corpus_docs, k * 2)

# log entropy
log_entropy <- model_logentropy(corpus_bow)
expect_type(log_entropy, "environment")
wrapped_corpus <- wrap(log_entropy, corpus_bow)

# hdp
hdp <- model_hdp(corpus_mm, id2word = dictionary)
expect_type(hdp, "environment")
topics <- reticulate::py_to_r(hdp$show_topic(topic_id = 1L, topn = 5L))
expect_length(topics, 5L)

# word2vec
word2vec <- model_word2vec(size = 100L, window = 5L, min_count = 1L)
expect_type(word2vec, "environment")
word2vec$build_vocab(docs)
word2vec$train(docs, total_examples = word2vec$corpus_count, epochs = 20L)
word2vec$init_sims(replace = TRUE)
Expand All @@ -92,6 +101,7 @@ test_that("models works", {
data("authors")

auth2doc <- auth2doc(authors, name, document)
expect_type(auth2doc, "environment")

# create temp to hold serialized data
temp <- tempfile("serialized")
Expand All @@ -105,6 +115,7 @@ test_that("models works", {
serialized = TRUE,
serialization_path = temp
)
expect_type(atmodel, "environment")

# delete temp
unlink(temp, recursive = TRUE)
Expand Down

0 comments on commit 2b8eab5

Please sign in to comment.