Useful Tips for Tensorflow Newbies

Tensorflow is one of the most widely used Deep Learning frameworks. In this post, I share some tips I had noted while learning, and it may be useful for you if you start from scratch.

Placeholders

Placeholder is used to assign a latent value during operations of the training phase.

While defining a placeholder with a type of value, the types should be inherited from the package, i.e. Tensorflow.Float32 instead of the standard float data type.

When it is needed to execute a tensorflow operation inline, the approach  below is useful


sess = tf.Session()
sess.run(variable_name)

Example:


x = tf.placeholder(tf.int32)
y = tf.placeholder(tf.int32)

#we define the add operation, notice that it belongs to the method provided by the tensorflow library
added = tf.add(x,y)

#execution
sess.run(added,feed_dict={x:50, y:40})

Constants

These are the most simple variable types you can use in your neural network. Here an example


import numpy as np

mat1 = tf.constant(np.array([[1.0,2.0]]))
mat2 = tf.constant(np.array([[3.0],[4.0]]))

#we now define the operation of multiplying two matrices, in shapes of (1, 2) and (2, 1)
multiplied = tf.matmul(mat1,mat2)

#and finally we execute the define operation in the tensorflow environment
sess.run(multiplied)

Constants, variables, placeholders are similar objects in Tensorflow. For example, you can multiply a placeholder with a variable or a constant without having any error. The main difference is the purpose of use. If you want to add a latent value to an object during the training phase, the placeholder class is the convenient one.

New Year Wishes

2018 was a year of change for me. Significant changes bring many difficulties, and yes, this was also the year of problems for me at the same time. Adaptation is not only needed for animals to live but we humans also have to be capable to adapt ourselves to the new environments. When you do nothing and watch others’ living those changes, it maybe seems very simple. But it’s not… I hope 2019 will be the year of being more powerful. Despite the new expected or unexpected changes that life will bring, I wish to become the person who swims well and accelerates his speed becoming a part of the waves. Wish all of you happy surfing!

A Book Recommendation: “Look at You Now: My Journey from Shame to Strength”

Without giving any spoiler, I strongly recommend reading this book, I read it in just five days! By the way, I’m still behind my goal of reading eight books in 2018. It is certainly because of my poor book choices. The thing that makes a book readable for you is not the number of stars given by other users. Reading a book is a very special thing, you impersonalize yourself with the book. So a 5-stars given by a person who has a totally different character than you doesn’t matter. This is my lesson-learned of 2018.

 

Worst Parts of Living in Italy as a Foreigner

Italy is a wonderful country with its history, geographic location, culture, food, and many other things. These are the primary reasons that make the country attractable. However, when you decide to live in Italy, you face with thousands of difficulties after your first arrival. Italy is the country of procedures, and the ones who want to spend half of their time with these procedures keep living in Italy. The others are being messed with unreasonable difficulties and decide to leave the country. Let me give you some examples from our daily life here in Milan.

  • As an international student, you need to renew your permit of stay each year, even you are a Ph.D. student. There is not any agreement or integration between university and government which facilitates your stay. You need to get your documents from university each year and then follow the requirements for applying for a stay permit. If you are lucky, you can get an appointment date to 4-5 months later, and it takes 40 days to get your card after attending the appointment. I am not kidding, it takes almost 6-7 months to renew your yearly permit of stay. In other words, you spend half of the year to get access to stay on the following mid-year. Since you don’t have a valid stay permit for 6 months, you are forbidden to visit any European country because with the appointment paper, you can only go to your home country. You should have the card, not the paper to visit France for example.
  • Even you have an appointment date for stay permit, the officers may not work on that day, because they can give decisions on their own. In my case, my wife was having an appointment on Saturday, we went to the Police station with our official appointment paper, but they told us that their colleagues decided not to work on that day, and we should come by Monday.
  • Most of the government organizations do not support their online valid operations. You need to go to the offices as a person and wait for hours to get the hard-copy of documents.
  • For each document, Italy government requests a timber costing 16 euro. In many cases, you need 2 timbers, which cost 32 euro in total. You buy your timber from the shops located in the streets, and you collide your timber into any document to make it official. In some cases, the machine which generates the timber doesn’t work, because it is connected to the government computers. In a single year, I bought 40+ timbers and I paid more than 650 euro for the timbers. (I am not including the application fees for each process)
  • If you are a student and want to work in a company, you should change the stay permit from student to employee. This process nearly takes 3 months. You are very lucky if you haven’t heard the words of Nulla Osta so far.
  • When you are ready to work in a company, you should prove that your house is convenient to live. In fact, your house is already recognized by the municipality, but it doesn’t matter. You should find and call a certified engineer to validate your living conditions in the house and pay him 100 euro. But before that, you should have the certificates, plans of the house, and if you don’t have, you should pay 600 euro and spend days to get those documents. Each year, the validity of approval expires, so you should find and call a certified engineer and pay 100 euro.
  • Most of the employees working in local authorities (municipality, police office, etc) do not know English. So you should use your body language capabilities.
  • If you make a money transfer from a bank account to another, it needs to pass a day. Only in very few examples, such as internal bank transfers between Intesa San Paolo accounts, you can transfer money on the same day. In 99% of cases, you need to wait, and also pay 1 euro for each transfer.
  • If there is a cargo or a document sent to your address with Italy Postal Office service and you are not at home, you need to take it from the central Postal Office. When you go there, you should wait at least 2-3 hours other people, and after all of that time, you may not have your package since it is lost.
  • After being graduated, it takes 4 months to get your diplome. In that time, your stay permit maybe overdue, so return to your home country, and apply for a tourist visa to come back and get your document. If you plan to stay in Italy and apply for a job, you cannot make that application without your diplome.

