Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cos_similarity should return Symmetric matrix #283

Open
prbzrg opened this issue Jun 19, 2024 · 1 comment
Open

cos_similarity should return Symmetric matrix #283

prbzrg opened this issue Jun 19, 2024 · 1 comment

Comments

@prbzrg
Copy link
Contributor

prbzrg commented Jun 19, 2024

No description provided.

@rssdev10
Copy link
Collaborator

Hi, there is no way to change the return value produced by this function without breaking comparability. But it is possible to create another one. https://github.com/JuliaText/TextAnalysis.jl/blob/master/src/tf_idf.jl#L329

At the same time, it would be good to check what the performance difference will be if you want to change this implementation for symmetric. Also, what will happen to the number of memory allocations and total memory used.

function cos_similarity(tfm::AbstractMatrix)
    cs = tfm * tfm'
    d = sqrt.(diag(cs))
    # prevent division by zero  (only occurs for empty documents)
    d[findall(iszero, d)] .= 1
    cs ./ (d * d')
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants