public static void saveTopWords(List<Datum> train, String fileName, int topK) throws FileNotFoundException, IOException{
		Map<Integer, Integer> wordCount = new HashMap<Integer, Integer>();	
		for(Datum d : train){
			int index = getIndex(d.word);
			if(wordCount.containsKey(index)){
				wordCount.put(index, wordCount.get(index) + 1);
			} else {
				wordCount.put(index, 1);
			}
		}
		
		// http://stackoverflow.com/questions/109383/how-to-sort-a-mapkey-value-on-the-values-in-java
		ValueComparator bvc =  new ValueComparator(wordCount);
		TreeMap<Integer, Integer> sorted_map = new TreeMap<Integer, Integer>(bvc);
		sorted_map.putAll(wordCount);
		
		File f = new File(fileName);
		BufferedWriter bw = null;
		bw = new BufferedWriter(new FileWriter(f));
		int c = 1;
		for(Integer s : sorted_map.keySet()){
			if(c>topK) break;
			if(!wordCount.containsKey(s))
				System.out.println(s);
			System.out.println(numToWord.get(s));
			bw.append(s + "\n");
			c++;
		}
		bw.close();
	}