Technical Deep Dive: Taking Watson to the Developer Glenn R. Fisher
by user
Comments
Transcript
Technical Deep Dive: Taking Watson to the Developer Glenn R. Fisher
Technical Deep Dive: Taking Watson to the Developer Session 4 - iOS and Python SDKs Glenn R. Fisher Jeffrey Stylos ©IBM Corporation Watson Developer Cloud: iOS SDK ©IBM Corporation 2 Why build an iOS SDK? • Meet customer expectations—backend services tend to offer native SDKs for mobile developers. • Support IBM-Apple partnership by enabling easier design of cognitive applications. • Encourage adoption of Watson services by targeting the growing ecosystem of Apple developers and devices. • More than 380,000 registered Apple developers. • More than 1 billion active Apple devices right now. • Platforms: iPhone, iPad, Apple TV, Apple Watch, Mac OS X, and Swift on Linux. ©IBM Corporation 3 Why build an iOS SDK? • To enhance the developer experience. With iOS SDK ©IBM Corporation 4 Getting Started with iOS SDK • Github Repository: https://github.com/watson-developer-cloud/ios-sdk • Quickstart Guide: https://github.com/watson-developer-cloud/ios-sdk/blob/master/Quickstart.md • Let’s write a powerful translation program. 1. An English sentence is transcribed by Speech to Text. 2. The sentence is translated by Language Translation. 3. The translation is synthesized by Text to Speech. ©IBM Corporation 5 iOS SDK Design Decision: Asynchronous • Asynchronous execution is expected in mobile applications. • Expensive network operations need to run in the background to maintain application responsiveness. • (No one likes an app that freezes every time it refreshes!) • To support asynchronous execution, the iOS SDK uses closures. • Closures are self-contained functions that can be passed around. (Similar to lambdas in other languages.) • Swift has first-class support for “trailing closure syntax” which makes it really easy to define completion handlers. ©IBM Corporation 6 iOS SDK Design Decision: Authentication Strategy Would you feel comfortable embedding your Bluemix credentials in a published application? Yes? Excellent! Then the iOS SDK is very easy to use. No? Then feel free to define a custom authentication strategy for your application. ©IBM Corporation 7 iOS SDK Design Decision: Authentication Strategy • Internally, we define a BasicAuthenticationStrategy and APIKeyAuthenticationStrategy. • Developers have the choice to either: • use a simple built-in authentication strategy but embed credentials in their application, or • write a custom authentication strategy to hide/protect their credentials. ©IBM Corporation 8 iOS SDK Timeline Completed: • Alchemy Language • Natural Language Classifier • Alchemy Vision • Personality Insights • Dialog • Speech to Text • Language Translation • Text to Speech Future Work: • Additional Watson Services • Additional Apple Platforms • Swift 3 + Swift Package Manager • Demo Applications • Hackathon Pitches ©IBM Corporation 9 Python SDK pip install --upgrade watson-developer-cloud https://github.com/watson-developer-cloud/python-sdk/ Design Decisions • So you want to make an SDK… Naming • “Watson” in the package / module name, not the class and method name • No abbreviations or acronyms (“NLC”) • Language-specific case conventions • Python: ClassName, module_name, variable_name • https://google.github.io/styleguide/ pyguide.html#Naming Examples as integration tests import json from os.path import join, dirname from watson_developer_cloud import SpeechToTextV1 speech_to_text = SpeechToTextV1( username='YOUR SERVICE USERNAME', password='YOUR SERVICE PASSWORD') print(json.dumps(speech_to_text.models(), indent=2)) with open(join(dirname(__file__), '../resources/speech.wav'), 'rb') as audio_file: print(json.dumps(speech_to_text.recognize( audio_file, content_type='audio/wav'), indent=2)) VCAP_SERVICES support • Credentials “just work” when using Bluemix, local environment variables, Travis speech_to_text = SpeechToTextV1() (Semi) Object Oriented status = natural_language_classifier.status('c7e487x21-nlc-1063') classes = natural_language_classifier.classify('c7e487x21-nlc-1063', 'How hot will it be tomorrow?’) vs classifier = natural_language_classifier.lookup(‘c7e487x21-nlc-1063') classifier.status() classifier.classify('c7e487x21-nlc-1063') Service Versions from watson_developer_cloud import NaturalLanguageClassifierV1 vs from watson_developer_cloud.NaturalLanguageClassifier.V1 import NaturalLanguageClassifier vs from watson_developer_cloud import NaturalLanguageClassifier natural_language_classifier = NaturalLanguageClassifier( version='v1', username='YOUR SERVICE USERNAME', password='YOUR SERVICE PASSWORD') Version Dates visual_recognition = VisualRecognitionV2Beta( username='YOUR SERVICE USERNAME', password='YOUR SERVICE PASSWORD', version='2015-12-02') vs visual_recognition = VisualRecognitionV2Beta( username='YOUR SERVICE USERNAME', password='YOUR SERVICE PASSWORD')