torcharrow.functional.get_cosine_similarity¶
- torcharrow.functional.get_cosine_similarity(input_ids: ListColumn, input_id_scores: ListColumn, matching_ids: ListColumn, matching_id_scores: ListColumn)¶
返回由 input_ids 定义的向量(由 input_id_scores 加权)与由 matching_ids 定义的向量(由 matching_id_scores 加权)之间的余弦相似度。
- 参数:
input_ids (第一个 ID 列表) –
input_ids_scores (input_ids 的分数(权重)) –
matching_ids (第二个 ID 列表) –
matching_ids_scores (matching_ids 的分数(权重)) –
示例
>>> import torcharrow as ta >>> from torcharrow import functional >>> input_ids = ta.column([[1, 2, 3]]) >>> input_id_scores = ta.column([[1.0,2.0,3.0]]) >>> matching_ids = ta.column([[1,2,3]]) >>> matching_id_scores = ta.column([[5.0,4.0,3.0]]) >>> functional.get_cosine_similarity(input_ids, input_id_scores, matching_ids, matching_id_scores) 0 0.831522 dtype: Float32(nullable=True), length: 1, null_count: 0