Reductio icon indicating copy to clipboard operation
Reductio copied to clipboard

Reductio tends to freeze app when summarizing long articles

Open tetron432 opened this issue 5 years ago • 1 comments

The library works fine unless its trying to summarize very long articles, such as this: https://www.popsci.com/can-ai-destroy-humanity?utm_source=pocket-newtab

tetron432 avatar May 27 '19 11:05 tetron432

I don't know if is still a concern, but I had some difficulties with some peculiar texts as well. I think I pinpointed it to this part

let score: Float = links.reduce(0.0) { $0 + nodes[$1] / outlinks[$1] * weights[$1, node] }

in iteration within TextRank, which in my case yielded NaN for some parts, I am guessing due to outlinks[$1] and/or weights[$1, node] being 0 (did not debug that deep yet).

My current workaround is to check for NaN and in case replace the score with 0, i.e.

    private func iteration(_ nodes: Node) -> Node {
        var vertex = Node()
        for (node, links) in graph {
            let score: Float = links.reduce(0.0) { $0 + nodes[$1] / outlinks[$1] * weights[$1, node] }
            if score.isNaN {
                vertex[node] = (1-damping/nodes.count) + damping * 0.0
            } else {
                vertex[node] = (1-damping/nodes.count) + damping * score
            }
        }
        return vertex
    }

It is not the most elegant solution but for the time being it seems to do the trick during some initial testing. If it proves to be working in other cases as well, I could submit a pull request. Perhaps it helps with the other related issues as well.

philip-iii avatar Nov 09 '20 21:11 philip-iii