From d75527f7eecc4e2fcdd18ab157412506717c8adb Mon Sep 17 00:00:00 2001 From: navanchauhan Date: Mon, 7 Nov 2022 23:36:11 -0700 Subject: add blog post --- ...21-06-27-Crude-ML-AI-Powered-Chatbot-Swift.html | 30 ++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'docs/posts/2021-06-27-Crude-ML-AI-Powered-Chatbot-Swift.html') diff --git a/docs/posts/2021-06-27-Crude-ML-AI-Powered-Chatbot-Swift.html b/docs/posts/2021-06-27-Crude-ML-AI-Powered-Chatbot-Swift.html index 0b307fd..cdae911 100644 --- a/docs/posts/2021-06-27-Crude-ML-AI-Powered-Chatbot-Swift.html +++ b/docs/posts/2021-06-27-Crude-ML-AI-Powered-Chatbot-Swift.html @@ -89,7 +89,8 @@ I created a sample JSON with only 3 examples (I know, very less, but works for a

Screenshot of Sample Dataset

-
[
+
+
[
     {
         "tokens": ["Tell","me","about","the","drug","Aspirin","."],
         "labels": ["NONE","NONE","NONE","NONE","NONE","COMPOUND","NONE"]
@@ -103,7 +104,8 @@ I created a sample JSON with only 3 examples (I know, very less, but works for a
         "labels": ["NONE","NONE","NONE","NONE","COMPOUND","NONE","NONE"]
     }
 ]
-
+
+

Screenshot of Create ML Text Classifier

@@ -113,7 +115,8 @@ I created a sample JSON with only 3 examples (I know, very less, but works for a

Screenshot

-
import CoreML
+
+
import CoreML
 import NaturalLanguage
 
 let mlModelClassifier = try IntentDetection_1(configuration:  MLModelConfiguration()).model
@@ -124,7 +127,8 @@ I created a sample JSON with only 3 examples (I know, very less, but works for a
 
 let tagger = NLTagger(tagSchemes: [.nameType, NLTagScheme("Apple")])
 tagger.setModels([tagPredictor], forTagScheme: NLTagScheme("Apple"))
-
+
+

Now, we define a simple structure which the custom function(s) can use to access the provided input. It can also be used to hold additional variables. @@ -134,7 +138,8 @@ The latter can be replaced with a function which asks the user for the input. Screenshot

-
struct User {
+
+
struct User {
     static var message = ""
 }
 
@@ -158,14 +163,16 @@ The latter can be replaced with a function which asks the user for the input. }
 
 }
-
+
+

Sometimes, no action needs to be performed, and the bot can use a predefined set of responses. Otherwise, if an action is required, it can call the custom action.

Screenshot

-
let defaultResponses = [
+
+
let defaultResponses = [
     "greetings": "Hello",
     "banter": "no, plix no"
 ]
@@ -173,14 +180,16 @@ Otherwise, if an action is required, it can call the custom action.

let customActions = [ "deez-drug": customAction ] -
+
+

In the sample input, the program is updating the User.message and checking if it has a default response. Otherwise, it calls the custom action.

Screenshot

-
let sampleMessages = [
+
+
let sampleMessages = [
     "Hey there, how is it going",
     "hello, there",
     "Who let the dogs out",
@@ -200,7 +209,8 @@ Otherwise, it calls the custom action.

print(customActions[prediction!]!()) } } -
+
+

Output

-- cgit v1.2.3