Aryan Singh's World

Data Science, Statistics, ML, Deep Learning

Tensorflow 2.0 in 2 minutes

Tensorflow 2.0-alpha was released a couple of days ago with a bunch of exciting features. It can be installed by following command:

pip install -U –pre tensorflow

In this post I explore the 17 most key features among them. The purpose is to make this short, crisp but touch on all the major pointers.

  1. Improvement in tf.keras high level API: Tensorflow 2.0 takes the compatibility between imperative Keras and DAG driven tensorflow to next level by adopting tf.keras to its core. This will make prototyping and productionizing deep learning models fast. Also, this will engage and bring more developers towards deep learning, keras being more intuitive.
  2. Eager execution by default: No need to create an interactive session to execute the graph. TF 2.0 introduces the eager execution by default moving all the session related boilerplate under the hood.
  3. Compact and improved documentation: TF 2.0 offers better organized documentation. Most of it is available here: https://www.tensorflow.org/versions/r2.0/api_docs/python/tf
  4. Clarity: 2.0 takes clarity to the next level by removing various duplicate functionalities like multiple versions of GRU and LSTM cells available. 2.0 takes care of choosing the optimum node according to hardware giving developer a single unified library to choose from for instance one implementation of LSTM and one for GRU.
  5. Low Level API: Full low level API in tf.raw_ops with inheritable interfaces for variables, checkpoints and layers to define your own components.
  6. Easy Up-gradation: Conversion script in tf_upgrade_v2 to convert TF 1.0 code into TF 2.0 code automatically. Just write: !tf_upgrade_v2 –infile <input_file> –outfile <output_file>
  7. Backward compatibility: Comes with a separate backward compatibility module tf.compat.v1 for getting the older components.
  8. One optimizer, one losses module, one layers module: Unified optimizers module in tf.keras.optimizer.*. Similarly one losses and one layers module under tf.keras.losses.* and tf.keras.layers.*.
  9. Better graphical visualization: 2.0 gives better graph visualizations in Tensorboard even for keras models.
  10. Easy to distribute: Provides more options for scaling and multi GPU training via tf.distribute.Strategy module. strategy = tf.distribute.MirroredStrategy()
    with strategy.scope():
    <define the model here>
  11. Save and Import keras model: Easy to save and load the keras models by using tf.keras.experimental.*.
  12. Run Keras On TPUs: 2.0 comes with tf.distribute.experimental.TPUStrategy() that will allow the keras code to run on TPUs.
  13. New datasets available: 2.0 comes with new datasets to test the models on in vision, audio and text domain.
  14. More pre-trained models at TF Hub: More pre-trained models from the world of NLP and Vision available at Tensorflow Hub.
  15. Improved error reporting: Improved error reporting with exact line number and full call stack.
  16. TFFederated: TF federated to support federated learning on edge devices.
  17. Swift support and Fast AI: 2.0 to come with a Swift library. Jeremy Howard will be delivering a course on the same.

Source: Tensorflow Dev Summit 2019

Camaraderie Of Silence

In this poem I talk about the times of silence where I sit alone and think about life, goals and the problems that keep me awake at night.

Zero, Vaccum, tranquility, hush are the diamonds in the life’s rough,
Waging lonely battles against life’s frivolous trouphs.
In harrowing night where becons a tryst with the longing to wither the time,
The power of silence rallies the intellect to stifle this crime.

Alone I sit waiting for the train of thoughts,
Sometimes its musings somedays its an aweful lot.
The vine of challenges encircles to thicken the plot,
Then I draw the sword of logic to cut through these knots.

The time that makes the philosophers think, the time that changes the rulers to kings.
It’s that time of the day which solitude brings,
Where silence is the companion in the troubled brinks.

Things go quieter as the times go past,
Mind aches for a companion to share the feel of outcast.
The fire of melancholy burns the cauldron of heart,
Enraging the blood to add fuel for a quest miles apart.

Now I have made friends with the lonesome days,
Now i hold hands with the quiet nights.
For its the time of the day that gives wings to the thought’s flight,
My comate my crony, towards the ultimate light.

Rendezvous With The Past

This poem talks about the poet’s desire to do time travel to his past to advice his younger self towards a path of happiness.

There reeks a sense of deep longing,
A longing to meet the alter ego of my lost past.
To travel through the folds of the time dust,
To meet the boy squealing under the life’s thrust.

To stroke his head with a kind touch,
To soothe his predicaments with a sensible advice.
To ask him not to be scared of the life’s vice,
To ask him not to worry about that bully’s size.

To ask him to tread the Invictus paths,
To tell him that he is good enough for every task.
To tell him that he is a lovable soul,
To convince him to take that girl out for a stroll.

To tell him to turn those tears into fire,
To press him not to kill his own for other’s desires.
To ask him to take it easy on himself,
To tell him its okay to fail in some tests.

I want to kill all those negative thoughts,
I want to soothe his deep insecurities with wisdom of life’s sorts.
I want to tell him its fine chase his dreams,
I want to give the wings back to his stunted teens.

To propel Singh to set the stage on fire,
To inspire him to punch back when the straits are dire.
O lord give me a chance to make that journey at last,
To save the childhood of your troubled son, in this rendezvous with the debilitated past.

Hoarder Of Memories

I walk the paths of the dusty terrain,
I dance to the sounds of the falling rain.

I enjoy the first rays of the morning sun,
I adore the innocence of the children’s fun.

