Click4Ai

498.

Hard

Model Compression

===============

In machine learning, model compression is the process of reducing the size of a trained neural network model while preserving its accuracy. This is essential for deploying models on devices with limited memory or computational resources. In this problem, you will implement a simple model compression technique using weight quantization.

Example:

Suppose we have a neural network with weights in the range [-1, 1]. We can compress the model by quantizing the weights to 8-bit integers.

Constraints:

  • The input is a 2D array of weights with shape (num_layers, num_weights).
  • The output should be a 2D array of quantized weights with shape (num_layers, num_weights).
  • Use NumPy's integer data types to represent the quantized weights.
  • Implement a function that takes the input weights and returns the quantized weights.
  • Test Cases

    Test Case 1
    Input: [[0.5, 0.2], [0.1, 0.8]]
    Expected: [[0, -1], [0, 1]]
    Test Case 2
    Input: [[-1, 1], [0.5, 0.2]]
    Expected: [-1, 1]
    + 3 hidden test cases