machine-learning - 在 GPU 中计算余弦相似度的最快方法

所以我有一个包含超过一百万条记录的巨大 tfidf 矩阵,我想找到这个矩阵与其自身的余弦相似度。我正在使用 colab 来运行代码,但我不确定如何最好地利用 colab 提供的 gpu。

顺序运行代码 -

tfidf_matrix = tf.fit_transform(df['categories'])

cosine_similarities = linear_kernel(matrix, matrix)

有没有办法使用 jit 或任何其他方式并行化代码?

最佳答案

  1. 尝试使用 sentence transformers 库中的示例中的简单 torch 代码:https://github.com/UKPLab/sentence-transformers/blob/master/sentence_transformers/util.py#L31 或者只导入函数。

  2. 考虑使用 CUDA 加速的 cuml 库 https://docs.rapids.ai/api/cuml/nightly/api.html

https://stackoverflow.com/questions/62317399/

相关文章:

python - 位置破折号引导导航栏

laravel-5 - 解决facade root has not been set

python - Pandas 仅与列中的非空值合并并保留具有空值的值

jquery - 具有 intellisense 支持 Web 的文本编辑器,如 Avalon Ed

sql - hive 中的 with (nolock) 相当于 sql (nolock)

python - 如何使用基于 Web 应用程序的身份验证在 Python Django 中使用 M

r - unnest_longer 给出美元符号而不是正常的 tibble

angular - 单元测试 FormGroup 无法读取未定义的 Prop 值

image - 来自 Markdown 元数据或 frontmatter 的 NextJs 图像

graphql - Apollo GraphQL 中的命令式是什么意思?