Community project sharing | Build a movie recommendation system with Jina

Time:2022-9-22

We are in contact with recommendation systems every day, short videos, e-commerce, takeaways, performances, advertisements…

Today, we will demonstrate the project of Jina AI community user Achintya,He used Jina to build a movie recommendation system.

An overview of the principle of movie recommendation system

In this demo, the authors transform movie recommendation into a text search problem.

The system takes the user input as a text query and searches and finds similar movies in the database.

Note: You need to provide the model with fields such as the movie's name, description, and genre before starting.

Technology stack: Jina,Rest API,Dart

database: IMDB Movie Dataset

Community project sharing | Build a movie recommendation system with Jina

Movie recommendation system architecture diagram

The specific process is as follows:

1. Download from KaggleIMDB Movie Dataset

2. Add the data to the DocumentArray for further preprocessing and indexing.

3. Send the DocumentArray to Flow, and use the Executor on Jina Hub to index the data.

4. Search Flow will encode the input query and search the index data for the best matching option.

5. After finding the best match, send the Rest API as output data (this API is suitable for various front-end frameworks).

Code demo: 3 key steps to build a movie recommendation system

The core steps of this demo include: building Flow, indexing, and searching.

1. Create Flow

Two Executors will be used here:SimpleIndexerandTransformerTorchEncoder

from jina import Flow 

flow = (
 Flow(port_expose='12345', protocol='http').add(
  uses="jinahub://TransformerTorchEncoder",
  uses_with={
   "pretrained_model_name_or_path": 
   "sentence-transformers/paraphrase-distilroberta-base-v1"
   },
  name="encoder",
  install_requirements=True
 )
 .add(
  uses="jinahub://SimpleIndexer/latest", 
  uses_metas={"workspace": "workspace"},
  volumes="./workspace:/workspace/workspace",
  name="indexer"
 )
)

2. Create the Index function

The Index function takes an image dataset in text format, converts it to Jina's native DocumentArray, and sends it to Flow for indexing and searching.

with flow as f:    
 f.post(on="/index", inputs=movies, show_progress=True)     
 f.post(on="/", show_progress=True)
 f.cors = True
 f.block()

3. Create a search function

The search function takes text input and makes an HTTP post request to get similar movie titles from the Jina backend.

import 'dart:convert';
import 'package:http/http.dart';
 
makePostRequest() async {  
 final uri = Uri.parse('http://192.168.1.9:12345/search');
 final headers = {'Content-Type': 'application/json'};
 var  final_data = [];
 Map<String, dynamic> body = {
    "data": [      
        {"text": "comedy"}
    ],
    "parameters": {"limit": 10}
 };
 String jsonBody = json.encode(body);
 final encoding = Encoding.getByName('utf-8'); 
 Response response = await post(
    uri,
    headers: headers,
    body: jsonBody,
    encoding: encoding,
 );
 int statusCode = response.statusCode;
 String responseBody = response.body;
 print(statusCode);
 var convertedData = jsonDecode(responseBody);
 final_data = convertedData['data'][0]['matches'];
 for (var item in final_data) {
    print(item['tags']['Title']);
  }
} 
void main(List<String> arguments) {
  print("Starting"); 
  makePostRequest();
}

The above is the whole process of creating a movie recommendation system with Jina. For the complete code, please visitGitHub Repo

Community project sharing | Build a movie recommendation system with Jina

Effect display of movie recommendation system

About the author Achintya:

Jina AI community member, sophomore majoring in computer science, specializing in machine learning and application development.

Learning materials covered in this article

Learning Bootcamp

DocArray documentation

Jina Documentation

Join the community

Read the original blog

Recommended Today

Docker Notes – Making docker-compose commands work in any path

The command docker-compose to maintain the docker harbor warehouse has a strange (very) strange (low) default setting, which isIt must be executed in the directory where docker-compose.yml (or any one of the four files docker-compose.yml, docker-compose.yaml, compose.yml, and compose.yaml) is located to be valid. Execute the docker-compose command in any path, and the result may […]