← back

Historical Context Compression Ratio

#455 · Computer Vision · Easy

⊣ Solve on deep-ml.com

Problem

Compute the compression ratio achieved by a historical context compression method in video generation. Given the original number of frames, the number of features per frame, and the compressed representation size (number of tokens), calculate the compression ratio.

Solution

1
2
3
4
5
6
7
8
def compression_ratio(
    num_frames: int,
    features_per_frame: int,
    compressed_tokens: int
) -> float:
    original_size = num_frames * features_per_frame
    ratio = original_size / compressed_tokens
    return round(ratio, 4)

Explanation

  1. The original representation has num_frames * features_per_frame total tokens/features.
  2. After compression the context is represented by compressed_tokens tokens.
  3. The compression ratio is the original size divided by the compressed size, showing how many times smaller the compressed representation is.

Complexity

  • Time: O(1)
  • Space: O(1)