BERT句子嵌入的k均值

时间:2019-08-27 09:25:16

标签: python tensorflow pytorch k-means embedding

我正在尝试对从预训练的BERT模型获得的张量(句子嵌入)进行k均值聚类。

from sklearn.cluster import KMeans

embedding = BERTembeddingGenerator.generateSentenceEmbedding(sentence)
embeddingMapping[embedding] = sentence
sentenceEmbeddingsList = list(embeddingMapping.keys())
model = KMeans(n_clusters=10, init='k-means++', max_iter=100, n_init=1)
labels = model.fit_predict(sentenceEmbeddingsList)

这会引发错误

ValueError: only one element tensors can be converted to Python scalars

句子嵌入的大小为768

我试图将张量转换为numpy数组。任何有关我弄错地方的指针

0 个答案:

没有答案