I've serialized a CRF Model using CRFClassifier based on a custom dataset. I can access to the model using the below code.
CRFClassifier<CoreLabel> crfClassifier = CRFClassifier.getClassifierNoExceptions("crf_ner_model.ser.gz");
I also have a set of Regex Mappings (Java Regular expressions and corresponding labels) using which I instantiate an instance of RegexNERSequenceClassifier
RegexNERSequenceClassifier regexNERSequenceClassifier = new RegexNERSequenceClassifier(mappingPath, true, true, null);
I am able to individually call the classify()
for both of these classifiers and they successfully annotate the test data-set.
Example:
List<CoreLabel> testData = new ArrayList<CoreLabel>();
// assume testData is initialized with values.
List<CoreLabel> crfOutput = crfClassifier.classify(testData);
List<CoreLabel> regexOutput = regexNERSequenceClassifier.classify(testData);
Sample Output using above code:
Input Test Data: 72" x 60" wooden bed
crfOutput:
72" (label: O)
,x (label: O)
,60" (label: O)
,wooden (label: material)
,bed (label: category)
(label: O)
is the background symbolregexOutput:
72" (label: UNIT_OF_LENGTH)
,x
,60" (label: UNIT_OF_LENGTH)
,wooden
,bed
However when I try to combine them, such that a test document is first classified by CRF and then by RegexNER, it doesn't work (RegexNER doesn't tag anything even though there are tokens matching the regex, only the CRF tags are visible). Example:
List<CoreLabel> crfOutput = crfClassifier.classify(testData);
// send crfOutput as input to RegexNER
List<CoreLabel> regexOutput = regexNERSequenceClassifier.classify(crfOutput);
How do I combine the two classifiers. I tried using NERClassifierCombiner.java (as described here: Stanford NER: Can I use two classifiers at once in my code?) but that doesn't work either.