Slamby Similar Product Recommendation Engine (SPR) in 9 Simple Steps

This use case tutorial shows how easy to have high accurate and language independent similar product recommendation engine with Slamby. The tutorial covers the all steps from the beginning till the implementation to your website in Node.JS (JavaScript) language.

1. Collecting your data to work with

At first lets create a dataset on the Slamby Server where we can import our required product data and categories. After it’s done Slamby can use it to learn your classification rules.

During the training process, Slamby will read and understand the text from the interpreted fields in your product database and learn how to categorize your digital products. After the training process, Slamby will be able to recommend similar products with the most relevant products from your product database.

Keep in mind that when the product quantity is higher, accuracy will be higher as well. Especially when there is high amount of category in your database.

Necessary fields inside of category database are ’Category ID’, ’Parent ID’ and ’Category Name’.
Necessary fields inside of product database are ’Category ID’, Product ID’, ’Product Title’ and ’Product Description’.

Example Database

slamby_database

Tips: You can have as much fields as you want in your product database in order to store, monitor, modify and analyze. Mentioned fields are necessary to build recommendation engine.

2. Getting Started

In order to speed up process and avoid complexity, we are going to use Slamby TAU. TAU is a desktop application that makes you able to communicate with your Slamby Server directly to take quick actions. Click here to download the latest release of Slamby TAU.

Slamby TAU Tutorials

For an additional information, you can manage all process by using your command line in several programming languages as well. To know how, visit our GitHub Page to find out our SDKs.

Example TAU Login Screen

Slamby TAU Login Screen

After launching TAU, the first thing to do is to define our server credentials. Click on the New button to create new endpoint. Now, we can set our credentials in a JSON format.

{
"ApiBaseEndpoint": "https://europe.slamby.com/demo/",
"ApiSecret": "s3cr3t",
"ParallelLimit": 4,
"BulkSize": 1000
}

Example TAU New Dataset Screen
Slamby TAU Creating a New Dataset

To create a dataset, first we need to fill a form with the following parameters:

Name: We will define name of our dataset. demo-dataset

NgramCount: This count will determine the maximum n-gram value of our database that will be used during the classification. Default value is "3"

IdField: the ID field name from the sample database. id

TagField: the tag field name from the sample database. category

InterpretedFields: fields from the sample database which contains text to analyze. We want to analyze ad titles and descriptions to get best category recommendation. name, description

SampleDocument: We should define the schema of our product database.

{
"id": 10,
"name": "thisistheadtitle",
"description": "thisistheaddescription",
"category": [
"category1"
],
"price": "$100"
}

3. Importing Data into the Dataset

Next step is importing our product and category databases into the dataset.

Example TAU Data Import
Slamby TAU Dataset Importing

  1. By right-click on created dataset, we can select to import document from ”csv or json” and import tag from ”csv or json”.

  2. After selecting the right import format, we can select our source file using file browser.

  3. Then, – a setting window pops-up. Here we can set the delimiter that will apply during CSV parsing. There is also a force import checkbox. Using force mode, all the errors will be detected and reported, but the import will be continued anytime. Not using Force mode, import process will stop when the first error detected.

Tips: If you want to fix the errors inside of your database, don’t use force mode. In that time, Slamby will detect the mistakes particularly and you can easily fix those one by one.

4. Creating a Similar Product Recommendation Engine (PRC Service)

Next step is building PRC service using “Slamby Twister” technology.

Example TAU Create New Service Screen
Slamby TAU Create New Service (PRC)

To create a PRC Service, we will provide the required name and the short description of it in order to recognize the service in our future actions. Select Prc as a type of service, and click on the ‘Ok’ button. The service is going to be displayed in ‘New status’.

5. Preparation of SPR Engine

Next step is preparation of ‘PRC Service’ by providing our custom settings as a single JSON.

Example TAU Preparation Setting Screen

Name Description
DataSetName Source Dataset name that we are going to use to create PRC Service. We will use ecommerce_dataset that we have created.
TagIdList Tag IDs that we are going to use for SPR. We will keep it as null, all the Leaf Tag Ids will be used or we can provide the specific Tag IDs to be used for SPR.
{
"DataSetName": "demo-dataset",
"TagIdList": null
}

Tips: to select your custom Tag Ids and paste it into the JSON setting, select your required Tags in Data>Tags, and press ctrl+c, then ctrl+v in the json document. The selected Tag IDs array will be pasted as a JSON array.

