Created
December 21, 2023 09:17
-
-
Save a-agmon/91a1ff7d3e99fefdb959b996ebb7db8c to your computer and use it in GitHub Desktop.
utility functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn apply_max_pooling(embeddings: &Tensor) | |
-> anyhow::Result<Tensor> { | |
Ok(embeddings.max(1)?) | |
} | |
pub fn l2_normalize(embeddings: &Tensor) | |
-> anyhow::Result<Tensor> { | |
Ok(embeddings.broadcast_div(&embeddings.sqr()?.sum_keepdim(1)?.sqrt()?)?) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment