Compute Sentence Similarity
ByteDanceMachine Learning Engineer · Technical ScreenLast updated
This question evaluates understanding of sentence-level and token-level embedding techniques, text preprocessing, similarity metrics, edge-case handling for empty or unknown tokens, and trade-offs between pretrained sentence encoders and averaged word embeddings.
Given two text inputs, design and implement a method to compute their semantic similarity.
You may use either of the following approaches:
- Encode each sentence into a single embedding using a pretrained sentence encoder, then compute cosine similarity.
- Convert each token to a word embedding, average the token embeddings for each sentence, then compute cosine similarity between the two averaged vectors.
Your answer should describe:
- How the text is preprocessed
- How embeddings are produced
- How cosine similarity is computed
- How to handle empty text or unknown tokens
- The trade-offs between sentence-level encoders and average word embeddings
If coding is requested, provide clear pseudocode or implementation-level steps.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.