-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi-model support #692
Multi-model support #692
Conversation
…tatic singleton rather they are stored in the annotator (which is a singleton per model via the factory for NER annotators). In this way, we can have multiple NER models for different languages in the same process space.
@cowchipkid not that I know of. Unless it's necessary, please don't. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, looks really good.
I've marked a couple of catch blocks that simply print an error, but don't otherwise interfere with program execution. I think failure to load a resource should result in an exception: if the client wants to ignore it, then they should do so consciously. It is generally undesirable to run without realizing some resource is not available.
@@ -153,15 +156,13 @@ else if (mode.contains("ALL")){ | |||
bcsl.add(false); | |||
bcsl.add(false); | |||
bcsl.add(false); | |||
BrownClusters.init(bcs, bcst, bcsl, false); | |||
brownClusters = BrownClusters.get(bcs, bcst, bcsl); | |||
WordNetManager.loadConfigAsClasspathResource(true); | |||
wordNet = WordNetManager.getInstance(); | |||
} | |||
catch (Exception e){ | |||
e.printStackTrace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please throw an exception here unless there is a recovery option based on a reported failure.
@@ -155,15 +158,14 @@ private void annotateTas(){ | |||
bcsl.add(false); | |||
bcsl.add(false); | |||
bcsl.add(false); | |||
BrownClusters.init(bcs, bcst, bcsl, false); | |||
brownClusters = BrownClusters.get(bcs, bcst, bcsl); | |||
WordNetManager.loadConfigAsClasspathResource(true); | |||
wordNet = WordNetManager.getInstance(); | |||
} | |||
catch (Exception e){ | |||
e.printStackTrace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw exception
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree completely, however, this is not my code, it's nothing that I have changed, it has been this way. I can throw the exceptions up, but the exception apparently end up being thrown in the reader generation code inside the LBJava stuff, and again, I don't even know what this code does. So I can make the change, I can throw the exception up to the reader, but I can't change the getReader method signature of the LBJ generated code, or at least I shouldn't. I propose we throw the exceptions, but in the constructor for this reader, catch the thrown exceptions, convert them to a runtime exception and throw that so we don't have to change the get reader method. And the author should be made aware that this sort of absence of thought about error handling is wrong minded and unacceptable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize this is not your coding practice, just saw it in the context of your changes. I think your proposal is good. If you think it will take too much time right now, you can skip making the change, but open an issue that describes them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have made the change, and from just a cursor glance, I think it will work out just fine.
@@ -135,14 +138,11 @@ public String getId(){ | |||
bcsl.add(false); | |||
bcsl.add(false); | |||
bcsl.add(false); | |||
BrownClusters.init(bcs, bcst, bcsl, false); | |||
|
|||
brownClusters = BrownClusters.get(bcs, bcst, bcsl); | |||
} | |||
catch (Exception e){ | |||
e.printStackTrace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw exception
@@ -227,13 +230,11 @@ public static void testExtentOnGoldHead(){ | |||
bcsl.add(false); | |||
bcsl.add(false); | |||
bcsl.add(false); | |||
BrownClusters.init(bcs, bcst, bcsl, false); | |||
brownClusters = BrownClusters.get(bcs, bcst, bcsl); | |||
} | |||
catch (Exception e){ | |||
e.printStackTrace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw exception
@@ -306,13 +309,11 @@ public static void testExtentOnPredictedHead(){ | |||
bcsl.add(false); | |||
bcsl.add(false); | |||
bcsl.add(false); | |||
BrownClusters.init(bcs, bcst, bcsl, false); | |||
brownClusters = BrownClusters.get(bcs, bcst, bcsl); | |||
} | |||
catch (Exception e){ | |||
e.printStackTrace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw exception
@@ -181,8 +181,7 @@ else if (_mode.contains("ERE")){ | |||
bcsl.add(false); | |||
bcsl.add(false); | |||
bcsl.add(false); | |||
BrownClusters.init(bcs, bcst, bcsl, false); | |||
brownClusters = BrownClusters.get(); | |||
brownClusters = BrownClusters.get(bcs, bcst, bcsl); | |||
WordNetManager.loadConfigAsClasspathResource(true); | |||
wordNet = WordNetManager.getInstance(); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw exception in following catch block
@@ -25,7 +25,6 @@ | |||
HashSet<String> labelsToAnonymizeForEvaluation = new HashSet<>(); | |||
|
|||
private Data(Data other) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's OK to leave (or update) the original comment to make it immediately clear to any other dev why this is specified.
|
||
// NOTICE: this only checks tagger1 because tagger2 may legally be null. | ||
if (tagger1 == null) { | ||
if (params.taggerLevel1 == null) { | ||
logger.error("Tagger1 is null. You may need to call NETagPlain.init() first."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it correct to return null here rather than throwing an exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, but as the above, it has always been this way. I personally don't use this method any more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Fine to leave as is, then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides Mark's comments, looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for adding the exception handling.
This version eliminates the reliance on static singletons for configuration parameters, models, brown clusters and gazetteers for NER.