def addNodeandEdge(self, a, b, nextLayer, model): score = 0 if self.p.__len__() > 0 and (self.p[-1] == ' ' or self.q[-1] == ' '): ascore = 0 bscore = 0 if self.p[-1] == ' ': ascore = model.score(a, context=tokenlize(' ')) else: ascore = model.score(a, context=tokenlize(self.p)) if self.q[-1] == ' ': bscore = model.score(b, context=tokenlize(' ')) else: bscore = model.score(b, context=tokenlize(self.q)) score = log_base2(ascore * bscore) else: score = log_base2( model.score(a, context=tokenlize(self.p)) * model.score(b, context=tokenlize(self.q))) # print(self.p + a + "," + self.q + b + ": " + str(score)) if score > POSSIBLE_BRANCH_THRESHOLD or (self.p.__len__() < 3 and score > -20): print(self.p + a + "," + self.q + b + ": " + str(score)) newNode = Node(self.p + a, self.q + b) newEdge = Edge(a, b, self, newNode, score) newNode.inEdge.append(newEdge) newNode.sumWeight = newEdge.prevNode.sumWeight + score self.possibleEdges.add(newEdge) nextLayer.nodeList.add(newNode)
def logscore(self, word, context=None): """Evaluate the log score of this word in this context. The arguments are the same as for `score` and `unmasked_score`. """ return log_base2(self.score(word, context))
def logscore(self, word, context=None): """Evaluate the log score of this word in this context. The arguments are the same as for `score` and `unmasked_score`. """ return log_base2(self.score(word, context))