Compute Sentence Similarity

Read the full interview experience this question came from →

Quick Overview

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.

Compute Sentence Similarity

Company: ByteDance

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Technical Screen

Given two text inputs, design and implement a method to compute their semantic similarity. You may use either of the following approaches: 1. Encode each sentence into a single embedding using a pretrained sentence encoder, then compute cosine similarity. 2. 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.

Overview: 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.

Read the full ByteDance Machine Learning Engineer interview experience this question came from

ByteDance logo
ByteDance
Jan 7, 2026
mediumMachine Learning EngineerTechnical ScreenMachine Learning
4
0

Given two text inputs, design and implement a method to compute their semantic similarity.

You may use either of the following approaches:

  1. Encode each sentence into a single embedding using a pretrained sentence encoder, then compute cosine similarity.
  2. 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.