from sklearn.mixture import GaussianMixture import pickle def build_gmm_clusters(embeddings, n_clusters=12): gmm = GaussianMixture( n_components=n_clusters, covariance_type="full", random_state=42 ) gmm.fit(embeddings) cluster_probs = gmm.predict_proba(embeddings) return gmm, cluster_probs def save_gmm_model(gmm, path="models/gmm_model.pkl"): with open(path, "wb") as f: pickle.dump(gmm, f) def load_gmm_model(path="models/gmm_model.pkl"): with open(path, "rb") as f: return pickle.load(f)