Community project sharing | build a film recommendation system with Jina

We are in contact with the recommendation system every day, including short videos, e-commerce, takeout, performances, advertisements

Today, we will demonstrate the project of Jina AI Community user Li Achintya, who built a movie recommendation system with Jina.

Overview of the principle of film recommendation system

In this Demo, the author transforms the movie recommendation into a text search problem.

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

Note: before starting, you need to provide the model with fields such as movie name, description and type.

Technology stack: Jina,Rest API,Dart

Database: IMDB movie dataset

Architecture diagram of film recommendation system

The specific process is as follows:

1. Download from Kaggle IMDB movie dataset.

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

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

4. Search Flow encodes the input query and searches the index data for the most matching option.

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

Code demonstration: three key steps to build a movie recommendation system

The core steps of this Demo include: building Flow, indexing and search functions.

1. Create Flow

Two executors will be used here: SimpleIndexer And TransformerTorchEncoder

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 Index function

The Index function obtains the image data set in text format, converts it into 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 search function

The search function receives text input and sends an HTTP post request to obtain similar movie titles from 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. Please visit the complete code GitHub Repo

Effect display of film recommendation system

About author Achintya:

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

Learning materials involved in this paper

Learning Bootcamp

DocArray document

Jina document

Join the community

Read the original blog

Tags: AI neural networks Deep Learning

Posted by shadowwebs on Fri, 06 May 2022 14:33:23 +0300