I love to laugh on a bad joke,
I enjoy the humour of a sarcastic poke.

I enjoy the journey to the places unknown,
I cherish the perspective of a stranger forlorn.

I love to see the dog wiggle its tail to care,
I love to help the friends going through times despair.

I love to get beguiled by the beauty of a women’s eyes,
I love to hug the people full of despise.

Because I know when the end is near,
I will reflect upon these good times with smiles and flair.

The money is a myth so is the fame,
I am the hoarder of memories that flash in the light of my extinguishing flame.

Mai yaadon ka sudagar hoon nikla hu yaadon se bharne apna pitara,

Kuch khushnuma si hain, kuchh ranjo ghum ki hain toh kya malal,

Aji agar ye zakhm lete hain kisi ka naam toh kuch naam marham vaale bhi toh hain.

Choir Of Dreams

There is a land of motley musings,
Beyond the horizon where clouds float.

It houses the adobe of fluttering dreams,
Where the mind goes for its nightly stroll.

While on its excursion through the dim and lit halls,
It discovers a canvas in the stream of thoughts.

Some faces flash on and off, most known yet some unknown,
Some look at me with a kind gaze, while others with a vicious smirk.

Sometimes there is a resolute knight, fighting the dismaying desolation of war,
Sometimes appears a crumbling prisoner consuming itself in the guilt’s core.

Sometimes I meet a scared child looking for the familiar touch of care,
And some nights it is an apparition, threatening to tear my soul with a spare.

Somedays the visual of a cheering crowd coddling over every move of mine,
Sometimes its a story of severe strife that behooves me to struggle against that plight.

Every night when I close my eyes in this world of mortal scenes,
The mind opens a cornucopia to the choir of my dreams.

Face Of God

I saw the face of god in the laughter of a child,
I saw it in the zeal of a bee carrying nectar to the hive.

I saw it in the eyes of a cuddling mother,
I saw it in the sweat of a struggling potter.

I saw it in the mascara laden eyes of a happy bride,
I saw it In the serenity of the ocean after a tide.

I saw it in the wisdom of old and wise,
I saw it in the rays of a beach sunrise.

I saw it in the blessing of elders,
I saw it in the honour of a vailant soldier.

Its when I saw within, that I realised,
That he lives in the hearts of those devoid of pride.

That he breathes through the kindness of one’s actions,
The face is all but a mere reflection.

Dream Of Heavens

Sometimes I close my eyes to explore the darkest realms of sleep

When the dreams go darker and the night becomes mellow, I see an angel knocking on the door

The angel so beautiful that her beauty transcends the universe, her smile a blessing of gods

A beauty so rare that her touch makes me valuable, her gaze makes me surrender

Her lips, her eyes, her little perfect ears, her body, her hair is what makes this life worth living

Because it can’t be real that someone so perfect touches my life everyday, sometimes i think its all but a dream of heavens.

Roar of the warrior within

Come fight a little in the cradle of this burning log,
Come fight a little to right what’s wrong.

Don’t supress the voice that vanquishes the swines,
Oh come hither with your wrath, run fear down their spines.

Tear down the protection of that seed coat,
Within the storms let the fleet float.

For you are the master of the universe beats,
You are the fire that the dragon breathes.

Let them see the flare of that supressed flame,
Let them know who is running the end game.

Fight to last breath come what may,
Let them know to whom the legends pray.

An ode to the traveller

Again he saunters into the boulevard of life,

Tired, Disheveled, the wear of sojourn arching his back.

But his thirst is ravenous, the hunger insatiable,

The hunger to win, the hunger to strive, it fuels the senses, fires the drive

As he flings away the baggage of foes, packs the sac with words of wise

His fervour becons with excitement of uncharted lands, In his eyes the crimson of pluck gallores

For at heart he is but a traveller, his life a procession of uncharted dreams

And again he augurs on another path, a path more perilous, a path more beguile,

Oh! he is all but an undaunted soul, For He would die on the road than at home lie.

How to choose the Machine Learning algorithm to use for a problem?

The choice of machine learning algorithm to solve a particular problem is very hard to determine before trying a bunch of algorithms along with hyperparameter optimisation. But there are some pointers that can be kept in mind while figuring out the right algorithm:

1. Time Series Data: For data having one dependent variable in the form of time sequence algorithms like ARIMA or sequence models like LSTM can be benchmarked to find the optimum solution.

2. Speech/ Text Analytics: Probably a deep learning based approach along with sequence to sequence models like RNN and LSTM can be a good start.

3. Text Classification: Sequence models like HMM, CRF and LSTM can be tried for this solution.

4. Structured Data(Regression): Linear regression can be used as baseline, followed by SVM regression followed by using non linear kernels like rbf. Tree based ensemble models like Random Forrest and XGBoost should be tried for a more intuitive solution.

5. Structured Data(Classification): We can start with Logistic Regression for baseline. It also explains the importance of each of the dependent variables in terms of the coefficient. Furthermore, SVM, Random Forrest and XGBoost can be tried. If we have a large number of training examples and better hardware then solution based on deep learning along with appropriate activation functions like softmax(Multiclass) or sigmoid(binary) can be used.

6. Image/Video based Data: For image/video based data a pre trained DL based network is a good starting point. Particularly tried and tested architectures like VGG and Resnet 50 trained on Image net dataset can be used and the final few layers can be retrained to tail it to our particular problem. For real time object detection YOLO is a very elegant solution and can be given a try.