Shortcuts

Function torch::nn::functional::cosine_similarity

Function Documentation

inline Tensor torch::nn::functional::cosine_similarity(const Tensor &x1, const Tensor &x2, const CosineSimilarityFuncOptions &options = {})

See https://pytorch.org/docs/main/nn.functional.html#torch.nn.functional.cosine_similarity about the exact behavior of this functional.

See the documentation for torch::nn::functional::CosineSimilarityFuncOptions class to learn what optional arguments are supported for this functional.

Example:

namespace F = torch::nn::functional;
F::cosine_similarity(input1, input2,
F::CosineSimilarityFuncOptions().dim(1));

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources