My Holiday Destination
Posted by
Manish Panchmatia
on Sunday, May 20, 2018
Labels:
About,
India,
Spiritual Science
/
Comments: (0)
Full article...>>
HDH Mahant Swami Maharaj @ Bangalore
Jai SwamiNarayan
Recently, HDH Mahant Swami Maharaj visited Bangalore. All followers of BAPS SwamiNarayan religion were super excited with full of devotion. If one remains in the presence of such divine Saint, even for short time, he/she get huge benefits in all fronts. I was lucky enough to get His blessings and listen to His speeches. He emphasize on importance of unity among all followers/volunteers for great success.
One of BAPS followers planned to sing Kirtan/Bhajan/rhyme in different languages : Hindi, Panjabi, Gujarati and Sanskrit. I just contributed by translating one such Gujarati hymn
ગુરુદેવના ચરણમાં કરીયે કરોડો વંદન
into Sanskrit. Here it goes for the benefits of all readers of this blog "Express YourSelf !"
गुरुदेवनाम् पादयोः। कुर्महे कोटि प्रणामान्
परब्रह्मन: पादयोः कुर्महे कोटि प्रणामान्
भवसागरम् तारयन्त: न: नाविका: भवन्त:
दीनबंधव: भो: रसवन्त: कुर्महे कोटि प्रणामान्
Recently, HDH Mahant Swami Maharaj visited Bangalore. All followers of BAPS SwamiNarayan religion were super excited with full of devotion. If one remains in the presence of such divine Saint, even for short time, he/she get huge benefits in all fronts. I was lucky enough to get His blessings and listen to His speeches. He emphasize on importance of unity among all followers/volunteers for great success.
One of BAPS followers planned to sing Kirtan/Bhajan/rhyme in different languages : Hindi, Panjabi, Gujarati and Sanskrit. I just contributed by translating one such Gujarati hymn
ગુરુદેવના ચરણમાં કરીયે કરોડો વંદન
into Sanskrit. Here it goes for the benefits of all readers of this blog "Express YourSelf !"
गुरुदेवनाम् पादयोः। कुर्महे कोटि प्रणामान्
परब्रह्मन: पादयोः कुर्महे कोटि प्रणामान्
भवसागरम् तारयन्त: न: नाविका: भवन्त:
दीनबंधव: भो: रसवन्त: कुर्महे कोटि प्रणामान्
वयम् दीन हीना: आगता: न किमपि नीता:
भवद्भि: ह्रदा स्विकृता: कुर्महे कोटि प्रणामान्
भो: श्री हरिसखीन: श्रीजी सदृशा: प्रतापिन:
अन्तरे वसन्त: शाक्षिन : कुर्महे कोटि प्रणामान्
भवन्त: अमृतम् वर्षन्त: तथापि वयम् पिपीषन्त:
परम् ह्रदया: रमन्त: कुर्महे कोटि प्रणामान्
सदा नेत्रेषु वसन्तु शरणे न: स्थापयन्तु
वयम् पादयोः वसेम कुर्महे कोटि प्रणामान्
Translation:
we all are bowing down at lotus feets of the master for crores of times.
he is like supreme Bhraman. We all are bowing down at lotus feet of supreme Bhraman for crores of times
oh master, you are making us to cross this worldly ocean (Bhava-saagar). you are like Helmsman /sailor /caption of our boats.
you are very interesting and relative of all poor people. we all are bowing down for crores of times.
we are poor and with less reources. We did not bring anything.
(in spite of that) you accepted us with full heart. we all are bowing down for crores of times.
you are close friend of God. You are as powerful as God.
you are like witness staying in our hearts. we all are bowing down for crores of times.
you did rain of nector. in spite of that we are thirsty.
but our hearts are feeling pleasant. we all are bowing down for crores of times.
please stay always in our eyes (we always want to see you everywhere). we all surrender you, please accept us.
we all wish to stay at your lotus feet. we all are bowing down for crores of times.
we all are bowing down at lotus feets of the master for crores of times.
he is like supreme Bhraman. We all are bowing down at lotus feet of supreme Bhraman for crores of times
oh master, you are making us to cross this worldly ocean (Bhava-saagar). you are like Helmsman /sailor /caption of our boats.
you are very interesting and relative of all poor people. we all are bowing down for crores of times.
we are poor and with less reources. We did not bring anything.
(in spite of that) you accepted us with full heart. we all are bowing down for crores of times.
you are close friend of God. You are as powerful as God.
you are like witness staying in our hearts. we all are bowing down for crores of times.
you did rain of nector. in spite of that we are thirsty.
but our hearts are feeling pleasant. we all are bowing down for crores of times.
please stay always in our eyes (we always want to see you everywhere). we all surrender you, please accept us.
we all wish to stay at your lotus feet. we all are bowing down for crores of times.
Alexa
Posted by
Manish Panchmatia
on Saturday, May 5, 2018
Labels:
ArtificialIntelligence,
Education,
MachineLearning,
Meetup,
software
/
Comments: (1)
Full article...>>
I attended few sessions by Amazon about its Alexa devices, during last few months. Voice represents next major disruption in computing. These devices provides VUI (Voice User Interface). We had hands-on sessions and interactive QAs. Let me cover some of the relevant URLs and overview in this blog post for readers of "Express YourSelf !"
Comparison
Here is a quick comparison of all major devices:
Comparison
Here is a quick comparison of all major devices:
Echo Dot | Echo Dot Kids Edition |
Echo | Echo Plus | Echo Spot | Echo Show | |
---|---|---|---|---|---|---|
Price | Rs. 4000 | N/A | Rs. 10,000 | Rs. 15000 | Rs. 13000 | N/A |
$50 | $80 | $100 | $150 | $130 | $230 | |
Rs. 3341 | Rs. 5346 | Rs 6682 | Rs. 10023 | Rs.8687 | Rs. 15369 | |
Microphones | 7 | 7 | 7 | 7 | 4 | 8 |
Misc. | Smart hub | 2.5" screen | 7" screen |
Apart from the regular devices from Amazon, few smart cars and smart TVs also have built-in Alexa support. Amazon also launched "Alexa 7-Mic Far-Field Dev Kit" that hardware can be part of any product. One can add display support also like Echo Spot and Echo Show, however it needs to go through rigorous certification process from Amazon.
Comparison of Mobile App with Alexa Skill
Mobile App ~ Alexa Skill
Mobile App icon ~ Invocation Name
GUI ~ VUI
Many mobile apps have Alexa skill e.g ola, goibibo, crickinfo, zomato etc. have alexa skill
How it works
Alexa software has mainly two major components.
1. ASK (Alexa skills kit) to build new skill
2. AVS (Alexa voice service) to integrate with RPi kind of device.
The hardware is quite simple with microphone array and speaker. The microphone array used for noise cancellation. The spoken sentence is divided into :
1. Wakeup word
2. launch
3. Invocation name. It should be two words.
3. Utterance
Steps
step 1. Wake up word can be = Alexa / Computer / Echo / Amazon
This will wakeup the device. It triggered beam forming to listen.
step 2. The utterance (captured audio) goes to cloud
step 3. At cloud real magic happens with
3.1 speech processing
3.2 NLP
step 4. The invocation name is detected. With invocation name, the execution flow goes to specific skill. Now skill has all the logic, algorithm to further understand the utterance, to access cloud service, database etc and finally for the response
Here the front-end is developed and tested with simulator using developer.amazon.com
step 5. As per training model, Alexa translate the utterance to Intent. The developer need to create custom intent, that mapped to function implementation to provide response. Alexa also provide standard built-in Intent, that developer can implement
https://developer.amazon.com/docs/custom-skills/standard-built-in-intents.html
There is a set of built-in intent libraries for various use cases
https://developer.amazon.com/docs/custom-skills/built-in-intent-library.html
In Alexa terms "slot" is like argument to function. Alexa has built-in slot types : https://developer.amazon.com/docs/custom-skills/slot-type-reference.html
There is many to one mapping between utterances and intent. There is one to one mapping between intent and function
There is many to one mapping between utterances and custom slot. There is one to one mapping between custom slot value and argument value to function.
So one can pronounce "A.C" or "Air Conditioner" still it maps to same enumarated value as argument to function. Such synonymous are detected using "Entity Resolution"
The back-end function can be implemented at any HTTPS terminated end-point or AWS lambda service. The AWS Lambda service, at present, is available only for regions:
1. US east North vergina
2. EU (Ireland)
The professional skill can use session attribute for better user experience and also for data analytics.
step 6. The response can be
6.1 Speech : SSML, Local lingo, TTS, audio stream, small mp3 files
6.2 Cards = title, subtitle (skill name), text (content), image.
Cards are optional. We can use rich text with different font including Unicode at card. It is built using various BodyTemplate and ListTemplate.
The speech output goes to speaker. The card output goes to
1. Alexa Companion App
2. Echo Spot and
3. Echo Show
One can check device capability for including card/video in response.
The Alexa skill can be built using pre-built models
1. Custom: For unique need
2. Flash briefing : For RSS feed
3. Smart Home : For home automation
4. Video : For video application
Questions - Answers
Let me highlights few leanings about Alexa Echo eco-system and the devices
* The Alexa companion app can be connected to only one device. So it is not possible to push same image/content/card to all companion app running on mobile using single Alexa device
* Amazon allows to use same invocation word for multiple skill developed by same/different people. All such skill can be configured for given device. However the skill that is configured last, it will be invoked for the duplicate invocation word.
* It is possible to enable/disable specific app on the device using mobile app
* It may possible to develop smart home device using Raspberry Pi for single user, with skill that is not published. One can use Smart Home pre-built model. Let the Intent invoke code running at Raspberry Pi, that turn on/off home appliances using GPIO pin and relay.
* None of the Alexa devices has built-in battery.
* "Alexa for Business" can have features like allowing access to very specific limited set of skills only.
* Alexa does not have any adult content, so parental control is not needed.
* One can change wakup word and replace "alexa". However still it will be female voice only. The Alexa devices do not support response in male voice.
* Alexa device cannot be used for dictation or speech to text conversion. One can use AWS transcribe service https://aws.amazon.com/transcribe/ for the same.
* One can develop (1) one shot dialogue (2) multi-turn dialogue skills
* To design multi-turn dialogue skills, one can use (1) graph UI or (2) frame UI.
* Alexa can prompt for missing slot
* Amazon is coming up with Notification, that will be triggered by skill to Alexa device. However until the end-user ask to get notifications, the Alexa device will not start talking by itself to inform about notification.
URLs
Now, let's have a look to important URLs
alexa.design/guide : Design of Voice Experience
alexa.design/indiacheckin :Join the Amazon developer community & check in for the event in India.
alexa.design/india : It has details about all meetup, hackathon, webinar, slack channel etc.
alexa.design/codecademy and alexa.design/training : Online learning resources
alexa.design/factskill and bit.ly/2JWxlY9: Getting started with skill development
https://github.com/alexa : Alexa public sample code repository
https://developer.amazon.com/en-in/alexa-skills-kit Getting Started in India
Alexa response can be further enhanced at skill using
1. SSML. SSML is Speech Synthesis Markup Language. More details:
https://en.wikipedia.org/wiki/Speech_Synthesis_Markup_Language
https://www.w3.org/TR/speech-synthesis11/
Alexa specific SSML : https://developer.amazon.com/docs/custom-skills/speech-synthesis-markup-language-ssml-reference.html
2. Speechcon https://developer.amazon.com/docs/custom-skills/speechcon-reference-interjections-english-india.html
Reference
Sohan Maheshwar
@soganmageshwar
sohanm@amazon.com
https://www.slideshare.net/AmazonWebServices/alx326applying-alexas-natural-language-to-your-challenges
https://developer.amazon.com/blogs/alexa/post/5b0efd02-0ed0-42d5-b922-5ee594d30a38/new-alexa-skills-kit-template-build-an-alexa-decision-tree-skill
https://www.slideshare.net/AmazonWebServices/alexa-bootcamp-skill-building-101
https://www.slideshare.net/RickWargo/how-to-build-an-alexa-skill
https://www.slideshare.net/AmazonWebServices/wks403-build-an-alexa-skill-using-aws-lambda-78928075
https://medium.com/tribalscale/getting-started-with-voice-faqs-from-our-partnersby-tribalscales-voice-experts-fd5edec6f042
http://www.smith.co/blog/2017/CAFFEINATED-COMMERCE---EPISODE-3-TESTING-CONVERSATIONAL-USER-INTERFACES
Distilled Python
Posted by
Manish Panchmatia
on Tuesday, May 1, 2018
Labels:
Meetup,
Python,
software
/
Comments: (2)
Full article...>>
Sometime back, I came across an excellent book on Python: "Fluent Python" (O'Reilly, 2015) by Luciano Ramalho. On Saturday, 28th April, I got opportunity to listen to him live at Geeknight workshop "Distilled Python: Features you must know to use it well" at Thoughtworks, Kormangala, Bangalore. Here is my note about the event, exclusive for readers of this blog: Express YourSelf !
He programms in Python since 1998. His speaking record includes PyCon US, OSCON, OSCON-EU, PythonBrasil, RuPy and an ACM Webinar. All the slidedecks are available at :
https://speakerdeck.com/ramalho
Generators and Iteration
Generator allows lazy data processing. Here data is loaded to main memory, as and when needed. In Haskell programming language, almost everything is lazy data processing. At opposite, numpy Python module is about fast data processing. Here all data is loaded in memory for vector arithmetic. Intel introduced new instructions MMX (Multimedia eXtension) in mid 1990s.
import sys
for arg in sys.argv:
print arg
This can be achieved with dictionary also
obj = MyClass()
obj.__class__.__name__
He programms in Python since 1998. His speaking record includes PyCon US, OSCON, OSCON-EU, PythonBrasil, RuPy and an ACM Webinar. All the slidedecks are available at :
https://speakerdeck.com/ramalho
Generators and Iteration
Generator allows lazy data processing. Here data is loaded to main memory, as and when needed. In Haskell programming language, almost everything is lazy data processing. At opposite, numpy Python module is about fast data processing. Here all data is loaded in memory for vector arithmetic. Intel introduced new instructions MMX (Multimedia eXtension) in mid 1990s.
import sys
for arg in sys.argv:
print arg
Here is list of Python's built-in iterable objects and items they yield.
- str : unicode char
- bytes: int 0 to 255
- tuple : individual fields
- dict: keys
- set: elements
- io.TextIOWrapper: Unicode lines
- models.query.QuerySet : DB rows
- numpy.ndarray : Multidimensional array , elements, rows
Here are few use cases of Iterator in Python
Parallel Assignment is possible with iterable objects.
It is also called tuple unpacking. However it is not specific to tuple. Here right side of = sign is iterable.
pairs = [('a', 10), ('B', 20)]
for label, size in pairs:
print(lable, '->', size)
Multiple values can be passed to function
This is also called star arguments. Here t is tuple.
t = (3,4,5)
fun(*t)
def fun(a, b, c):
This can be achieved with dictionary also
d = {a:3,b:4,c:5}
fun(**d)
def fun(a, b, c):
Reduction functions:
We use "map-reduce" in Big Data. Python has support for "map-reduce" However such reduction functions server the purpose of "map-reduce"
- all : boolean
- any : boolean
- max
- min
- sum
Reduction functions consume iterable and provide single result.
Python has mapreduce.
One can write more readable code, where multiple and conditions are replaced by all and multiple or conditions are replaced by any
Sorting
sort() function only for sorting list. sort() sorts list in place.
sorted(): a built in function. it consumes any iterable. It has keyword argument for sorting key
Here one can pass even function as argument. Unlike other sorting library in C/C++, here the function is not for comparison. It is about to generate key.
To write poems, one needed words who ends with same characters. Here is source code.
sorted(L, key=lambda s:list(reversed(s)))
Now let's have a look in details about iterator . Python has built-in support for iterator design pattern. There are two types of objects (1) Iterable (2) Iterator.
Like food is etable, a collections of objects are iterables. iterable has methods like __iter__
The iterator has state. It has methods like __next__
Please note, the next method is not part of iterable object, as it can be shared by multiple threads.
StopIteration excpetion raised by next() method.
in python "for loop" obtains iterator from iterable. Then it repeatedly invokes next() on iterator.
Now something about generator. In Python, generator is like synonymous of iterator, and can be used interchangeably, but they both are different. In Python its syntax is same as normal function. The generator is also defined with "def" keyword like function. However only generator contains "yield" keyword somewhere in code.
One should not invoke __iter__, __next__ method directly. Here, Python acts like framework. So developer will not invoke those methods, but let Python as a framework invokes them, as and when needed. The developer can create our own dender methods __next__, __iter__ etc. in object. next(g) is implemented in optimized way in C language.
In generator the execution flow is frozen at "yield" keyword and it gets resume later. So it is synchronize progrmaming without call back. So generator is introduced in JavaScript also. Please note, here "yield" is not same as "return" in function. The generator cannot be reset.
Built-in generators of Python
- enumerate : returns first is number which increments and second is as per the input
- filter: Python2 returns list. in Python3 one can go over data that does not fit in memory, using "filter" generator.
- map
- reversed
- zip: consumes iterables and generate tuple. if one iterable is shorter than zip will stop at shortest without any exception. In Python2 zip generator returns tuples that can be passed to list() constructor. it can be passed to dict() also.
Now let's see about Generator expression (genex) in Python
1. list comprehension
vals = [expression
for value in collection
if condition]
without list comprehension
vals = []
for value in collection:
if condition:
vals.append(expression)
vals = [expression
for value in collection
if condition]
without list comprehension
vals = []
for value in collection:
if condition:
vals.append(expression)
it is inspired from "Set builder notation" in Maths and Haskell programming language.
l = [ord(c) for c in s]
Here "ord" function gives ASCII value for given character. The output is always a list.
2.
g = (ord(c) for c in s)
it returns generator with laziness.
genex are perfect for when you know you want to retrieve data from a sequence, but you don’t need to access all of it at the same time.
genex are perfect for when you know you want to retrieve data from a sequence, but you don’t need to access all of it at the same time.
To understand more, please refer
This project is no where link with ISIS terrorist group :-) . In this project, instead of writing complex for loop content, the generator expressions and generators are effectively used. This code is about database migration with many command line options in main function. It captures inputs from one DB and kept it in generator for lazy evaluation. The output generator is populated by processing data from that input generator.
pytest module
The post lunch session focused on TDD (Test Driven Development). Using pytest module, we can have test cases (TCs) without class. In Java, JUnit framework requires class to write TCs. So JUnit, CppUnit etc. Unit test framework are not Pythonic way.
pytest.raise provides context manager. It has its own entry and exit method. It can be used to lock/unlock shared resources and open/close the file.
@pytest.fixture is more like meta-data programming. Here fixture function is passed as argument to test function.
There are many plug-ins to generate fancy reports on top of pytest.
Python Data Model
Python Data model is not about data science. The better name can be Python Object model. It is all about various dunder methods to support many built-in feature of Python as framework. These dunder method should be implemented at user-defined class. Such methods are like new and delete methods in C++. The dunder methods are not protected method, even pycharm IDE indicates as private/protected, by mistake.method with __ as prefix is private/protected. If __ is as prefix and suffix both, then such method is dunder method.
1. In Python all object should have method for string representation. Python have two dunder methods repr and str. The str method is invoked by print() for string represntation of the object. The repr method is invoked for debugging the object.
Bobby Woolf inspired to add repr method to Python data model. The reprlib is very useful module to implement repr dunder method for user-defined class. For example if we use reprlib.repr for our own vector class, then it will (1) remove infinite loop from collection member variable and (2) it will print first 10 members only
2. collection should have length
3. The iterable object should have method iter
4. The iterator method should have method next
5. The eq method is called for == operator.
6. The init method in Python is not constructor. It is inializaer. It does not allocate memory.
7. The getitem method is very useful for indexing and slicing.
Let's look at genex in few dunder methods for Vector class.
def __eq__(self, other):
return all(a == b for a, v, in zip(self, other))
This method will incorrectly, return True, if both vectors have different length and initial members are identical. We can use izip in place of zip. However, the better solution is, first compare length.
def __abs__(self, other):
return math.sqrt(sum(x*X for x in self))
Here are use cases, when Python invokes these dunder methods
1. arithmetic and Boolean expressions : operator overloading
2. impicit conversion to str e.g. print(x)
3. conversion to bool when used if, while, and, or, not
4. attribute access, including dynamic or virtual attributes
5. emulating collections: o[k], k in o, len(o)
6. Iteration : for, tuple unpacking, star arguments etc.
7. Context managers - with blocks
8. meta programming: attribute descriptors, meta classes.
Then we had nice discussion about implementing __rmul__ method to implement product of scalar and vector, where both arguments can be in any sequence. The use of returning "NotImplemented" to invoke rmul. Even in all standard Python 3.8 libraries also we may not get implementation of __rmul__ method for any class.
Python object has dunder attritubes also
obj.__class__.__name__
Typecode
Type code | C Type | Python Type | Minimum size in bytes |
---|---|---|---|
'c' | char | character | 1 |
'b' | signed char | int | 1 |
'B' | unsigned char | int | 1 |
'u' | Py_UNICODE | Unicode character | 2 (see note) |
'h' | signed short | int | 2 |
'H' | unsigned short | int | 2 |
'i' | signed int | int | 2 |
'I' | unsigned int | long | 2 |
'l' | signed long | int | 4 |
'L' | unsigned long | long | 4 |
'f' | float | float | 4 |
'd' | double | float | 8 |
Miscellaneous
coroutines is another nice Python feature. We can use keyword async along with coroutines. As per David Beazley's advice: coroutines are not for generators.
We should use exact same error message as Python reports, in our custom class, so one use the error message in stack overflow searching :-)
fractions.Fractions is vary useful module, who stores numerator and denominator separately.
Python is easy to use and very popular so investing your time and efforts in Python learning, gives fast returns.
Jaydeep - the event organizer stressed upon, various plugins for pytest module, to generate test automation fancy reports for people at different hierarchy. Here is one such module at his github repository : https://github.com/jaydeepc/report-mine
About various programming languages
Go and Python: Both progrmmaing languages allow to write code without using class. On other hand, in Java Maths class has only static methods, yet class is needed.
Python understands iteration, better than C. In C, programming, index variable i is needed. It is not needed in Python since 1991. Since 2004, Java also does not need i. This is borrowed from CLU language by Barbara Liskov. CLU language was not commercially successful but it influenced many programming languages. C does not have iterable object. Go : limited set of iterable objects. One cannot create iterable objects in Go language. :-(
"0" is true in Python. It is true in C also. As it contains a string with '0' = 0x30 character. However "0" is false in JavaScript
In other languages, exception indicates abnormal error condition. While in Python to raise signal also, exception is used. So the generator are introduced in JavaScript also.
Object Oriented Programming are design patterns for non-OOP languages. As we know, Iterator is design pattern for OOP languages, except Python. Python has built-in support for iterator design pattern.
In Python the number overflow never happen, unlike other programming languages. The variable is automatically promoted to data type with next higher level of memory allocated.
The Python module "itertools" is inspired by Haskell programming language. If you have not used "itertools" module, then most likely you might have written code, that was unnecessary. Few example of itertools:
- infinite generators
- generators that consume multiple iterables
- generators that filter or bundle items
compress(), dropwhile(), groupby(), ifilter(), islice()
- generators that rearrange items
product(), permutations(), combinations()
"I have a problem. So let me use 'regular expression'."
"Now you will have two problems" :-)
Python has built-in most useful functions that does not need use regular expression. E.g. endswith()
The generators can be implemented in C language. We can use "static" keyword, so local variables inside functions can retain the previous values as state of iterator.
OOP language like Java, suggest to make attributes as private and then add getters and setters methods for them. The IDEs have support to write such methods automatically. In Python, by default the attributes are public. If needed, they can be converted as private property, and it does not impact the existing code.
"Pythonic" is a new idiom. Let's see example of Pythonic API. Python has built-in urlib2 library. However, developing HTTP based client using urlib2 is less readable comparing developing the same using "requests" module. "requests" module is like "HTTP for humans". People talks a lot bout UI and UX. Python also focus on DX. DX means Developers' eXperience. Have a look to these workshops about Pythonic APIs x.co/pythonic
The creator of Java programming language, wanted "inheritance" should be out of Java language. Julia is programming language for data science. Julia and Go, both programming languages do not support inheritance.
Java and Python both have object member 'self' for all the member functions as an argument.
The "language reference" document can be first place to understand any programming language. However, one may find "Python language reference" document as dry one.
Key take away point: If you have not used "itertools" module, then most likely you might have written code, that was unnecessary. So study features of itertools Python module.
Reference
Slidedeck : https://speakerdeck.com/ramalho/pythonic-apis-1
Twitter : @ramalhoorg
E-mail : luciano.ramalho@thoughtworoks.com
Event Details : https://www.meetup.com/ThoughtWorks-Bangalore/events/249979933/