def vectors(request, dataset): """ Generate random word vectors Params: dimensionality """ output_vec = normalize_rows(np.random.randn(dataset.dim, request.param)) input_vec = normalize_rows(np.random.randn(1, request.param)) return input_vec, output_vec
def test_normalize_rows(): first = normalize_rows(np.array([[3.0, 4.0], [1.0, 2.0]])) second = np.array([[0.6, 0.8], [0.4472, 0.8944]]) assert_close( first, second )
def dummy_vectors(dataset): dim = 10 weights = 0.1 * np.random.randn(dim, 5) features = np.zeros((dataset.dim, dim)) labels = np.zeros((dataset.dim,), dtype=np.int32) word_vectors = normalize_rows(np.random.randn(dataset.dim, dim)) for i in xrange(dataset.dim): words, labels[i] = dataset.get_random_train_sentence() features[i, :] = get_sentence_feature(dataset.tokens, word_vectors, words) return weights, features, labels