Click4Ai

524.

Hard

The Two-Tower Model is a type of neural network architecture used in recommender systems for retrieval tasks. It consists of two towers, one for users and one for items, that learn to represent users and items in a shared embedding space. **Example:** Suppose we have a user-item interaction matrix where each entry represents the rating given by a user to an item. We can use the Two-Tower Model to learn the embeddings of users and items that capture their interactions. **Constraints:** The user-item interaction matrix is sparse, meaning most users have interacted with few items. The number of users and items is large. The ratings are mostly binary (0 or 1).

Your task is to implement a Two-Tower Model using NumPy to learn the embeddings of users and items.

Test Cases

Test Case 1
Input: [[0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 1, 0], [1, 0, 0, 1]]
Expected: [[[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]], [[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]]]
Test Case 2
Input: [[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 0, 1], [0, 1, 1, 0]]
Expected: [[[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]], [[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]]]
+ 3 hidden test cases