You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: scorer.rs
    path of file: ./repos/rust-bert/src/pipelines/keywords_extraction
    
    the code of the file until where you have to start completion: /// Derived from https://github.com/MaartenGr/KeyBERT, shared under MIT License
///
/// Copyright (c) 2020, Maarten P. Grootendorst
/// Copyright (c) 2022, Guillaume Becquin
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, includ
    
fn cosine_similarity(document_embedding: Option<&Tensor>, word_embeddings: &Tensor) -> Tensor {
    let word_embeddings = word_embeddings
        / word_embeddings.linalg_norm(2.0, vec![1i64].as_slice(), true, Kind::Float);
    let reference_embedding = document_embedding.map(|embedding| {
        embedding / embedding.linalg_norm(2.0, vec![1i64].as_slice(), true, Kind::Float)
    });
    let reference_embedding = reference_embedding.as_ref().unwrap_or(&word_embeddings);

    reference_embedding.matmul(&word_embeddings.transpose(0, 1))
}