当前位置: 首页>>代码示例>>Python>>正文


Python Constants.get_indices方法代码示例

本文整理汇总了Python中constants.Constants.get_indices方法的典型用法代码示例。如果您正苦于以下问题:Python Constants.get_indices方法的具体用法?Python Constants.get_indices怎么用?Python Constants.get_indices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在constants.Constants的用法示例。


在下文中一共展示了Constants.get_indices方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from constants import Constants [as 别名]
# 或者: from constants.Constants import get_indices [as 别名]

#.........这里部分代码省略.........
                        [[coder[self.tri,  self.left, s, t]]],
                        labels= label_indices)


                label_indices = self.compute_label_indices(self.tri,
                                     self.right, s, t)

                chart.set_t(coder[self.tri,  self.right, s, t],
                        coder[self.trap, self.right, s,  s+1:t+1],
                        coder[self.tri_stop,  self.right, s+1:t+1, t])
            
                if s!=0 or (s==0 and t==n-1):
                    label_indices = self.compute_label_indices(self.tri_stop,
                                     self.right, s, t)

                    chart.set(coder[self.tri_stop, self.right,  s, t],
                        [[coder[self.tri,  self.right, s, t]]],
                        labels=label_indices)

        self.graph = chart.finish()
        return self.graph

    def compute_weights(self, label_scores):
        if self.weights == None:
            self.weights = pydecode.transform(self.graph, label_scores)
        return self.weights

    def reset_values(self):
        self.weights = None
            
    def compute_marginals(self, label_scores):
        self.compute_weights(label_scores)
        edge_marginals = pydecode.marginals(self.graph, self.weights)
        return edge_marginals

    def best_path(self, label_scores):
        self.compute_weights(label_scores)
        return pydecode.best_path(self.graph, self.weights)

    def best_edges(self, label_scores):
        path = self.best_path(label_scores)
        best_edges = path.edges
        heads = np.array([], dtype=np.int64)

        for edge in best_edges:
            heads = np.append(heads, edge.head.label)

        shapes, direction, head, modifier = self.get_indices_of_heads(heads,
                                                          len(self.sentence))

        print "shapes"
        pprint.pprint(shapes)

        print "direct"
        pprint.pprint(direction)

        print "head"
        pprint.pprint(head)

        print "mod"
        pprint.pprint(modifier)


        right_indices = np.where(direction == 0)
        left_indices = np.where(direction == 1)

        depen = np.full(len(self.sentence), -1, dtype=np.int64)
        depen[modifier[right_indices].tolist()] = head[right_indices].tolist()
        depen[head[left_indices].tolist()] = modifier[left_indices].tolist()
        return depen

    def get_indices_of_heads(self, heads, n):
        shapes, direction, row, column = self.constants.get_indices(heads, n)
        indices_needed = np.where(shapes == 1)
        return shapes[indices_needed], direction[indices_needed], row[indices_needed], column[indices_needed]

    def compute_label_indices(self, shape, direction, head, mod):
        indices = np.tile([shape, direction, 0, head, mod], abs(head-mod)).\
            reshape(abs(head-mod), 5)
        indices[:,2] = self.compute_adj(head, mod)
        if(indices.shape[0] == 1):
            return np.array([self.out[indices[0,0], indices[0,1], indices[0,2],
                                      indices[0, 3], indices[0, 4]]])
        return self.out[indices[:,0].tolist(),indices[:,1].tolist(),
              indices[:,2].tolist(), indices[:,3].tolist(), indices[:,4].tolist()]

    def compute_adj(self, head, mod):
        if(head > mod):
            split  =  np.arange(mod, head)
        else:
            split = np.arange(head, mod)

        vfunc = np.vectorize(self.is_adj)
        return vfunc(head, split)

    def is_adj(self, head,  split):
        if abs(head - split) <=1:
            return self.adj
        else:
            return self.non_adj
开发者ID:tejaswini,项目名称:parsing,代码行数:104,代码来源:eisner_algo.py


注:本文中的constants.Constants.get_indices方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。