Skip to content

Commit

Permalink
review delft model loading when archtecture is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
kermitt2 committed Oct 18, 2020
1 parent 9598ab3 commit 475d6b5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
Expand Up @@ -48,15 +48,6 @@ public static synchronized GenericTagger getTagger(GrobidModel model, GrobidCRFE
t = new WapitiTagger(model);
break;
case DELFT:
// be sure the native JEP lib can be loaded
// try {
// String libraryFolder = LibraryLoader.getLibraryFolder();
// System.out.println(libraryFolder);
// LibraryLoader.addLibraryPath(libraryFolder);
// } catch (Exception e) {
// LOGGER.info("Loading JEP native library for DeLFT failed", e);
// }

t = new DeLFTTagger(model, architecture);
break;
default:
Expand Down
19 changes: 12 additions & 7 deletions grobid-core/src/main/java/org/grobid/core/jni/DeLFTModel.java
Expand Up @@ -32,7 +32,7 @@ public class DeLFTModel {
public DeLFTModel(GrobidModel model, String architecture) {
this.modelName = model.getModelName().replace("-", "_");
try {
LOGGER.info("Loading DeLFT model for " + model.getModelName() + "...");
LOGGER.info("Loading DeLFT model for " + model.getModelName() + " with architecture " + architecture + "...");
JEPThreadPool.getInstance().run(new InitModel(this.modelName, GrobidProperties.getInstance().getModelPath(), architecture));
} catch(InterruptedException e) {
LOGGER.error("DeLFT model " + this.modelName + " initialization failed", e);
Expand All @@ -54,10 +54,15 @@ public InitModel(String modelName, File modelPath, String architecture) {
public void run() {
Jep jep = JEPThreadPool.getInstance().getJEPInstance();
try {
if (this.architecture == null)
jep.eval(this.modelName+" = Sequence('" + this.modelName.replace("_", "-") + "')");
else
jep.eval(this.modelName+" = Sequence('" + this.modelName.replace("_", "-") + "', model_type='" + this.architecture + "')");
String fullModelName = this.modelName.replace("_", "-");

if (architecture != null && !architecture.equals("BidLSTM_CRF"))
fullModelName += "-" + this.architecture;

if (GrobidProperties.getInstance().useELMo() && modelName.toLowerCase().indexOf("bert") == -1)
fullModelName += "-with_ELMo";

jep.eval(this.modelName+" = Sequence('" + fullModelName + "')");
jep.eval(this.modelName+".load(dir_path='"+modelPath.getAbsolutePath()+"')");
} catch(JepException e) {
throw new GrobidException("DeLFT model initialization failed. ", e);
Expand Down Expand Up @@ -211,7 +216,7 @@ public void run() {
jep.eval("print(len(x_valid), 'validation sequences')");

String useELMo = "False";
if (GrobidProperties.getInstance().useELMo()) {
if (GrobidProperties.getInstance().useELMo() && modelName.toLowerCase().indexOf("bert") == -1) {
useELMo = "True";
}

Expand Down Expand Up @@ -266,7 +271,7 @@ public static void train(String modelName, File trainingData, File outputModel,
command.add("--architecture");
command.add(architecture);
}
if (GrobidProperties.getInstance().useELMo()) {
if (GrobidProperties.getInstance().useELMo() && modelName.toLowerCase().indexOf("bert") == -1) {
command.add("--use-ELMo");
}

Expand Down
6 changes: 3 additions & 3 deletions grobid-home/config/grobid.properties
Expand Up @@ -50,15 +50,15 @@ grobid.crf.engine.fulltext=wapiti
#grobid.crf.engine.figure=wapiti
#grobid.crf.engine.table=wapiti
#grobid.crf.engine.name_citation=wapiti
#grobid.crf.engine.affiliation_address=wapiti
#grobid.crf.engine.affiliation_address=delft
#grobid.crf.engine.citation=delft

grobid.delft.install=../delft
grobid.delft.useELMo=false
grobid.delft.python.virtualEnv=
grobid.delft.redirect.output=true
grobid.delft.architecture=bidLSTM_CRF
#grobid.delft.architecture=SciBERT
grobid.delft.architecture=BidLSTM_CRF
#grobid.delft.architecture=scibert

grobid.pdf.blocks.max=100000
grobid.pdf.tokens.max=1000000
Expand Down

0 comments on commit 475d6b5

Please sign in to comment.