MCPcopy
hub / github.com/MaartenGr/BERTopic / check_embeddings_shape

Function check_embeddings_shape

bertopic/_utils.py:51–62  ·  view source on GitHub ↗

Check if the embeddings have the correct shape.

(embeddings, docs)

Source from the content-addressed store, hash-verified

49
50
51def check_embeddings_shape(embeddings, docs):
52 """Check if the embeddings have the correct shape."""
53 if embeddings is not None:
54 if not any([isinstance(embeddings, np.ndarray), isinstance(embeddings, csr_matrix)]):
55 raise ValueError("Make sure to input embeddings as a numpy array or scipy.sparse.csr.csr_matrix. ")
56 else:
57 if embeddings.shape[0] != len(docs):
58 raise ValueError(
59 "Make sure that the embeddings are a numpy array with shape: "
60 "(len(docs), vector_dim) where vector_dim is the dimensionality "
61 "of the vector embeddings. "
62 )
63
64
65def check_is_fitted(topic_model):

Callers 4

fit_transformMethod · 0.90
transformMethod · 0.90
partial_fitMethod · 0.90

Calls

no outgoing calls

Tested by 1