SlideShare a Scribd company logo
1 of 48
Download to read offline
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 1
IBM Watson & PHP:
A Practical
Demonstration
Clark Everetts, Rogue Wave Software
php[tek] 2018
31 May 2018
Atlanta Georgia
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 2
Agenda
• The Goal
• Possible ML use cases
• Sample database
• IBM Cloud brief overview
• Text to Speech :-)
• Speech to Text :-/
• Initial Chatbot with Watson Assistant
• Next Steps / Further Research
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 3
My end goal
• Can you find how much of your inventory is on hand or
allocated?
• Which product lines your customers are buying, and in what
volume?
• Hands-free?
• How can Watson services help you:
• understand how much stock is available
• who is buying and selling it
• spot trends
• Key concepts and points:
• speech-to-text
• text-to-speech
• interactive application on IBM i
• powered by Watson in the cloud
• data residing on the IBM I – not stored in cloud
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 4
Machine Learning Use-Case: Code Quality
Higher quality libraries are
• Easier to understand
• Easier to maintain
• Easier to test
• Get updated sooner
• Bugfixes
• New features
• Don’t break as easily or as often
• Greater interest/participation from dev team and users
*Campbell County Kentucky Public Library
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 5
Code Quality: Cognitive vs. Static Analysis
• PHPLOC – size metrics, complexity, dependencies, structure
– https://github.com/sebastianbergmann/phploc
• Copy/Paste Detector – finds duplicated code (exact dups)
– https://github.com/sebastianbergmann/phpcpd
• PHP Depend -
– https://pdepend.org/
• PHP Mess Detector
– https://phpmd.org/
• Phpstan
– https://github.com/phpstan/phpstan
• Phan
– https://github.com/phan/phan
• Exakat
– https://www.exakat.io/
• PHPMetrics
– http://www.phpmetrics.org/
Watson:
?
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 6
Know anybody with a warehouse?
Product picking system
Text-to-speech and db-connectivity are key.
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 7
BIRT Sample Database
BIRT – Business Intelligence Reporting Tools
Eclipse Project, has an interesting sample database
Classic marine, car, truck, and train models.
DB Tables:
Offices
Employees
Customers
Orders
Payments
Order Details
Products
Product Lines
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 8
BIRT Database Schema
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 9
IBM Bluemix Cloud
https://console.bluemix.net/ (login with IBM id)
Stay informed!!
https://www.ibm.com/blogs/bluemix/
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 10
IBM Cloud Catalog Categories
Infrastructure
Compute
Storage
Network
Security
Containers
VMware
Platform
Boilerplates
APIs
Application Services
Blockchain
Cloud Foundry Apps
Data & Analytics
DevOps
Finance
Functions
Integrate
Internet of Things
Mobile
Network
Security
Storage
Watson
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 11
IBM Cloud Catalog: Watson
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 12
Choosing the right services
• Several related / overlapping services
• Need good understanding
• Application
• functionality, scope, breadth,
depth
• Nature of data
• static / dynamic
• structure & contents
• size
• Watson services
• what each provides, &
doesn’t
• setup, (re)training, update
• initial and ongoing cost
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 13
IBM Cloud Catalog: Watson
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 14
Challenges
• Unstructured speech to structured db queries
• Correctly parsing the resulting text
• Building correct SQL query from text
• Knowing when not to attempt a query
Question: “Who are my customers?”
Appropriate Query: Select customerName from Customers
join Employees on salesrepEmployeeNumber = employeeNumber
where salesrepEmployeeNumber = X;
• Intention, Context, Memory
• Q1. Who are my customers? (company name or point of contact)
• Q2. Where are they located? (city, state, province, sales region,
country?)
• Q3. Who has not ordered in three months?
“my” (authenticated user), “they” (results of Q1), “who” (results of Q1, not
Q2)
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 15
Text-to-Speech: Overview
• Quickly converts written text to natural-sounding speech
• Voice-driven and screenless interfaces
• Anywhere where audio is the preferred method of output
• home automation solutions
• assistance tools for the vision-impaired
• reading text and email messages aloud to drivers
• video script narration and voice over
• reading-based educational tools
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 16
Text-to-Speech: Features
• HTTP and WebSocket interfaces
• SSML (Speech Synthesis Markup Language)
• Audio formats
• Ogg format with Opus or Vorbis codec
• Waveform Audio File Format (WAV)
• Free Lossless Audio Codec (FLAC)
• MP3 (Motion Picture Experts Group, or MPEG)
• Web Media (WebM) with the Opus or Vorbis codec
• Linear 16-bit Pulse-Code Modulation (PCM)
• mu-law (u-law)
• basic audio
• Languages
• English, French, German, Italian, Japanese, Spanish, and
Brazilian Portuguese
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 17
Text-to-Speech: Features (cont’d)
• Voices -
• one male or female voice, sometimes both, for each
language
• US and UK English and Castilian, Latin American, North
American Spanish
• uses appropriate cadence and intonation
• Expressiveness
• Add’l SSML element to indicate a speaking style
• GoodNews, Apology, Uncertainty
• currently US English Allison voice only
• Voice transformation
• pitch, rate, timbre
• built-in transformations for “young” and “soft”
• Customization of pronunciation
• International Phonetic Alphabet (IPA)
• IBM Symbolic Phonetic Representation (SPR)
• Text-to-speech demo https://text-to-speech-
demo.ng.bluemix.net/
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 18
Text-to-Speech: Initial Test
<?php
namespace ClarkPhpWatsonDemo;
use GuzzleHttpClient;
use ZendDiactorosRequest;
use ZendDiactorosUri;
use ZendDiactorosResponse;
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../src/classic-models.php';
call_user_func(function () {
$config = getConfig()['text-to-speech'];
$client = new Client();
$request = (new Request())
->withUri((new Uri("{$config['uri']}/synthesize"))
->withQuery('voice=en-US_AllisonVoice'))
->withMethod('POST')
->withAddedHeader('Authorization',
'Basic ' .
base64_encode("{$config['username']}:{$config['password']}"))
->withAddedHeader('Content-Type', 'application/json')
->withAddedHeader('Accept', $config['mime_type']);
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 19
Text-to-Speech: Initial Test (cont’d)
$request->getBody()->write(
json_encode(['text' => 'Customer requested special shipment. The
instructions were passed along to the warehouse.'])
);
$response = $client->send($request); // send to Watson
// send audio output back to web browser
header("Content-Type: {$config['mime_type']}");
header('Content-Disposition: inline; filename=result.ogg');
header('Content_Length: ' . strlen($response->getBody()));
print $response->getBody();
});
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 20
Application Configuration
<?php
return [
'text-to-speech' => [
'mime_type' => 'audio/ogg;codecs=opus',
'uri' => 'https://stream.watsonplatform.net/text-to-speech/api/v1',
],
'speech-to-text' => [
'mime_type' => 'audio/ogg;codecs=opus',
'uri' => 'https://stream.watsonplatform.net/speech-to-text/api/v1',
],
'db' => [
'I71EDU' => [
'options' => [
'autocommit' => DB2_AUTOCOMMIT_OFF,
'DB2_ATTR_CASE' => DB2_CASE_NATURAL,
'cursor' => DB2_FORWARD_ONLY,
'i5_lib' => 'CLARK',
'i5_naming' => DB2_I5_NAMING_OFF,
'i5_query_optimize' => DB2_ALL_IO,
],
],
],
];
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 21
Credentials Configuration
<?php
return [
'text-to-speech' => [
'username' => ‘a-big-long-obfuscated-hash',
'password' => ‘a-secret-hash'
],
'speech-to-text' => [
'username' => ' another-obfuscated-hash',
'password' => ' another-secret-hash'
],
'db' => [
'I71EDU' => [
'userprofile' => ‘my-user-name',
'password' => ‘my-password'
],
],
];
Keep auth credentials out of source code repository by putting them in
a separate file, and mark that file to be ignore by version control.
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 22
Merged Configuration
function getConfig()
{
return array_merge_recursive(
require_once __DIR__ . '/../config/config.php',
require_once __DIR__ . '/../config/credentials.php'
);
}
Calling the above yields the following merged configuration:
[
'text-to-speech' => [
'mime_type' => 'audio/ogg;codecs=opus',
'uri' => 'https://stream.watsonplatform.net/text-to-speech/api/v1/',
'username' => ‘a-big-long-obfuscated-hash',
'password' => ‘a-secret-hash‘
],
'speech-to-text' => […],
'db' => […]
]
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 23
Text-to-Speech: Product Description
call_user_func(function ()
{
$config = getConfig();
$db = getDbConnection($config);
$productDesc = getRandomProductDescription($db);
$client = new Client();
$request = (new Request())
->withUri((new Uri("{$config['text-to-speech']['uri']}/synthesize"))
->withQuery('voice=en-US_AllisonVoice’)) // config candidate
->withMethod('POST')
->withAddedHeader(
'Authorization',
'Basic ' . base64_encode("{$config['text-to-
speech']['username']}:{$config['text-to-speech']['password']}")
)->withAddedHeader('Content-Type', 'application/json')
->withAddedHeader('Accept', $config['text-to-speech']['mime_type']);
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 24
Text-to-Speech: Product Description (cont’d)
$request->getBody()->write(
json_encode(['text' => $productDesc ?: 'I was unable to access any
product description.'])
);
$response = $client->send($request);
header("Content-Type: {$config['text-to-speech']['mime_type']}");
header('Content-Disposition: inline; filename=result.ogg');
header('Content_Length: ' . strlen($response->getBody()));
print $response->getBody();
});
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 25
Quick Demo
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 26
Speech-to-Text: Overview
• Converts human voice into the written word
• Potential uses
• voice control of embedded systems
• transcription of meetings and conference calls
• dictation
• Combines information about grammar and language structure with
knowledge of the composition of the audio signal to generate a
transcription
• Languages: US and UK English, Japanese, Arabic, Mandarin, Brazilian
Portuguese, Spanish (Latin American & Spain), French, Localized
version available in Japan via SoftBank
• Metadata object in JSON response
• confidence score (per word), start/end time (per word), and
alternate hypotheses / N-Best (per phrase), word alternatives per
(sequential) time intervals
• Keyword Spotting (beta)
• search for keywords in audio stream. Begin/end times, confidence
score for each instance of the keyword found
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 27
Speech-to-Text: Overview (cont’d)
• Mobile SDKs (beta) for iOS and Android
• Optional metadata in JSON response includes
• confidence score (per word), start/end time (per word),
alternate hypotheses / N-Best (per phrase). alternatives per
(sequential) time interval
• Keyword search in audio stream
• beginning and end times
• confidence score for each instance found
• currently available at no additional charge
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 28
Speech-to-Text: Available Interfaces
• WebSocket
• single version of recognize method for transcribing audio
• low latency, high throughput over a full-duplex connection
• HTTP REST
• HTTP POST versions of recognize method for transcribing audio
with or without establishing a session with the service
• Accept input audio via
• request body
• multipart form data consisting of one or more audio files
• Can establish and maintain sessions with the service
• Obtain information about supported languages and models
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 29
Speech-to-Text: Available Interfaces
• Asynchronous HTTP
• Provides a non-blocking POST recognitions method
• Additional methods let you register a callback URL, to which the
service sends job status and optional results or to check the
status of jobs and retrieve results manually
• Uses HMAC-SHA1 signatures based on a user-specified secret
to provide authentication and data integrity for callback
notifications
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 30
Speech-to-Text: First Attempt
What I said:
Hello! This is Clark Everetts with Rogue Wave Software. I’m unable to
take your call at the moment, but if you leave your name, telephone
number, and a brief message, I’ll return your call as soon as possible.
Thank-you!
What I got:
hello this is or ever will when software mama unable to halt the
moment but if you leave your home telephone number and message
of return your call as soon as possible and
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 31
Speech-to-Text: Alternatives
“ … as soon as possible and “ (selected with highest confidence of
0.628)
“ … as soon as possible “
“ … as soon as possible are “
"alternatives": [
{
"timestamps": [
[
"hello",
0.13,
0.56
],
[
"this",
0.59,
0.76
],
[
"is",
0.76,
0.98
],
[
"or",
1.02,
1.3
],
[
"ever",
1.33,
1.64
],
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 32
Speech-to-Text: Recent Attempt
What I said:
Hello! This is Clark Everetts with Rogue Wave Software. I’m unable to
take your call at the moment, but if you leave your name, telephone
number, and a brief message, I’ll return your call as soon as possible.
Thank-you!
What I got:
hello this is or ever will one software on unable to recall the moment
but if you own telephone number which of the turn your call as soon
as possible
My theory: Terrible quality of audio taken from my laptop. Even after
editing out the worst hiss, the speech, though clear enough to a
person, isn’t clear enough for speech recognition.
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 33
Speech-to-Text test: Code
<?php
namespace ClarkPhpWatsonDemo;
use GuzzleHttpClient;
use ZendDiactorosRequest;
use ZendDiactorosUri;
use ZendDiactorosResponse;
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../src/classic-models.php';
call_user_func(function () {
$config = getConfig();
$config = $config['speech-to-text'];
$client = new Client();
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 34
Speech-to-Text test: Code (cont’d)
$request = (new Request())
->withUri((new Uri("{$config['uri']}/recognize"))
->withQuery('timestamps=true&max_alternatives=3&inactivity_timeout=3'))
->withMethod('POST')
->withAddedHeader('Authorization',
'Basic ' . base64_encode("{$config['username']}:{$config['password']}"))
->withAddedHeader('Content-Type', 'audio/flac')
->withAddedHeader('Accept', 'application/json');
$request->getBody()
->write(file_get_contents(__DIR__ . '/../docs/telephone-greeting.flac'));
$response = $client->send($request);
print('<pre>');
printf("Response status: %d (%s)n",
$response->getStatusCode(), $response->getReasonPhrase()
);
printf("Headers:n");
foreach ($response->getHeaders() as $header => $values) {
printf(" %s: %sn", $header, implode(', ', $values));
}
printf("Message:n%sn", $response->getBody());
print '</pre>';
});
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 35
Watson Assistant: Overview
• Natural language interface backend for any application
• Natural conversation flows between your applications and users
• Automate interactions with end users
• Common applications
• virtual agents
• chat bots
• Trainable through web application, import of CSV files, or web API
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 36
Assistant: Where to get help
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 37
Watson Assistant: Intents – what are they?
• Purpose or goal expressed in a customer's input
• answering a question
• placing an order
• processing a bill payment
• canceling a process
• turning something on
• turning something off
• Watson recognizes the intent expressed in input
• Uses intent to choose appropriate dialog flow for responding to it
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 38
Watson Assistant: Intents - training
• Train Watson with minimum of five example statements
• More is better
• Best case: real user statements or questions for examples of intent
• Not necessary for examples to work with the same aspect of your
system; the important thing is they express intent
• Example: finding the location of something (#find_location intent)
• Customers, Employees, and Offices have locations
• Employees are associated with Office location.
• Where is customer Atelier graphique?
• Where is customer Dragon Souveniers located?
• What city is customer Diecast Classics headquartered in?
• Customer Herkku Gifts is located where?
• The location of William Patterson is where?
• Find Mary Patterson?
• What is the location of Julie Firrelli?
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 39
Watson Assistant: Entities
• Represent a class of object or a data type relevant to a user's purpose
• Recognizes entities mentioned in the user's input
• Conversation service uses entities to choose the specific actions to
take to fulfill an intent.
• Entities clarify a user's intent.
• Different entity values trigger different responses for the same intent.
• Entities for which there is a location:
• Employees
• Diane Murphy
• Mary Patterson, …
• Customers
• Technics Stores Inc.
• Herkku Gifts…
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 40
Dialog Flow
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 41
Conversation Dialog Flow (cont’d)
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 42
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 43
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 44
Conversation Dialog Flow (cont’d)
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 45
Testing Conversation Flow
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 46
Where to go from here?
• Next Phase
• Add more to Assistant instance, for workflow and context, and
“flow” to appropriate action, driving appropriate DB queries
• Use API to build and modify Assistant Dialog
• Making programmatic calls from an Assistant dialog node
• Improve recognition of Speech-to-Text
• Using spotted key words, parse text files and build SQL queries?
• Follow-on research
• Natural Language Processing
• Trend analysis, perhaps unexpected correlations (need more
realistic data and a much larger data set)
• Other Watson services
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 47
So, who is this guy?
• Clark Everetts
• Rogue Wave Software (acquired Zend 2015)
• PHP since 2005
• Professional Services Consultant
• Architecture & Performance Audits
• PHP, Zend Framework Training
• Zend Server
• App Development, Best Practices
• Many moons ago: missile launch control,
space station embedded software
• clark.everetts@roguewave.com
• @clarkphp on Twitter
© 2018 Rogue Wave Software, Inc. All Rights Reserved. 48
THANK-YOU
Stay in touch!
clark.everetts@roguewave.com
@clarkphp
Source code will be at
https://github.com/clarkphp/watson-classic-models
Your feedback is invaluable!
https://joind.in/talk/6a1fe

More Related Content

Similar to IBM Watson & PHP, A Practical Demonstration

국내 미디어 고객사의 AWS 활용 사례 - POOQ 서비스, 콘텐츠연합플랫폼::조휘열::AWS Summit Seoul 2018
국내 미디어 고객사의 AWS 활용 사례 - POOQ 서비스, 콘텐츠연합플랫폼::조휘열::AWS Summit Seoul 2018국내 미디어 고객사의 AWS 활용 사례 - POOQ 서비스, 콘텐츠연합플랫폼::조휘열::AWS Summit Seoul 2018
국내 미디어 고객사의 AWS 활용 사례 - POOQ 서비스, 콘텐츠연합플랫폼::조휘열::AWS Summit Seoul 2018
Amazon Web Services Korea
 
Using LLVM to accelerate processing of data in Apache Arrow
Using LLVM to accelerate processing of data in Apache ArrowUsing LLVM to accelerate processing of data in Apache Arrow
Using LLVM to accelerate processing of data in Apache Arrow
DataWorks Summit
 
Mobile Web Applications using HTML5 [IndicThreads Mobile Application Develop...
Mobile Web Applications using HTML5  [IndicThreads Mobile Application Develop...Mobile Web Applications using HTML5  [IndicThreads Mobile Application Develop...
Mobile Web Applications using HTML5 [IndicThreads Mobile Application Develop...
IndicThreads
 
Introduction to Backend Development (1).pptx
Introduction to Backend Development (1).pptxIntroduction to Backend Development (1).pptx
Introduction to Backend Development (1).pptx
OsuGodbless
 

Similar to IBM Watson & PHP, A Practical Demonstration (20)

The Role of Standards in IoT Security
The Role of Standards in IoT SecurityThe Role of Standards in IoT Security
The Role of Standards in IoT Security
 
Building your own chat bot with Amazon Lex - Hebrew Webinar
Building your own chat bot with Amazon Lex - Hebrew WebinarBuilding your own chat bot with Amazon Lex - Hebrew Webinar
Building your own chat bot with Amazon Lex - Hebrew Webinar
 
국내 미디어 고객사의 AWS 활용 사례 - POOQ 서비스, 콘텐츠연합플랫폼::조휘열::AWS Summit Seoul 2018
국내 미디어 고객사의 AWS 활용 사례 - POOQ 서비스, 콘텐츠연합플랫폼::조휘열::AWS Summit Seoul 2018국내 미디어 고객사의 AWS 활용 사례 - POOQ 서비스, 콘텐츠연합플랫폼::조휘열::AWS Summit Seoul 2018
국내 미디어 고객사의 AWS 활용 사례 - POOQ 서비스, 콘텐츠연합플랫폼::조휘열::AWS Summit Seoul 2018
 
Using LLVM to accelerate processing of data in Apache Arrow
Using LLVM to accelerate processing of data in Apache ArrowUsing LLVM to accelerate processing of data in Apache Arrow
Using LLVM to accelerate processing of data in Apache Arrow
 
Custom Component development Oracle's Intelligent Bot Platform
Custom Component development Oracle's Intelligent Bot PlatformCustom Component development Oracle's Intelligent Bot Platform
Custom Component development Oracle's Intelligent Bot Platform
 
Breaking Up the Monolith While Migrating to AWS (GPSTEC320) - AWS re:Invent 2018
Breaking Up the Monolith While Migrating to AWS (GPSTEC320) - AWS re:Invent 2018Breaking Up the Monolith While Migrating to AWS (GPSTEC320) - AWS re:Invent 2018
Breaking Up the Monolith While Migrating to AWS (GPSTEC320) - AWS re:Invent 2018
 
Lex and connect
Lex and connectLex and connect
Lex and connect
 
Intro to AWS Cloud Development Kit | AWS Floor28
Intro to AWS Cloud Development Kit | AWS Floor28Intro to AWS Cloud Development Kit | AWS Floor28
Intro to AWS Cloud Development Kit | AWS Floor28
 
Mobile Web Applications using HTML5 [IndicThreads Mobile Application Develop...
Mobile Web Applications using HTML5  [IndicThreads Mobile Application Develop...Mobile Web Applications using HTML5  [IndicThreads Mobile Application Develop...
Mobile Web Applications using HTML5 [IndicThreads Mobile Application Develop...
 
AI Powered Conversational Interfaces
AI Powered Conversational InterfacesAI Powered Conversational Interfaces
AI Powered Conversational Interfaces
 
Connected Product Development - Secure Cloud & Local Connectivity for Microco...
Connected Product Development - Secure Cloud & Local Connectivity for Microco...Connected Product Development - Secure Cloud & Local Connectivity for Microco...
Connected Product Development - Secure Cloud & Local Connectivity for Microco...
 
Driving Innovation with Serverless Applications (GPSBUS212) - AWS re:Invent 2018
Driving Innovation with Serverless Applications (GPSBUS212) - AWS re:Invent 2018Driving Innovation with Serverless Applications (GPSBUS212) - AWS re:Invent 2018
Driving Innovation with Serverless Applications (GPSBUS212) - AWS re:Invent 2018
 
Introduction to Backend Development (1).pptx
Introduction to Backend Development (1).pptxIntroduction to Backend Development (1).pptx
Introduction to Backend Development (1).pptx
 
運用 AWS Edge Services 作為遊戲行業的關鍵基礎設施元件 (Level 200)
運用 AWS Edge Services 作為遊戲行業的關鍵基礎設施元件 (Level 200)運用 AWS Edge Services 作為遊戲行業的關鍵基礎設施元件 (Level 200)
運用 AWS Edge Services 作為遊戲行業的關鍵基礎設施元件 (Level 200)
 
ai mlLeverage Data and AI/ML to Drive New Experiences and Make Better Decisions
ai mlLeverage Data and AI/ML to Drive New Experiences and Make Better Decisionsai mlLeverage Data and AI/ML to Drive New Experiences and Make Better Decisions
ai mlLeverage Data and AI/ML to Drive New Experiences and Make Better Decisions
 
Media Processing Workflows at High Velocity and Scale using AI and ML - AWS O...
Media Processing Workflows at High Velocity and Scale using AI and ML - AWS O...Media Processing Workflows at High Velocity and Scale using AI and ML - AWS O...
Media Processing Workflows at High Velocity and Scale using AI and ML - AWS O...
 
Zapbuild Portfolio
Zapbuild PortfolioZapbuild Portfolio
Zapbuild Portfolio
 
Platform as Art: A Developer’s Perspective
Platform as Art: A Developer’s PerspectivePlatform as Art: A Developer’s Perspective
Platform as Art: A Developer’s Perspective
 
Amazon FreeRTOS: IoT Operating System for Microcontrollers (IOT208-R1) - AWS ...
Amazon FreeRTOS: IoT Operating System for Microcontrollers (IOT208-R1) - AWS ...Amazon FreeRTOS: IoT Operating System for Microcontrollers (IOT208-R1) - AWS ...
Amazon FreeRTOS: IoT Operating System for Microcontrollers (IOT208-R1) - AWS ...
 
Open Source AI - News and examples
Open Source AI - News and examplesOpen Source AI - News and examples
Open Source AI - News and examples
 

More from Clark Everetts

Zend con practical-zf1-zf2-migration
Zend con practical-zf1-zf2-migrationZend con practical-zf1-zf2-migration
Zend con practical-zf1-zf2-migration
Clark Everetts
 
Zend con what-i-learned-about-mobile-first
Zend con what-i-learned-about-mobile-firstZend con what-i-learned-about-mobile-first
Zend con what-i-learned-about-mobile-first
Clark Everetts
 

More from Clark Everetts (7)

Analysis of-quality-of-pkgs-in-packagist-univ-20171024
Analysis of-quality-of-pkgs-in-packagist-univ-20171024Analysis of-quality-of-pkgs-in-packagist-univ-20171024
Analysis of-quality-of-pkgs-in-packagist-univ-20171024
 
Php Dependency Management with Composer ZendCon 2017
Php Dependency Management with Composer ZendCon 2017Php Dependency Management with Composer ZendCon 2017
Php Dependency Management with Composer ZendCon 2017
 
Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016
 
Automated Infrastructure and Application Management
Automated Infrastructure and Application ManagementAutomated Infrastructure and Application Management
Automated Infrastructure and Application Management
 
Sunshine php practical-zf1-zf2-migration
Sunshine php practical-zf1-zf2-migrationSunshine php practical-zf1-zf2-migration
Sunshine php practical-zf1-zf2-migration
 
Zend con practical-zf1-zf2-migration
Zend con practical-zf1-zf2-migrationZend con practical-zf1-zf2-migration
Zend con practical-zf1-zf2-migration
 
Zend con what-i-learned-about-mobile-first
Zend con what-i-learned-about-mobile-firstZend con what-i-learned-about-mobile-first
Zend con what-i-learned-about-mobile-first
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

IBM Watson & PHP, A Practical Demonstration

  • 1. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 1 IBM Watson & PHP: A Practical Demonstration Clark Everetts, Rogue Wave Software php[tek] 2018 31 May 2018 Atlanta Georgia
  • 2. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 2 Agenda • The Goal • Possible ML use cases • Sample database • IBM Cloud brief overview • Text to Speech :-) • Speech to Text :-/ • Initial Chatbot with Watson Assistant • Next Steps / Further Research
  • 3. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 3 My end goal • Can you find how much of your inventory is on hand or allocated? • Which product lines your customers are buying, and in what volume? • Hands-free? • How can Watson services help you: • understand how much stock is available • who is buying and selling it • spot trends • Key concepts and points: • speech-to-text • text-to-speech • interactive application on IBM i • powered by Watson in the cloud • data residing on the IBM I – not stored in cloud
  • 4. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 4 Machine Learning Use-Case: Code Quality Higher quality libraries are • Easier to understand • Easier to maintain • Easier to test • Get updated sooner • Bugfixes • New features • Don’t break as easily or as often • Greater interest/participation from dev team and users *Campbell County Kentucky Public Library
  • 5. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 5 Code Quality: Cognitive vs. Static Analysis • PHPLOC – size metrics, complexity, dependencies, structure – https://github.com/sebastianbergmann/phploc • Copy/Paste Detector – finds duplicated code (exact dups) – https://github.com/sebastianbergmann/phpcpd • PHP Depend - – https://pdepend.org/ • PHP Mess Detector – https://phpmd.org/ • Phpstan – https://github.com/phpstan/phpstan • Phan – https://github.com/phan/phan • Exakat – https://www.exakat.io/ • PHPMetrics – http://www.phpmetrics.org/ Watson: ?
  • 6. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 6 Know anybody with a warehouse? Product picking system Text-to-speech and db-connectivity are key.
  • 7. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 7 BIRT Sample Database BIRT – Business Intelligence Reporting Tools Eclipse Project, has an interesting sample database Classic marine, car, truck, and train models. DB Tables: Offices Employees Customers Orders Payments Order Details Products Product Lines
  • 8. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 8 BIRT Database Schema
  • 9. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 9 IBM Bluemix Cloud https://console.bluemix.net/ (login with IBM id) Stay informed!! https://www.ibm.com/blogs/bluemix/
  • 10. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 10 IBM Cloud Catalog Categories Infrastructure Compute Storage Network Security Containers VMware Platform Boilerplates APIs Application Services Blockchain Cloud Foundry Apps Data & Analytics DevOps Finance Functions Integrate Internet of Things Mobile Network Security Storage Watson
  • 11. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 11 IBM Cloud Catalog: Watson
  • 12. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 12 Choosing the right services • Several related / overlapping services • Need good understanding • Application • functionality, scope, breadth, depth • Nature of data • static / dynamic • structure & contents • size • Watson services • what each provides, & doesn’t • setup, (re)training, update • initial and ongoing cost
  • 13. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 13 IBM Cloud Catalog: Watson
  • 14. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 14 Challenges • Unstructured speech to structured db queries • Correctly parsing the resulting text • Building correct SQL query from text • Knowing when not to attempt a query Question: “Who are my customers?” Appropriate Query: Select customerName from Customers join Employees on salesrepEmployeeNumber = employeeNumber where salesrepEmployeeNumber = X; • Intention, Context, Memory • Q1. Who are my customers? (company name or point of contact) • Q2. Where are they located? (city, state, province, sales region, country?) • Q3. Who has not ordered in three months? “my” (authenticated user), “they” (results of Q1), “who” (results of Q1, not Q2)
  • 15. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 15 Text-to-Speech: Overview • Quickly converts written text to natural-sounding speech • Voice-driven and screenless interfaces • Anywhere where audio is the preferred method of output • home automation solutions • assistance tools for the vision-impaired • reading text and email messages aloud to drivers • video script narration and voice over • reading-based educational tools
  • 16. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 16 Text-to-Speech: Features • HTTP and WebSocket interfaces • SSML (Speech Synthesis Markup Language) • Audio formats • Ogg format with Opus or Vorbis codec • Waveform Audio File Format (WAV) • Free Lossless Audio Codec (FLAC) • MP3 (Motion Picture Experts Group, or MPEG) • Web Media (WebM) with the Opus or Vorbis codec • Linear 16-bit Pulse-Code Modulation (PCM) • mu-law (u-law) • basic audio • Languages • English, French, German, Italian, Japanese, Spanish, and Brazilian Portuguese
  • 17. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 17 Text-to-Speech: Features (cont’d) • Voices - • one male or female voice, sometimes both, for each language • US and UK English and Castilian, Latin American, North American Spanish • uses appropriate cadence and intonation • Expressiveness • Add’l SSML element to indicate a speaking style • GoodNews, Apology, Uncertainty • currently US English Allison voice only • Voice transformation • pitch, rate, timbre • built-in transformations for “young” and “soft” • Customization of pronunciation • International Phonetic Alphabet (IPA) • IBM Symbolic Phonetic Representation (SPR) • Text-to-speech demo https://text-to-speech- demo.ng.bluemix.net/
  • 18. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 18 Text-to-Speech: Initial Test <?php namespace ClarkPhpWatsonDemo; use GuzzleHttpClient; use ZendDiactorosRequest; use ZendDiactorosUri; use ZendDiactorosResponse; require __DIR__ . '/../vendor/autoload.php'; require __DIR__ . '/../src/classic-models.php'; call_user_func(function () { $config = getConfig()['text-to-speech']; $client = new Client(); $request = (new Request()) ->withUri((new Uri("{$config['uri']}/synthesize")) ->withQuery('voice=en-US_AllisonVoice')) ->withMethod('POST') ->withAddedHeader('Authorization', 'Basic ' . base64_encode("{$config['username']}:{$config['password']}")) ->withAddedHeader('Content-Type', 'application/json') ->withAddedHeader('Accept', $config['mime_type']);
  • 19. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 19 Text-to-Speech: Initial Test (cont’d) $request->getBody()->write( json_encode(['text' => 'Customer requested special shipment. The instructions were passed along to the warehouse.']) ); $response = $client->send($request); // send to Watson // send audio output back to web browser header("Content-Type: {$config['mime_type']}"); header('Content-Disposition: inline; filename=result.ogg'); header('Content_Length: ' . strlen($response->getBody())); print $response->getBody(); });
  • 20. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 20 Application Configuration <?php return [ 'text-to-speech' => [ 'mime_type' => 'audio/ogg;codecs=opus', 'uri' => 'https://stream.watsonplatform.net/text-to-speech/api/v1', ], 'speech-to-text' => [ 'mime_type' => 'audio/ogg;codecs=opus', 'uri' => 'https://stream.watsonplatform.net/speech-to-text/api/v1', ], 'db' => [ 'I71EDU' => [ 'options' => [ 'autocommit' => DB2_AUTOCOMMIT_OFF, 'DB2_ATTR_CASE' => DB2_CASE_NATURAL, 'cursor' => DB2_FORWARD_ONLY, 'i5_lib' => 'CLARK', 'i5_naming' => DB2_I5_NAMING_OFF, 'i5_query_optimize' => DB2_ALL_IO, ], ], ], ];
  • 21. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 21 Credentials Configuration <?php return [ 'text-to-speech' => [ 'username' => ‘a-big-long-obfuscated-hash', 'password' => ‘a-secret-hash' ], 'speech-to-text' => [ 'username' => ' another-obfuscated-hash', 'password' => ' another-secret-hash' ], 'db' => [ 'I71EDU' => [ 'userprofile' => ‘my-user-name', 'password' => ‘my-password' ], ], ]; Keep auth credentials out of source code repository by putting them in a separate file, and mark that file to be ignore by version control.
  • 22. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 22 Merged Configuration function getConfig() { return array_merge_recursive( require_once __DIR__ . '/../config/config.php', require_once __DIR__ . '/../config/credentials.php' ); } Calling the above yields the following merged configuration: [ 'text-to-speech' => [ 'mime_type' => 'audio/ogg;codecs=opus', 'uri' => 'https://stream.watsonplatform.net/text-to-speech/api/v1/', 'username' => ‘a-big-long-obfuscated-hash', 'password' => ‘a-secret-hash‘ ], 'speech-to-text' => […], 'db' => […] ]
  • 23. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 23 Text-to-Speech: Product Description call_user_func(function () { $config = getConfig(); $db = getDbConnection($config); $productDesc = getRandomProductDescription($db); $client = new Client(); $request = (new Request()) ->withUri((new Uri("{$config['text-to-speech']['uri']}/synthesize")) ->withQuery('voice=en-US_AllisonVoice’)) // config candidate ->withMethod('POST') ->withAddedHeader( 'Authorization', 'Basic ' . base64_encode("{$config['text-to- speech']['username']}:{$config['text-to-speech']['password']}") )->withAddedHeader('Content-Type', 'application/json') ->withAddedHeader('Accept', $config['text-to-speech']['mime_type']);
  • 24. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 24 Text-to-Speech: Product Description (cont’d) $request->getBody()->write( json_encode(['text' => $productDesc ?: 'I was unable to access any product description.']) ); $response = $client->send($request); header("Content-Type: {$config['text-to-speech']['mime_type']}"); header('Content-Disposition: inline; filename=result.ogg'); header('Content_Length: ' . strlen($response->getBody())); print $response->getBody(); });
  • 25. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 25 Quick Demo
  • 26. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 26 Speech-to-Text: Overview • Converts human voice into the written word • Potential uses • voice control of embedded systems • transcription of meetings and conference calls • dictation • Combines information about grammar and language structure with knowledge of the composition of the audio signal to generate a transcription • Languages: US and UK English, Japanese, Arabic, Mandarin, Brazilian Portuguese, Spanish (Latin American & Spain), French, Localized version available in Japan via SoftBank • Metadata object in JSON response • confidence score (per word), start/end time (per word), and alternate hypotheses / N-Best (per phrase), word alternatives per (sequential) time intervals • Keyword Spotting (beta) • search for keywords in audio stream. Begin/end times, confidence score for each instance of the keyword found
  • 27. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 27 Speech-to-Text: Overview (cont’d) • Mobile SDKs (beta) for iOS and Android • Optional metadata in JSON response includes • confidence score (per word), start/end time (per word), alternate hypotheses / N-Best (per phrase). alternatives per (sequential) time interval • Keyword search in audio stream • beginning and end times • confidence score for each instance found • currently available at no additional charge
  • 28. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 28 Speech-to-Text: Available Interfaces • WebSocket • single version of recognize method for transcribing audio • low latency, high throughput over a full-duplex connection • HTTP REST • HTTP POST versions of recognize method for transcribing audio with or without establishing a session with the service • Accept input audio via • request body • multipart form data consisting of one or more audio files • Can establish and maintain sessions with the service • Obtain information about supported languages and models
  • 29. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 29 Speech-to-Text: Available Interfaces • Asynchronous HTTP • Provides a non-blocking POST recognitions method • Additional methods let you register a callback URL, to which the service sends job status and optional results or to check the status of jobs and retrieve results manually • Uses HMAC-SHA1 signatures based on a user-specified secret to provide authentication and data integrity for callback notifications
  • 30. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 30 Speech-to-Text: First Attempt What I said: Hello! This is Clark Everetts with Rogue Wave Software. I’m unable to take your call at the moment, but if you leave your name, telephone number, and a brief message, I’ll return your call as soon as possible. Thank-you! What I got: hello this is or ever will when software mama unable to halt the moment but if you leave your home telephone number and message of return your call as soon as possible and
  • 31. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 31 Speech-to-Text: Alternatives “ … as soon as possible and “ (selected with highest confidence of 0.628) “ … as soon as possible “ “ … as soon as possible are “ "alternatives": [ { "timestamps": [ [ "hello", 0.13, 0.56 ], [ "this", 0.59, 0.76 ], [ "is", 0.76, 0.98 ], [ "or", 1.02, 1.3 ], [ "ever", 1.33, 1.64 ],
  • 32. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 32 Speech-to-Text: Recent Attempt What I said: Hello! This is Clark Everetts with Rogue Wave Software. I’m unable to take your call at the moment, but if you leave your name, telephone number, and a brief message, I’ll return your call as soon as possible. Thank-you! What I got: hello this is or ever will one software on unable to recall the moment but if you own telephone number which of the turn your call as soon as possible My theory: Terrible quality of audio taken from my laptop. Even after editing out the worst hiss, the speech, though clear enough to a person, isn’t clear enough for speech recognition.
  • 33. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 33 Speech-to-Text test: Code <?php namespace ClarkPhpWatsonDemo; use GuzzleHttpClient; use ZendDiactorosRequest; use ZendDiactorosUri; use ZendDiactorosResponse; require __DIR__ . '/../vendor/autoload.php'; require __DIR__ . '/../src/classic-models.php'; call_user_func(function () { $config = getConfig(); $config = $config['speech-to-text']; $client = new Client();
  • 34. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 34 Speech-to-Text test: Code (cont’d) $request = (new Request()) ->withUri((new Uri("{$config['uri']}/recognize")) ->withQuery('timestamps=true&max_alternatives=3&inactivity_timeout=3')) ->withMethod('POST') ->withAddedHeader('Authorization', 'Basic ' . base64_encode("{$config['username']}:{$config['password']}")) ->withAddedHeader('Content-Type', 'audio/flac') ->withAddedHeader('Accept', 'application/json'); $request->getBody() ->write(file_get_contents(__DIR__ . '/../docs/telephone-greeting.flac')); $response = $client->send($request); print('<pre>'); printf("Response status: %d (%s)n", $response->getStatusCode(), $response->getReasonPhrase() ); printf("Headers:n"); foreach ($response->getHeaders() as $header => $values) { printf(" %s: %sn", $header, implode(', ', $values)); } printf("Message:n%sn", $response->getBody()); print '</pre>'; });
  • 35. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 35 Watson Assistant: Overview • Natural language interface backend for any application • Natural conversation flows between your applications and users • Automate interactions with end users • Common applications • virtual agents • chat bots • Trainable through web application, import of CSV files, or web API
  • 36. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 36 Assistant: Where to get help
  • 37. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 37 Watson Assistant: Intents – what are they? • Purpose or goal expressed in a customer's input • answering a question • placing an order • processing a bill payment • canceling a process • turning something on • turning something off • Watson recognizes the intent expressed in input • Uses intent to choose appropriate dialog flow for responding to it
  • 38. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 38 Watson Assistant: Intents - training • Train Watson with minimum of five example statements • More is better • Best case: real user statements or questions for examples of intent • Not necessary for examples to work with the same aspect of your system; the important thing is they express intent • Example: finding the location of something (#find_location intent) • Customers, Employees, and Offices have locations • Employees are associated with Office location. • Where is customer Atelier graphique? • Where is customer Dragon Souveniers located? • What city is customer Diecast Classics headquartered in? • Customer Herkku Gifts is located where? • The location of William Patterson is where? • Find Mary Patterson? • What is the location of Julie Firrelli?
  • 39. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 39 Watson Assistant: Entities • Represent a class of object or a data type relevant to a user's purpose • Recognizes entities mentioned in the user's input • Conversation service uses entities to choose the specific actions to take to fulfill an intent. • Entities clarify a user's intent. • Different entity values trigger different responses for the same intent. • Entities for which there is a location: • Employees • Diane Murphy • Mary Patterson, … • Customers • Technics Stores Inc. • Herkku Gifts…
  • 40. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 40 Dialog Flow
  • 41. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 41 Conversation Dialog Flow (cont’d)
  • 42. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 42
  • 43. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 43
  • 44. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 44 Conversation Dialog Flow (cont’d)
  • 45. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 45 Testing Conversation Flow
  • 46. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 46 Where to go from here? • Next Phase • Add more to Assistant instance, for workflow and context, and “flow” to appropriate action, driving appropriate DB queries • Use API to build and modify Assistant Dialog • Making programmatic calls from an Assistant dialog node • Improve recognition of Speech-to-Text • Using spotted key words, parse text files and build SQL queries? • Follow-on research • Natural Language Processing • Trend analysis, perhaps unexpected correlations (need more realistic data and a much larger data set) • Other Watson services
  • 47. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 47 So, who is this guy? • Clark Everetts • Rogue Wave Software (acquired Zend 2015) • PHP since 2005 • Professional Services Consultant • Architecture & Performance Audits • PHP, Zend Framework Training • Zend Server • App Development, Best Practices • Many moons ago: missile launch control, space station embedded software • clark.everetts@roguewave.com • @clarkphp on Twitter
  • 48. © 2018 Rogue Wave Software, Inc. All Rights Reserved. 48 THANK-YOU Stay in touch! clark.everetts@roguewave.com @clarkphp Source code will be at https://github.com/clarkphp/watson-classic-models Your feedback is invaluable! https://joind.in/talk/6a1fe