package com.alg.qid.kmeans;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import com.alg.qid.word2vec.VectorModel;
public class Kmeans {
private int K;
static int vecsize=300;//向量长度
public static void main(String[] args) throws IOException{
if(args.length < 1){
System.err.println("parameter missing");
}
Kmeans kmclass = new Kmeans();
HashSet<String> title2word = new HashSet<String>();
int k=1000;
HashMap<String, float[]> title2vec = new HashMap<String, float[]>();
VectorModel vm = VectorModel.loadFromFile(args[1]);
System.out.println(vm.getVectorSize());
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(args[2]), "utf-8"));
PrintWriter pw = new PrintWriter(new OutputStreamWriter(
new FileOutputStream(args[2] + ".kmeans"), "utf-8"), true);
String line = null;
int count = 0;
while ((line = br.readLine()) != null){
count +=1;
System.out.println(count);
String[] words=line.split("\t");
if (!vm.getWordM
词向量的kmeans词聚类实现
最新推荐文章于 2024-08-16 15:57:51 发布
该博客介绍了如何使用Java实现K-means算法进行词向量的聚类。通过加载预训练的词向量模型,对输入的词汇进行处理,初始化聚类中心,迭代更新并找到新的聚类中心,最终实现词汇的自动分类。
摘要由CSDN通过智能技术生成