| 114 | // ---------------------------------------------------------------------------------------- |
| 115 | |
| 116 | void test_with_tfidf() |
| 117 | { |
| 118 | // The intended use: hashed counts in, TF-IDF weighted vectors out. |
| 119 | const std::vector<std::vector<std::string>> documents = { |
| 120 | {"the", "cat", "sat"}, |
| 121 | {"the", "dog", "sat"}, |
| 122 | {"the", "cat", "ran"} |
| 123 | }; |
| 124 | std::vector<sparse_type> counts; |
| 125 | for (const auto& document : documents) |
| 126 | counts.push_back(hash_word_ngrams(document, 1, 1, 1 << 20)); |
| 127 | |
| 128 | tfidf_transformer<sparse_type> tfidf; |
| 129 | tfidf.train(counts); |
| 130 | DLIB_TEST(tfidf.vocabulary_size() == 5); |
| 131 | DLIB_TEST(std::abs(length(tfidf(counts[0])) - 1) < 1e-12); |
| 132 | } |
| 133 | |
| 134 | // ---------------------------------------------------------------------------------------- |
| 135 |
no test coverage detected