def _set_graph_edge_weights(graph): """Sets weights using BM25 algorithm. Leaves small weights as zeroes. If all weights are fairly small, forces all weights to 1, inplace. Parameters ---------- graph : :class:`~gensim.summarization.graph.Graph` Given graph. """ documents = graph.nodes() weights = _bm25_weights(documents) for i in xrange(len(documents)): for j in xrange(len(documents)): if i == j or weights[i][j] < WEIGHT_THRESHOLD: continue sentence_1 = documents[i] sentence_2 = documents[j] edge_1 = (sentence_1, sentence_2) edge_2 = (sentence_2, sentence_1) if not graph.has_edge(edge_1): graph.add_edge(edge_1, weights[i][j]) if not graph.has_edge(edge_2): graph.add_edge(edge_2, weights[j][i]) # Handles the case in which all similarities are zero. # The resultant summary will consist of random sentences. if all(graph.edge_weight(edge) == 0 for edge in graph.edges()): _create_valid_graph(graph)
def _set_graph_edge_weights(graph): """Sets weights using BM25 algorithm. Leaves small weights as zeroes. If all weights are fairly small, forces all weights to 1, inplace. Parameters ---------- graph : :class:`~gensim.summarization.graph.Graph` Given graph. """ documents = graph.nodes() weights = _bm25_weights(documents) for i, doc_bow in enumerate(weights): if i % 1000 == 0 and i > 0: logger.info('PROGRESS: processing %s/%s doc (%s non zero elements)', i, len(documents), len(doc_bow)) for j, weight in doc_bow: if i == j or weight < WEIGHT_THRESHOLD: continue edge = (documents[i], documents[j]) if not graph.has_edge(edge): graph.add_edge(edge, weight) # Handles the case in which all similarities are zero. # The resultant summary will consist of random sentences. if all(graph.edge_weight(edge) == 0 for edge in graph.iter_edges()): _create_valid_graph(graph)
def _set_graph_edge_weights(graph): """Sets weights using BM25 algorithm. Leaves small weights as zeroes. If all weights are fairly small, forces all weights to 1, inplace. Parameters ---------- graph : :class:`~gensim.summarization.graph.Graph` Given graph. """ documents = graph.nodes() weights = _bm25_weights(documents) for i, doc_bow in enumerate(weights): if i % 1000 == 0 and i > 0: logger.info( 'PROGRESS: processing %s/%s doc (%s non zero elements)', i, len(documents), len(doc_bow)) for j, weight in doc_bow: if i == j or weight < WEIGHT_THRESHOLD: continue edge = (documents[i], documents[j]) if not graph.has_edge(edge): graph.add_edge(edge, weight) # Handles the case in which all similarities are zero. # The resultant summary will consist of random sentences. if all(graph.edge_weight(edge) == 0 for edge in graph.iter_edges()): _create_valid_graph(graph)
def _set_graph_edge_weights(graph): documents = graph.nodes() weights = _bm25_weights(documents) for i in xrange(len(documents)): for j in xrange(len(documents)): if i == j or weights[i][j] < WEIGHT_THRESHOLD: continue sentence_1 = documents[i] sentence_2 = documents[j] edge_1 = (sentence_1, sentence_2) edge_2 = (sentence_2, sentence_1) if not graph.has_edge(edge_1): graph.add_edge(edge_1, weights[i][j]) if not graph.has_edge(edge_2): graph.add_edge(edge_2, weights[j][i]) # Handles the case in which all similarities are zero. # The resultant summary will consist of random sentences. if all(graph.edge_weight(edge) == 0 for edge in graph.edges()): _create_valid_graph(graph)
def _set_graph_edge_weights(graph): documents = graph.nodes() weights = _bm25_weights(documents) for i in xrange(len(documents)): for j in xrange(len(documents)): if i == j: continue sentence_1 = documents[i] sentence_2 = documents[j] edge_1 = (sentence_1, sentence_2) edge_2 = (sentence_2, sentence_1) if not graph.has_edge(edge_1): graph.add_edge(edge_1, weights[i][j]) if not graph.has_edge(edge_2): graph.add_edge(edge_2, weights[j][i]) # Handles the case in which all similarities are zero. # The resultant summary will consist of random sentences. if all(graph.edge_weight(edge) == 0 for edge in graph.edges()): _create_valid_graph(graph)