) reduction = Umap(2, n_neighbors=n_neighbors, min_dist=min_dist) else: reduction = Pca(2) st.markdown("# Simple Text Clustering") st.markdown( "Let's say you've gotten a lot of feedback from clients on different channels. You might like to be able to distill main topics and get an overview. It might even inspire some intents that will be used in a virtual assistant!" ) st.markdown( "This tool will help you discover them. This app will attempt to cluster whatever text you give it. The chart will try to clump text together and you can explore underlying patterns." ) if method == "CountVector SVD": lang = CountVectorLanguage(n_svd, ngram_range=(min_ngram, max_ngram)) embset = lang[texts] if method == "Lite Sentence Encoding": embset = EmbeddingSet(*[ Embedding(t, v) for t, v in zip( texts, calculate_embeddings(texts, encodings=encodings)) ]) p = (embset.transform(reduction).plot_interactive(annot=False).properties( width=500, height=500, title="")) st.write(p) st.markdown( "While the tool helps you in discovering clusters, it doesn't do labelling (yet). We do offer a [jupyter notebook](https://github.com/RasaHQ/rasalit/tree/master/notebooks/bulk-labelling) that might help out though." )
st.markdown("# Simple Text Clustering") st.markdown( "Let's say you've gotten a lot of feedback from clients on different channels. You might like to be able to distill main topics and get an overview. It might even inspire some intents that will be used in a virtual assistant!" ) st.markdown( "This tool will help you discover them. This app will attempt to cluster whatever text you give it. The chart will try to clump text together and you can explore underlying patterns." ) if method == "CountVector SVD": lang = CountVectorLanguage(n_svd, ngram_range=(min_ngram, max_ngram)) embset = lang[texts] if method == "Lite Sentence Encoding": embset = EmbeddingSet( *[ Embedding(t, v) for t, v in zip(texts, calculate_embeddings(texts, encodings=encodings)) ] ) p = ( embset.transform(reduction) .plot_interactive(annot=False) .properties(width=500, height=500, title="") ) st.write(p) st.markdown( "While the tool helps you in discovering clusters, it doesn't do labelling (yet). We do offer a [jupyter notebook](https://github.com/RasaHQ/rasalit/tree/master/notebooks/bulk-labelling) that might help out though." )
def test_embset_creation_error(): foo = Embedding("foo", [0, 1]) # This vector has a different dimension. No bueno. bar = Embedding("bar", [1, 1, 2]) with pytest.raises(ValueError): EmbeddingSet(foo, bar)
def test_embset_creation_warning(): foo = Embedding("foo", [0, 1]) # This vector has the same name dimension. Dangerzone. bar = Embedding("foo", [1, 2]) with pytest.raises(Warning): EmbeddingSet(foo, bar)
def __getitem__(self, query): if isinstance(query, str): return Embedding(query, vector=self.model.encode(query)) else: return EmbeddingSet(*[self[tok] for tok in query])
def test_add_property(): foo = Embedding("foo", [0.1, 0.3, 0.10]) bar = Embedding("bar", [0.7, 0.2, 0.11]) emb = EmbeddingSet(foo, bar) emb_with_property = emb.add_property("prop_a", lambda d: "prop-one") assert all([e.prop_a == "prop-one" for e in emb_with_property])
def test_emb_ndim(): foo = Embedding("foo", [0, 1, 0.2]) assert foo.ndim == 3
def embset(): names = ["red", "blue", "green", "yellow", "white"] vectors = np.random.rand(5, 3) embeddings = [Embedding(name, vector) for name, vector in zip(names, vectors)] return EmbeddingSet(*embeddings)
def emb(): x = Embedding("x", [0.0, 1.0]) y = Embedding("y", [1.0, 0.0]) z = Embedding("z", [0.5, 0.5]) return EmbeddingSet(x, y, z)
def test_emb_plot_no_err_3d(): x = Embedding("x", [0.0, 1.0, 1.0]) y = Embedding("y", [1.0, 0.0, 1.0]) z = Embedding("z", [0.5, 0.5, 1.0]) for item in [x, y, z]: item.plot("scatter", x_axis=x, y_axis=y)
def test_negation(): foo = Embedding("foo", [0.1, 0.3]) assert np.allclose((-foo).vector, -np.array([0.1, 0.3]))
def test_assign_arrays_raise_error(): foo = Embedding("foo", [0.1, 0.3, 0.10]) bar = Embedding("bar", [0.7, 0.2, 0.11]) emb = EmbeddingSet(foo, bar) with pytest.raises(ValueError): emb.assign(prop_a=["a", "b"], prop_b=np.array([1, 2, 3]))
def test_reverse_strings(): embset = EmbeddingSet(Embedding(name="helloworld", vector=[1, 2])).pipe(reverse_strings) emb = [e for e in embset][0] assert emb.name == "dlrowolleh"