6. Activation of SPR Engine

Next step is adjusting the activation settings of ‘PRC Service’ in a JSON format.

Example TAU Activation Setting Screen
Slamby TAU PRC Service Activation

To activate the PRC Service, we can define interpreted fields for recommendation. But now, we will keep it as 'Null' to use all the fields.

{
"FieldsForRecommendation": null
}

7. Testing of Similar Product Recommendation Engine

Now, our recommendation engine is ready for testing…

Example TAU Recommend Screen
Slamby TAU PRC Recommendation

To test the service, we should fill the JSON setting input form with the available settings and to send our request to the Service API endpoint.

Name Description
Text Here, we can type the text to be analyzed by the PRC Service. This text will be analyzed and service will show us the similar product recommendations. "Limited Edition iPhone 6s 128GB Custom Matte Black Gold Logo & Buttons"
Count We can adjust the counter to determine the quantity of recommended products. We will type 5 to receive 5 most similar similar products as a result.
NeedDocumentInResult We can set the Need document in result as true in order to receive full detailed document response.
TagId We can set the TagID to determine the Target Tag ID where the analysis is going to be processed. We will keep it as null add all the Leaf Tag Ids will be used.
Filter By using Filter, we can make the analysis on the filtered documents. But, we will keep it as null and all the documents will be used for the analysis.
Weights By using Weight, we can customize our fields in an order. But, we will keep it as null and the results will be in an order according to the score.
{
"Text": "Limited Edition iPhone 6s 128GB Custom Matte Black Gold Logo & Buttons",
"Count": 5,
"NeedDocumentInResult": true,
"TagId": "4",
"Filter": null,
"Weights": null
}

8. Slamby SDK with Node.JS (JavaScript) Language

Open up your server file with the extension .js by using text editor (such as notepad). Just type out and modify the below code. Then, save it.

var SlambySdk = require('slamby-sdk');

var apiInstance = new SlambySdk.PrcServiceApi();

var id = "bde8cf2e-b543-456f-8d61-70769b923ae8"; // String |

var opts = {
'request': new SlambySdk.PrcRecommendationRequest() // PrcRecommendationRequest |
};

apiInstance.recommendService(id, opts).then(function(data) {
console.log('API called successfully. Returned data: ' + data);
}, function(error) {
console.error(error);
});

Click here to download the sample server.js file that we have already prepared for you.

Tips: You should modify the below listed items:
+ client.basePath with your ‘Server URL’
+ Authorization with your Server API Secret
+ ID with your PRC Service ID, which is created automatically after you created your service by using TAU.

9. Try it out

Enjoy your demo.

Import Tags from csv using Python

Quick example how to import tags from CSV file using Slamby Python SDK.

import slamby_sdk
from slamby_sdk.rest import ApiException
import csv

server = "https://europe.slamby.com/demo/"
secret = "s3cr3t"
targetDataset = "demo"

client = slamby_sdk.ApiClient(server)
client.set_default_header("Authorization", "Slamby {0}".format(secret))
client.set_default_header("X-DataSet", targetDataset);

with open('tags.csv') as csvfile: 
    for item in csv.DictReader(csvfile):
        try:
            tag = slamby_sdk.Tag()
            tag.id = item["Id"]
            tag.name = item["Name"]
            slamby_sdk.TagApi(client).create_tag(tag = tag)
        except ApiException as e:
            print(e)

Download this example from here

How to Create PRC Service with Slamby TAU and .Net SDK

In this tutorial, we will show you how to prepare and run a PRC service.

You can use this service for similar document detection, document match-making, keyword extraction, duplicated document detection. PRC service analyzes all incoming documents by using Slamby Twister algorithm to provide perfect result with a relevant score.

Slamby TAU is an integrated data management solution that communicates directly with your Slamby Server. It makes you able to use your server resources in the cloud and manage your data easily in a real-time on your computer.

PRC Service Video Tutorial

1. Creating a PRC Service

Let’s start with adding a new PRC service.

Example TAU Create New Service Screen
Slamby TAU PRC Service Creation

To create a PRC Service, provide the significant name and the short description. Then, click on the ‘Okay’ button. Now, you can see that service is displayed in New status.

Create New Service Example using .Net SDK

