Tag: Retrieval

  • ML0100 Duplicate Detection

    This is an IntvML Pro interview question. Upgrade to Pro to unlock the full prompt, diagrams, and solution.

  • MSD0014 Music Identification

    Design a music identification system like Shazam: a user holds up a phone in a noisy cafe, records a 10-second snippet, and the app names the song within a second. Apple’s ShazamKit exposes the same matching to third-party apps, Google’s “Now Playing” identifies music continuously and offline on Pixel phones, and SoundHound even accepts hummed melodies.

    How would you design this system? Cover the audio fingerprint representation, the matching index, the latency and scale budget, and how the system behaves under noise, tempo changes, and remixes.

    Line-art scene: a cafe loudspeaker playing a song, a phone recording a short snippet through noise waves, and a question mark asking which song is playing

    The Problem: ten seconds of music buried in cafe noise must pick one recording out of tens of millions, in under a second, and a wrong answer is worse than none. Design the system that hears the song through the crowd.

    Answer

    The design is audio fingerprinting with landmark hashes, the approach Shazam published in 2003 and which remains the backbone of production matchers: convert audio to a spectrogram, keep only the strongest time-frequency peaks (a constellation map that survives noise), hash pairs of peaks into compact tokens, and match a query by finding reference tracks whose hashes recur with one consistent time offset. The two pivotal decisions are to match a lossy peak representation instead of the waveform (robustness to noise, codec compression, and reverb) and to use an inverted index over hashes with time-coherence voting, which turns “find this song” into a few hundred lookups and a histogram test rather than a comparison against the whole catalog.

    (1) Constellation Frontend: STFT spectrogram, keep local peaks only; noise must out-shout a peak to erase it, so ~20 peaks/second survive a cafe.
    (2) Combinatorial Hashing: each anchor peak pairs with peaks in a short target zone; the hash packs both frequencies and the time gap, giving millions of distinct tokens.
    (3) Inverted Index + Offset Voting: hash to list of (track, time) postings; matching query hashes vote on the offset, and a histogram spike declares the track.
    (4) Asymmetric Confidence: naming the wrong song costs more than “no match found”, so an answer needs enough aligned votes plus a margin over the runner-up.
    (5) Catalog Ingestion at Scale: new releases are fingerprinted as labels deliver them; the index is sharded by hash and held in RAM for sub-second queries.

    Music identification pipeline: a register lane fingerprints catalog tracks into a hash index, and a recognize lane turns a noisy snippet into hashes, votes on time offsets, and returns the track title

    Figure 1: Register and recognize lanes share one fingerprinting frontend; recognition is index lookups plus offset voting, never a comparison against raw audio.

    Clarify Before Designing:
    (1) Query Conditions: phone microphone in noise versus clean line-in audio, and how short a snippet must work (5 s? 15 s?)?
    (2) Catalog Scope: tens of millions of commercial tracks, and do covers, remixes, and live versions count as the same song?
    (3) Latency Budget: sub-second answer on a mobile connection, or is a few seconds acceptable?
    (4) On-Device versus Cloud: must matching run offline with a regional catalog subset (the Now Playing design), or is the phone always online?
    (5) Beyond Exact Recordings: is humming or cover identification in scope (a different, melody-based representation), or exact audio only?


    Login to view more content
  • MSD0009 Restaurant Recommendation System for Food Delivery

    This is an IntvML Pro interview question. Upgrade to Pro to unlock the full prompt, diagrams, and solution.

  • DL0065 Group Normalization

    This is an IntvML Pro interview question. Upgrade to Pro to unlock the full prompt, diagrams, and solution.

  • DL0057 2D VS 3D Convolutions

    This is an IntvML Pro interview question. Upgrade to Pro to unlock the full prompt, diagrams, and solution.

  • DL0053 Gated Attention

    This is an IntvML Pro interview question. Upgrade to Pro to unlock the full prompt, diagrams, and solution.

  • DL0030 Positional Encoding

    This is an IntvML Pro interview question. Upgrade to Pro to unlock the full prompt, diagrams, and solution.

  • ML0011 Precision and Recall

    What are Precision and Recall?

    Three-panel question card. A test set of 10,000 card transactions has only 50 fraud cases. Model A flags 60 transactions and scores 99.6 percent accuracy, while Model B flags nothing and still scores 99.5 percent. Missed fraud and false alarms each carry a different business cost.

    The Problem: A fraud model and a do-nothing model reach almost the same accuracy on a test set where only 0.5% of transactions are fraud, and each kind of mistake has a different cost. Which metrics would tell these models apart?

    Answer

    Precision and recall are two fundamental metrics for evaluating classification models, especially with imbalanced data or asymmetric error costs. Precision (positive predictive value) is the ratio of correctly predicted positives to all predicted positives: it answers “when the model says positive, how often is it right?” If a spam detector flags 100 emails and 99 are truly spam, precision is 99%. Recall (sensitivity, true positive rate) is the ratio of correctly predicted positives to all actual positives: it answers “of all the real positives, how many did the model catch?” If 100 spam emails exist and the model finds 90, recall is 90%. High precision means few false alarms (a spam filter that almost never marks good mail as spam); high recall means few misses (a cancer screening that almost never misses a real case). The two metrics sit on a trade-off controlled by the decision threshold.

    (1) Precision = Accuracy Of Positive Predictions: Minimizing false positives matters when false alarms are costly.
    (2) Recall = Coverage Of Actual Positives: Minimizing false negatives matters when misses are costly.
    (3) Trade-Off: Lowering the classification threshold raises recall and usually lowers precision; raising it does the reverse.

    Set diagram of relevant and retrieved items showing TP, FP, and FN regions

    Figure 1: The set view: precision is the share of the retrieved set that is correct, recall is the share of the relevant set that was retrieved.

    Mathematical Formulation:
    \text{Precision} = \frac{TP}{TP + FP}
    \text{Recall} = \frac{TP}{TP + FN}

    Where:

    • TP (true positives) is the count of positives correctly predicted as positive.
    • FP (false positives) is the count of negatives wrongly predicted as positive, the false alarms.
    • FN (false negatives) is the count of positives wrongly predicted as negative, the misses.
    • TN (true negatives) is the count of negatives correctly predicted as negative; it enters neither formula, which is why these metrics shine on imbalanced data.

    Login to view more content