diff --git a/main/src/main/scala/org/clulab/dynet/Eisner.scala b/main/src/main/scala/org/clulab/dynet/Eisner.scala index af3740688..fbf48bf7d 100644 --- a/main/src/main/scala/org/clulab/dynet/Eisner.scala +++ b/main/src/main/scala/org/clulab/dynet/Eisner.scala @@ -245,7 +245,8 @@ class Eisner { val relativeHead = scores(i).maxBy(_._2)._1.toInt val depMod = i + 1 val depHead = if (relativeHead == 0) 0 else depMod + relativeHead - val valid = dependencies(depMod).indices.contains(depHead) && dependencies(depMod)(depHead) != null + // lift() checks the index, and Option(_) checks for nulls. + val valid = dependencies(depMod).lift(depHead).flatMap(Option(_)).isDefined val label = if (valid) dependencies(depMod)(depHead).label else "root" val head = if(generateRelativeHeads) {