Skip to content

Commit

Permalink
Adding caching and other performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
bmschmidt committed Aug 30, 2016
1 parent 2f843ae commit 67b55a5
Show file tree
Hide file tree
Showing 26 changed files with 91 additions and 40 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -6,3 +6,6 @@ inst/extdata/
hum2vec.Rproj
src/*.o
src/*.so
cookbooks cookbooks.txt cookbooks.vectors cookbooks.zip
cookbooks*
etc
21 changes: 13 additions & 8 deletions DESCRIPTION
@@ -1,18 +1,23 @@
Package: wordVectors
Type: Package
Title: Tools for creating and analyzing vector-space models of texts
Version: 1.0
Version: 1.1
Date: 2015-09-10
Author: Ben Schmidt, Jian Li
Maintainer: Ben Schmidt <bmschmidt@gmail.com>
Description: wordVectors wraps the word2vec code for creating vector-space models of texts, and defines a new class "VectorSpaceModel" extending matrix with a number of functions that make it easier to perform useful operations in a word-vector space.
Description: wordVectors wraps Google's word2vec code for creating vector-space
models of texts, and defines a new class "VectorSpaceModel" (extending the native matrix class)
with a number of functions that make it easier to perform useful operations in a
word-vector space.
License: Apache License (== 2.0)
Depends: R (>= 2.14.0)
Depends:
R (>= 2.14.0)
LazyData: TRUE
Imports:
graphics,
methods,
utils
graphics,
methods,
utils
Suggests:
stringi,
tsne
stringi,
tsne
RoxygenNote: 5.0.1
2 changes: 1 addition & 1 deletion NAMESPACE
@@ -1,4 +1,4 @@
# Generated by roxygen2 (4.1.1): do not edit by hand
# Generated by roxygen2: do not edit by hand

export(as.VectorSpaceModel)
export(cosineDist)
Expand Down
10 changes: 5 additions & 5 deletions R/matrixFunctions.R
Expand Up @@ -18,14 +18,13 @@ setMethod("initialize", "VectorSpaceModel",
callNextMethod(.Object, .cache=.cache, ...)
})

#' Cached Square Magnitudes
#' Square Magnitudes with caching
#'
#' @param VectorSpaceModel
#' @param VectorSpaceModel A matrix or VectorSpaceModel object
#' @description square_magnitudes Returns the square magnitudes and
#' caches them if necessary
#' @return A vector of the square magnitudes for each row
#' @keywords internal
#' @examples
square_magnitudes = function(object) {
if (class(object)=="VectorSpaceModel") {
if (.hasSlot(object, ".cache")) {
Expand All @@ -47,10 +46,11 @@ square_magnitudes = function(object) {

#' VectorSpaceModel indexing
#'
# @description Reduce a VectorSpaceModel to a smaller one
#' @description Reduce a VectorSpaceModel to a smaller one
#' @param x The vectorspace model to subset
#' @param i The row numbers to extract
#' @param j The column numbers to extract
#' @param j Other arguments to extract (unlikely to be useful).
#' @param drop Whether to drop columns. This parameter is ignored.
#' @return A VectorSpaceModel
#'
Expand Down Expand Up @@ -451,7 +451,7 @@ cosineDist <- function(x,y) {
#' of the same length as the VectorSpaceModel.
#'
#' @return A new matrix or VectorSpaceModel of the same dimensions as `matrix`,
#' each row of which is parallel to vector
#' each row of which is parallel to vector.
#'
#' If the input is a matrix, the output will be a matrix: if a VectorSpaceModel,
#' it will be a VectorSpaceModel.
Expand Down
Binary file modified data/demo_vectors.rda
Binary file not shown.
2 changes: 1 addition & 1 deletion man/VectorSpaceModel-VectorSpaceModel-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion man/VectorSpaceModel-class.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/as.VectorSpaceModel.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/cosineDist.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions man/cosineSimilarity.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/demo_vectors.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/filter_to_rownames.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/magnitudes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/nearest_to.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/normalize_lengths.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/plot-VectorSpaceModel-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/prep_word2vec.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/project.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions man/read.binary.vectors.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/read.vectors.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/reject.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions man/square_magnitudes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions man/sub-VectorSpaceModel-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/sub-sub-VectorSpaceModel-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/train_word2vec.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/write.binary.word2vec.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 67b55a5

Please sign in to comment.