There are many different stories which make our life messy here. In my calculation, I spent nearly 720+ hours of dedicated time for my official things in a single year. My house is full of documents. And the most interesting thing is, Italians are okay with this. There is no need to make any progress to make life easier.

In my following post, I will explain the best parts of living Italy.

A Useful Deep Learning Specialization Course: Structuring Machine Learning Projects

I have been attending deeplearning.ai’s specialization courses for a while, and I’ve completed the second part of the series this week. In this course, Prof Andrew Ng shares his experiences and best practices to build efficient machine learning pipelines. Although there is not any programming assignment in the course syllabus, there are 2 case studies that are very close to real-world experiments, and it is expected to give the right decisions on these scenarios. I strongly recommend practicing this short training.

An Article of Vigna and Kaplan about how Media bias impacts Elections

Link to the article

THE FOX NEWS EFFECT: MEDIA BIAS AND VOTING*
STEFANO DELLA VIGNA AND ETHAN KAPLAN

Does media bias affect voting? We analyze the entry of Fox News in able markets and its impact on voting. Between October 1996 and November 2000, the conservative Fox News Channel was introduced in the cable programming of 20 percent of U. S. towns. Fox News availability in 2000 appears to be largely idiosyncratic, conditional on a set of controls. Using a data set of voting data for 9,256 towns, we investigate if Republicans gained vote share in towns where Fox News entered the cable market by the year 2000. We find a significant effect of the introduction of Fox News on the vote share in Presidential elections between 1996 and 2000. Republicans gained 0.4 to 0.7 percentage points in the towns that broadcast Fox News. Fox News also affected voter turnout and the Republican vote share in the Senate. Our estimates imply that Fox News convinced 3 to 28 percent of its viewers to vote Republican, depending on the audience measure. The Fox News effect could be a temporary learning effect for rational voters, or a permanent effect for nonrational voters subject to persuasion

 

Good news.. I will be joining MIT Media Lab

As of November, I have started my 2nd year of Ph.D. study at Politecnico Milano. By the way, there was an opportunity for the students to apply MIT for a research stay abroad, and even there were too many requirements to get an acceptance, I was lucky that I’ve been successful at all, and I’ve been awarded a Rocca fellowship for two semesters at MIT! It will be a wonderful experience to be there, and I hope everything goes well, I can learn a lot and advance my current research many steps forward. The lab I will work with is Prof. Deb Roy’s Social Machines Lab, where they build advanced models for understanding human behavior in online social networks.

 

For football fans, life without football is possible, and it’s probably better!

Football is a huge balloon that contains billions of people and people from all over the world are strongly committed to football teams, go to the stadiums, watch TV games and spend their time reading the latest sports news, social media messages. It is very interesting that I was one of these people until recently. But after a few attempts, I’ve managed to leave all kinds of football-related activities, and now I have more time to discover things I’m not aware of. For example, I’ve completed reading two great books in the last two months, and I have time to clear and renew my mind to think more clearly. There are a lot of things I’ve started to do and I think it’s a complete change, like quitting smoking.