Salesforce Einstein Vision Intent and Sentiment Metamind APIs

 Salesforce Platform Einstein have following capabilities on Vision, Intent and Sentiment Analysis

This is end to end flow of capturing data points to training the Einstein Model

Intent API's are used for understanding the intent of statements and classify them into Intent buckets.

Sentiment API's are used for understanding the sentiment and classify them into Sentiment buckets.

Gather data points with examples for classification. Using these data points train the model. Then test the model by giving actual test data. 

Trained model would return probabilities of matching labels.

To create a intent dataset: 

Curl command:

curl -X POST -H "Authorization: Bearer GUZ2L7MWBXLVV4H2ZDB5JMZ5G7HKXXDMDM3DOO2NWMMI3DTRVXXGZMUMOHVRF4QNPNJG7XCPCSEXTWOPO2M7AO6B5VTH3XSOWEPQ4YQ" -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data" -F "type=text-intent" -F "data=@C:\Data_Set.csv" https://api.einstein.ai/v2/language/datasets/upload

Response received:

{"id":1028943,"name":"Data_Set","createdAt":"2017-12-08T14:13:39.000+0000","updatedAt":"2017-12-08T14:13:39.000+0000","labelSummary":{"labels":[]},"totalExamples":0,"available":false,"statusMsg":"UPLOADING","type":"text-intent","object":"dataset"}

 The id of the dataset is 1028943 and status is UPLOADING

To check the upload status of dataset:

Curl Command:

curl -X GET -H "Authorization: Bearer GUZ2L7MWBXLVV4H2ZDB5JMZ5G7HKXXDMDM3DOO2NWMMI3DTRVXXGZMUMOHVRF4QNPNJG7XCPCSEXTWOPO2M7AO6B5VTH3XSOWEPQ4YQ" -H "Cache-Control: no-cache" https://api.einstein.ai/v2/language/datasets/1028943

Commands for Training model

Following curl command was used to train the model using dataset uploaded.

Curl command:

curl -X POST -H "Authorization: Bearer GUZ2L7MWBXLVV4H2ZDB5JMZ5G7HKXXDMDM3DOO2NWMMI3DTRVXXGZMUMOHVRF4QNPNJG7XCPCSEXTWOPO2M7AO6B5VTH3XSOWEPQ4YQ" -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data" -F "name=Case Label Assignment Model" -F "datasetId=1028943" https://api.einstein.ai/v2/language/train

CCWGZ4ZMTV2MIVOSHMGSXUWGDY Model Id is returned in the response.

To get the training status

Curl command: 

curl -X GET -H "Authorization: Bearer GUZ2L7MWBXLVV4H2ZDB5JMZ5G7HKXXDMDM3DOO2NWMMI3DTRVXXGZMUMOHVRF4QNPNJG7XCPCSEXTWOPO2M7AO6B5VTH3XSOWEPQ4YQ" -H "Cache-Control: no-cache" https://api.einstein.ai/v2/language/train/CCWGZ4ZMTV2MIVOSHMGSXUWGDY

Testing Intent API

curl -X POST -H "Authorization: Bearer <TOKEN>" -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data" -F "modelId=WEQ6PHPBGFYVX5C7QDP6XU3NXY" -F "document=what is the weather in Los Angeles" https://api.einstein.ai/v2/language/intent

{
    "probabilities": [
        {
            "label": "current-weather",
            "probability": 0.9904295
        },
        {
            "label": "five-day-forecast",
            "probability": 0.009345241
        },
        {
            "label": "hourly-forecast",
            "probability": 0.00022528473
        }
    ]
}

Testing Sentiment API

curl -X POST -H "Authorization: Bearer <TOKEN>" -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data" -F "modelId=WJH4YCA7YX4PCWVNCYNWYHBMY4" -F "document=I can't tell you how much fun it was" https://api.einstein.ai/v2/language/sentiment

{ "probabilities": [
    {      "label": "positive",
      "probability": 0.77945083
    },
    {      "label": "negative",
      "probability": 0.18806243
    },
    {      "label": "neutral",
      "probability": 0.032486767
    }
  ] }

Following are VISON API's for uploading dataset and train the model

curl -X POST -H "Authorization: Bearer <token>" -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data" -F "type=image" -F "path=http://einstein.ai/images/mountainvsbeach.zip" https://api.einstein.ai/v2/vision/datasets/upload/sync
 
curl -X GET -H "Authorization: Bearer <token>" -H "Cache-Control: no-cache" https://api.einstein.ai/v2/vision/datasets

 curl -X DELETE -H "Authorization: Bearer <TOKEN>" -H "Cache-Control: no-cache" https://api.einstein.ai/v2/vision/datasets/<DATASET_ID>

curl -X POST -H "Authorization: Bearer <token>" -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data" -F "name=Beach and Mountain Model" -F "datasetId=1035643" https://api.einstein.ai/v2/vision/train

curl -X GET -H "Authorization: Bearer CXLFE3CLNQMYYNOB7RYFOEWK67BJBJVWVUOBHW3QQZAGBVPAKWFD6XHDIBDTA5REZFLPSKTDBY5FDJNBB7PGRWXMB727VIYZLEESBHI" -H "Cache-Control: no-cache" https://api.einstein.ai/v2/vision/train/VJBH7KRTZF2FSH7MSKEME2CQCM

Multi level images can also be trained
Each subdirectory below the parent directory becomes a label in the dataset. This subdirectory must contain images to be added to the dataset.
Following is the predict API.

Following is vision detect API


Following is Feedback API

curl -X POST -H "Authorization: Bearer <TOKEN>" -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data" -F "modelId=3CMCRC572BD3OZTQSTTUU4733Y" -F "data=@c:\data\alps.jpg" -F "expectedLabel=Mountains" https://api.einstein.ai/v2/vision/feedback 

Following is retrain API

curl -X POST -H "Authorization: Bearer <TOKEN>" -H "Cache-Control: no-cache" -H "Content-Type: multipart/form-data" -F "modelId=7JXCXTRXTMNLJCEF2DR5CJ46QU"  https://api.einstein.ai/v2/vision/retrain 

Following would be steps for auto training the model
1. Get all the data points which have been classified by model in last 24 hours.
2. Invoke "https://api.einstein.ai/v2/oauth2/token" and generate access token from Salesforce.
3. Upload the dataset using file created in step 1
4. Retrain the model (https://api.einstein.ai/v2/language/retrain) by giving model id.
5. Keep on checking the training status by invoking https://api.einstein.ai/v2/language/train/<modelid>

Setup VSCode with Salesforce

Step by Step guide to setup VSCode with Salesforce Install vscode Install Salesforce CLI (developer.salesforce.com/tools/sfdxcli) Perform fo...