We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Multimodal Search Implementation

Let's put it all together with a multimodal search function. It will generate embeddings for the text in our movie dataset, then allow us to provide an image to search for similar movies.

Combining Multiple Modalities

With CLIP models, it's even possible to construct hybrid queries that combine text and images. We can do this by taking a weighted average of a text embedding and an image embedding, then adjusting the weighting however we like.

# User uploads an image AND types text
uploaded_image = Image.open("user_upload.jpg")
text_modifier = "but with bears"

# Encode both inputs
image_embedding = model.encode_image([uploaded_image])
text_embedding = model.encode_text([text_modifier])

# Combine embeddings (weighted average)
combined_query = (0.7 * image_embedding) + (0.3 * text_embedding)

We won't go this far in the current project, but with different modalities embedded in the same vector space, we can mix and match them in all sorts of ways.

Assignment

Implement image-based search to find movies by uploading images instead of typing queries.

    1. f"{doc['title']}: {doc['description']}"
      
  1. 1. Paddington (similarity: 0.722)
       Deep in the rainforests of Peru, a young bear lives peacefully with his Aunt Lucy and Uncle Pastuzo,...
    
    2. Murder She Said (similarity: 0.686)
       This is based on the Agatha Christie book "4:50 from Paddington" and the opening locale is Paddingto...
    
    3. Ted (similarity: 0.685)
       In 1985, eight-year-old John Bennett makes a Christmas wish that his teddy bear, Ted, would come to ...
    

Run and submit the CLI tests.