var service = new Service()
{
Name = "Classifier",
Description = "This is a demo service description",
Type = ServiceTypeEnum.Prc
};
var result = await serviceManager.CreateServiceAsync(service);
var createdService = result.ResponseObject;

2. Preparation of PRC Service

To prepare your PRC Service, provide your custom settings by using Json.

Example TAU Preparation Setting Screen
Slamby TAU PRC Service Preparation

Define the Source Dataset name that you are going to use and provide the tag IDs or just keep it as 'null' to use all the leaf tag IDs.

{
"DataSetName": "demo-dataset",
"TagIdList": [ "4", "132", "211", "3" ],
}

Then, Click on the OK button to start the process.

Tips: to select your custom Tag Ids and paste it into the JSON setting, select your required Tags in Data>Tags, and press ctrl+c, then ctrl+v in the json document. The selected Tag IDs array will be pasted as a JSON array.

Preparation of New Service Example using .Net SDK

var prcServiceManager = new PrcServiceManager(_configuration);
var prcPrepareSettings = new PrcPrepareSettings()
{
DataSetName = "demo-dataset",
TagIdList = new List() { "4", "132", "211", "3" }
};
var prepareResponse = await prcServiceManager.PrepareServiceAsync(serviceId, prcPrepareSettings);
var process = prepareResponse.ResponseObject;

3. Activation of PRC Service

After preparation process is finished, you can set the activation settings in a JSON format.

Example TAU Activation Setting Screen
Slamby TAU PRC Service Activation

Define interpreted fields for recommendation or keep it as null to use all the fields. Those fields should be identical with your document database fields.

{
"FieldsForRecommendation": [ "Subject", "Body" ]
}

Then, click on the OK button to activate the service.

Activation of PRC Service Example using .Net SDK

var prcServiceManager = new PrcServiceManager(_configuration);
var prcActivateSettings = new Models.Services.PrcActivateSettings()
{
FieldsForRecommendation = new List() { "title" }
};
var activateResponse = await prcServiceManager.ActivateServiceAsync(serviceId, prcActivateSettings);

4. Testing of PRC Service

And finally, everything is ready to test the PRC Service. To test it, click on the Recommend button. You just need to fill the JSON setting input form with the available settings and send your request to the Service API endpoint.

Example TAU Recommend Screen
Slamby TAU PRC Service Recommendation

This text will be analyzed and used for recommendation. Set the count to determine the number of result items in response body. Set the Need document in result as ‘true or false’ in order to receive full detailed document response or just document IDs in response. Set the TagID to determine the Target Tag ID where the analysis is going to be processed. By using Filter, you can make the analysis on the filtered documents. And by using weights, you can customize your fields in an order. Weight can be any number between -10 to 10.

{
"Text": "Black Leather Laptop Bag",
"Count": 3,
"NeedDocumentInResult": true,
"TagId": 3,
"Filter": null,
"Weights": null,
}

And now, you can click on OK button to receive the recommendation results.

Recommendation of PRC Service Example using .Net SDK

var prcServiceManager = new PrcServiceManager(_configuration);
var prcRecommendationRequest = new Models.Services.PrcRecommendationRequest()
{
Text = "Black Leather Laptop Bag",
NeedDocumentInResult = true,
Count = 3,
TagId = "3"
};
var recommendResponse = (await prcServiceManager.RecommendServiceAsync(serviceId, prcRecommendationRequest));

5. PRC Service Recommendation Result

The score is between 0 to 2.

Example TAU PRC Result Screen
Slamby TAU PRC Service Recommendation Result

When the score is 1, all the relevant keywords are the same and basically it means a duplication. When the score is higher than 1, the documents contain the same keywords but more frequently.

Response Example of PRC Service Result

