(Corpus corpus)
| 156 | } |
| 157 | |
| 158 | public static void examineCorpus(Corpus corpus) { |
| 159 | ListMultimap<FeatureVectorAsObject, Integer> wsByFeatureVectorGroup = ArrayListMultimap.create(); |
| 160 | ListMultimap<FeatureVectorAsObject, Integer> hposByFeatureVectorGroup = ArrayListMultimap.create(); |
| 161 | int numContexts = corpus.featureVectors.size(); |
| 162 | for (int i = 0; i<numContexts; i++) { |
| 163 | int[] X = corpus.featureVectors.get(i); |
| 164 | int y1 = corpus.injectWhitespace.get(i); |
| 165 | int y2 = corpus.hpos.get(i); |
| 166 | wsByFeatureVectorGroup.put(new FeatureVectorAsObject(X, Trainer.FEATURES_INJECT_WS), y1); |
| 167 | hposByFeatureVectorGroup.put(new FeatureVectorAsObject(X, Trainer.FEATURES_HPOS), y2); |
| 168 | } |
| 169 | List<Double> wsEntropies = new ArrayList<>(); |
| 170 | List<Double> hposEntropies = new ArrayList<>(); |
| 171 | for (FeatureVectorAsObject x : wsByFeatureVectorGroup.keySet()) { |
| 172 | List<Integer> cats = wsByFeatureVectorGroup.get(x); |
| 173 | List<Integer> cats2 = hposByFeatureVectorGroup.get(x); |
| 174 | HashBag<Integer> wsCats = getCategoriesBag(cats); |
| 175 | HashBag<Integer> hposCats = getCategoriesBag(cats2); |
| 176 | double wsEntropy = getNormalizedCategoryEntropy(getCategoryRatios(wsCats.values())); |
| 177 | double hposEntropy = getNormalizedCategoryEntropy(getCategoryRatios(hposCats.values())); |
| 178 | wsEntropies.add(wsEntropy); |
| 179 | hposEntropies.add(hposEntropy); |
| 180 | System.out.printf("%130s : %s,%s %s,%s\n", x, |
| 181 | wsCats, wsEntropy, |
| 182 | hposCats, hposEntropy); |
| 183 | } |
| 184 | System.out.println("MEAN "+mean(wsEntropies)); |
| 185 | System.out.println("MEAN "+mean(hposEntropies)); |
| 186 | float contextRichness = wsEntropies.size()/(float) numContexts; // 0..1 where 1 means every token had different context |
| 187 | System.out.println("Context richness = "+contextRichness+ |
| 188 | " uniq ctxs="+wsEntropies.size()+", nctxs="+numContexts); |
| 189 | } |
| 190 | |
| 191 | /** Return diversity index, e^entropy. |
| 192 | * https://en.wikipedia.org/wiki/Diversity_index |
nothing calls this directly
no test coverage detected