-
Notifications
You must be signed in to change notification settings - Fork 1
MNN_example_EN
In Patent Example, we saw how to train and test a hierarchical classification.
In the illustration below, we see that there are many possibilities for classifying a document. You can directly request the classification at the finest level or ask the classification at an intermediate level, guide the choice and continue from this level. One can even ask for a classification at each level.
For our example on the Wipo's alpha collection, we must build:
- from the root: 4 classifiers
- from the section level: 8 * 3 classifier for all following levels
- from class level: 114 * 2 classifier for all following levels
- from the subclass level: 451 classifier for the next level
We must build 707 classifiers to cover all cases.
The program to use for training and testing is BuildMNN
.
The set of parameters is described in Parameters to build the hierarchy of classifiers
By convention, structures are in the data
folder. The myfirst
project contains a mnn
folder which will contain the result of the calculations.
Let's run the program.
The log records the construction of all NNs. The end of the log should look like this
recording NN: 7.C09G @706
START [2018/06/20 13:31:52] : compress MNN file
............
STOP [2018/06/20 13:32:48]: compress MNN file - 55481 ms
end of NNmany save
#NN:707#NN-cat:8977
STOP [2018/06/20 13:32:49]: global time -------------------------------- - 134115 ms
BUILD SUCCESSFUL (total time: 2 minutes 25 seconds)
It shows the recording of the last NN (7.C09G @ 706
), the compression of the NN.
A summary of the resources used #NN: 707 # NN-cat: 8977
is 707 NN and a total of 8977 classes.
the mnn
folder contains the following files
-
alpha.mnn
(37M): the file giving all information on all the NN of the hierarachie. -
alpha.cmnn
(43M): the compressed file of all NNs. -
alpha.rmnn
511M): the intermediate work file to build all the NNs.
The .rmnn file is quite large. Its size is the product of the number of features by the total classes of the HNN. But after compression, it can be deleted.
We will see an application that uses the HNN.
For that we use a classify class which allows to use the hierarchy of NN. Initialization requests access to the index to identify terms with the same numbers and to open the HNN. The .mnn product file is used. It is imperative to indicate the same maximum class number. The last three settings allow you to set the cache.
public static void init() { // init class
if (id == null) {
System.out.println("-------- init indexer and HNN");
id = new IdxStructure("QUERY", new ConfigurationForCat());
id.Statistic.global();
MM = new Categorizer(nnfile,
false, // load all in memory
10000, // maxclass
2000, // cache size
16, // start level
4 // free cache
);
}
The classification process is broken down into:
- Initialize the HNN.
- Parser the document to classify (build the BOW of the document)
- Classify the document.
The method we will use is advise (text, startWith, levelOfClassification)
.
public static String advise(String p, String starWith, String level) {
init();
ClassifierRequest rq = parse(p, "3", "EN");
return guessSimple(rq, starWith, level);
}
The test program is as follows:
public class ApplicationText2Class {
public static void main(String[] args) {
msg("init clssifier ...");
Classify.init();
String patentAbstract="The invention is a suspension for motor vehicles and the like which adjustably controls the wheel height of the vehicle relative to the chassis during turns. Sensors convert vehicle turn angle and velocity information into electrical signals for initiating pressure changes in selected expansible springs for adjustably offsetting the centrifugal force occurring during turns.\n";
// from root
System.out.println("from root to section"+Classify.advise(patentAbstract, "", "1")); // to section
System.out.println("from root to class"+Classify.advise(patentAbstract, "", "3")); // to class
System.out.println("from root to subclass"+Classify.advise(patentAbstract, "", "4")); // to subclass
System.out.println("from root to maingroup"+Classify.advise(patentAbstract, "", "7")); // to maingroup
// from section
System.out.println("from section to class"+Classify.advise(patentAbstract, "B", "3")); // to class
System.out.println("from section to subclass"+Classify.advise(patentAbstract, "B", "4")); // to subclass
System.out.println("from section to maingroup"+Classify.advise(patentAbstract, "B", "7")); // to maingroup
// from class
System.out.println("from class to subclass"+Classify.advise(patentAbstract, "B60", "4")); // to subclass
System.out.println("from class to maingroup"+Classify.advise(patentAbstract, "B60", "7")); // to maingroup
// from subclass
System.out.println("from subclass to maingroup"+Classify.advise(patentAbstract, "B60G", "7")); // to maingroup
msg("end ...");
}
}
The expected classification for the document is B60G17 / 0162
. We see that we have tested all the possibilities of classification.
By executing the program we obtain the following results:
Each test shows three predictions. For each prediction, we have the symbol of the class and the score associated with the class. Above 1000 is considered statistically as a good score. The score can be associated with the confidence in the prediction.
from root to section choice:1 B 1298 choice:2 G 651 choice:3 A 579
from root to class choice:1 B60 1429 choice:2 G01 802 choice:3 B62 701
from root to subclass choice:1 B60G 873 choice:2 B60R 785 choice:3 B62D 779
from root to maingroup choice:1 B60G011 723 choice:2 B60G017 712 choice:3 G05D001 688
from section to class choice:1 B60 1531 choice:2 B62 779 choice:3 B04 727
from section to subclass choice:1 B60R 813 choice:2 B60G 803 choice:3 B62D 790
from section to maingroup choice:1 B60G003 713 choice:2 B60G011 707 choice:3 B60G017 704
from class to subclass choice:1 B60G 1233 choice:2 B60R 643 choice:3 B60S 580
from class to maingroup choice:1 B60G017 730 choice:2 B60G011 666 choice:3 B60G003 627
from subclass to maingroup choice:1 B60G017 945 choice:2 B60G003 804 choice:3 B60G007 774
We see that it is easy to transform this application to give it a user interface.
We saw:
- The notion of Hierarchy of Neuron Networks (HNN)
- How to build and store the HNN
- How to write a program that exploits the HNN
In the following example, we will go back to language detection and develop a REST WS WS REST.
.