[
{
"DocumentId": "280092",
"Score": 1.1760036101632098,
"Document": {
"ad_id": "280092",
"category_id": "8392",
"subject": "Black Leather Laptop Bag",
"body": "Maxam Brand Italian Mosaic Design Genuine Black Leather Business Briefcase, Laptop Bag, Messenger or Carry On Bag. Features exterior zippered pockets on both sides. The zippered top opens into 3 compartments and another zipper-secured pocket. Hand grips are trimmed with silver-tone hardware. It can be shoulder carried by using the added detachable shoulder strap. Measures 16-1/2'' x 11'' x 5''.",
"moderation_status": "1",
}
]

 

Download our SDKs from Github.com/Slamby

How to Create Classifier Service with Slamby TAU and .Net SDK

In this tutorial, we will show you how to prepare and run a classifier service.

Slamby TAU is an integrated data management solution that communicates directly with your Slamby Server. It makes you able to use your server resources in the cloud and manage your data easily in a real-time on your computer.

With Slamby, you can easily create Text Classification service with high capacity and accuracy using Slamby Twister classification algorithm in any language.

Classifier Service Video Tutorial

1. Creating a Classifier Service

Let’s start with adding a new classifier service.

Example TAU Create New Service Screen
Slamby TAU Classifier Service Creation

To create a Classifier Service, provide the significant name and the short description. Then, click on the ‘Okay’ button. Now, you can see that service is displayed in New status.

Create New Service Example using .Net SDK

var service = new Service()
{
Name = "Classifier",
Description = "This is a demo service description",
Type = ServiceTypeEnum.Classifier
};
var result = await serviceManager.CreateServiceAsync(service);
var createdService = result.ResponseObject;

2. Preparation of Classifier Service

To prepare your Classifier Service, provide your custom settings by using Json.

Example TAU Preparation Setting Screen
Slamby TAU Classifier Preparation

Write the source ‘Dataset Name’ that you are going to use to create Classifier Service. Provide the Tag IDs to use for classification or just keep it as null to use all the leaf Tag IDs. And, Set the n-gram list with an array to use during your classification.

{
"DataSetName": "demo-dataset",
"TagIdList": [ "4", "132", "211", "3" ],
"NGramList": [ 1, 2 , 3 ]
}

Then, Click on the OK button to start the process.

Tips: to select your custom Tag Ids and paste it into the JSON setting, select your required Tags in Data>Tags, and press ctrl+c, then ctrl+v in the json document. The selected Tag IDs array will be pasted as a JSON array.

Preparation of New Service Example using .Net SDK

var classifierServiceManager = new ClassifierServiceManager(_configuration);
var classifierPrepareSettings = new ClassifierPrepareSettings()
{
DataSetName = "demo-dataset",
NGramList = new List() { 1, 2, 3 }
};
var prepareResponse = await classifierServiceManager.PrepareServiceAsync(serviceId, classifierPrepareSettings);
var process = prepareResponse.ResponseObject;

3. Activation of Classifier Service

After preparation process is finished, you can set the activation settings in a JSON format.

Example TAU Activation Setting Screen
Slamby TAU Classifier Activation

Define Tag IDs from the prepared list to use for classification or keep it as null to use all the prepared Tag IDs. And , which n-gram model you like to use during the classification.

{
"EmphasizedTagIdList": null,
"TagIdList": null,
"NGramList": [1,2,3]
}

Then, click on the OK button to activate the service.

Activation of Classifier Service Example using .Net SDK

var classifierServiceManager = new ClassifierServiceManager(_configuration);
var classifierActivateSettings = new Models.Services.ClassifierActivateSettings()
{
NGramList = new List() { 1, 2, 3 }
};
var activateResponse = await classifierServiceManager.ActivateServiceAsync(serviceId, classifierActivateSettings);

4. Testing of Classifier Service

And finally, everything is ready to test the classifier. To test it, click on the Recommend button. You just need to fill the JSON setting input form with the available settings and send your request to the Service API endpoint.

Example TAU Recommend Screen
Slamby TAU CLassifier Recommendation

This text will be analyzed and used for classification. Set the count to adjust the response tag number to display. If you don’t need tag in result, keep it as false. But when you value it as true, you will receive the results with details. Such as; Tag Id, Tag Name, Tag Parent ID and related properties.

{
"Text": "Brand New Laptop for Sales !!!",
"Count": 3,
"UseEmphasizing": false,
"NeedTagInResult": true
}

Then, click on the OK button to receive the result.

Testing of Classifier Service Example using .Net SDK

var classifierServiceManager = new ClassifierServiceManager(_configuration);
var classifierRecommendationRequest = new Models.Services.ClassifierRecommendationRequest()
{
Text = "Brand New Laptop for Sales !!!",
NeedTagInResult = true,
Count = 3
};
var recommendResponse = (await classifierServiceManager.RecommendServiceAsync(serviceId, classifierRecommendationRequest));

Example TAU Classifier Recommendation Result
Slamby TAU Classifier Recommendation Result

 

Download our SDKs from Github.com/Slamby