Tivadar Danka Profile picture
Apr 15, 2021 9 tweets 3 min read Read on X
In machine learning, the inner product (or dot product) of vectors is often used to measure similarity.

However, the formula is far from revealing. What does the sum of coordinate products have to do with similarity?

There is a very simple geometric explanation!

🧵 👇🏽
There are two key things to observe.

First, the inner product is linear in both variables. This property is called bilinearity.
Second, is that the inner product is zero if the vectors are orthogonal.
With these, given an 𝑦, we can decompose 𝑥 into two components: one is orthogonal, while the other is parallel to 𝑦.

So, because of the bilinearity, the inner product equals to the inner product of 𝑦 and the parallel component of 𝑥.
If we write 𝑦 as a scalar multiple of 𝑥, we can see that their inner product can be expressed in terms of the magnitude of 𝑦 and the scalar.
In addition, if we assume that 𝑥 and 𝑦 have unit magnitude, the inner product is even simpler: it describes the scaling factor between 𝑦 and the orthogonal projection of 𝑥 onto 𝑦.

Note that this factor is in [-1, 1]. (It is negative if the directions are opposite.)
There is more. Now comes the really interesting part!

Let's denote the angle between 𝑥 and 𝑦 by α. The scaling factor r equals the cosine of α!

(Recall that we assume that 𝑥 and 𝑦 have unit magnitude.)
If the vectors don't have unit magnitude, we can simply scale them.

The inner product of the scaled vectors is called cosine similarity.

This is probably how you know this quantity. Now you see why!
If you have liked this thread, consider following me and hitting a like/retweet on the first tweet of the thread!

I regularly post simple explanations of seemingly complicated concepts in machine learning, make sure you don't miss out on the next one!

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Tivadar Danka

Tivadar Danka Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @TivadarDanka

Jun 8
Differentiation reveals much more than the slope of the tangent plane.

We like to think about it that way, but from a different angle, differentiation is the same as an approximation with a linear function. This allows us to greatly generalize the concept.

Let's see why! Image
By definition, the derivative of a function at the point 𝑎 is defined by the limit of the difference quotient, representing the rate of change. Image
In geometric terms, the differential quotient represents the slope of the line between two points of the function's graph. Image
Read 12 tweets
Jun 6
Most people see neural networks as magic.

But at their core, they’re just graphs. And those are built from math so simple, you learned it in high school.

Here’s how computational graphs make deep learning possible, and why they’re the real MVP of machine learning. Image
Representing graphs as matrices unlocked new discoveries in both CS and math.

Similarly, viewing neural networks as computational graphs unlocked modern ML.

The magic is in the representation. Image
At a macro level, a neural network is a composition of a sequence of functions:

N(x) = Softmax(Linear₁(Relu(Linear₂(x))))

At a micro level:

A graph of operations + variables.

• Each variable becomes a node.
• Each operation becomes an edge. Image
Read 6 tweets
Jun 4
This will surprise you: sine and cosine are orthogonal to each other.

What does orthogonality even mean for functions? In this thread, we'll use the superpower of abstraction to go far beyond our intuition.

We'll also revolutionize science on the way. Image
Our journey ahead has three milestones. We'll

1. generalize the concept of a vector,
2. show what angles really are,
3. and see what functions have to do with all this.

Here we go!
Let's start with vectors. On the plane, vectors are simply arrows.

The concept of angle is intuitive as well. According to Wikipedia, an angle “is the figure formed by two rays”.

How can we define this for functions? Image
Read 18 tweets
Jun 3
In machine learning, we use the dot product every day.

However, its definition is far from revealing. For instance, what does it have to do with similarity?

There is a beautiful geometric explanation behind. Image
By definition, the dot product (or inner product) of two vectors is defined by the sum of coordinate products. Image
To peek behind the curtain, there are three key properties that we have to understand.

First, the dot product is linear in both variables. This property is called bilinearity. Image
Read 15 tweets
May 7
Behold one of the mightiest tools in mathematics: the camel principle.

I am dead serious. Deep down, this tiny rule is the cog in many methods. Ones that you use every day.

Here is what it is, how it works, and why it is essential. Image
First, the story.

The old Arab passes away, leaving half of his fortune to his eldest son, third to his middle son, and ninth to his smallest.

Upon opening the stable, they realize that the old man had 17 camels. Image
This is a problem, as they cannot split 17 camels into 1/2, 1/3, and 1/9 without cutting some in half.

So, they turn to the wise neighbor for advice. Image
Read 18 tweets
Mar 22
I am Hungarian, living in Hungary for 35 years. Everything is government propaganda in this thread.

Let me provide all the context.

Learn from this, and maybe your country can succeed in stopping an authoritarian takeover, in which Hungary have failed.

"1. No income tax for women with at least two children for life."

This is an election hack, meant to buy votes for the upcoming 2026 election. Fidesz (Hungary's ruling party) is significantly down in the polls after it was leaked that a convicted p*d*ph*le accessory was given a presidential pardon.

Hell, they even let a child p*rn*gr*phy wholesaler with 96000 images on his computer walk away with ~$1500 fine. (Check en.wikipedia.org/wiki/G%C3%A1bo… if you don't believe me.)

Thus, the government is scraping to buy back the trust of families.

Even if it wasn't an empty promise, waiving the income tax is unrealistic for budgetary reasons. Hungary's economy is in the toilet.
"3. Housing incentives for young couples.

Offers a low interest loan for couples raising or committing to having one child or more."

This loan is another propaganda trick. In practice, this loan resulted in the biggest housing crisis of the country's history, because all it did was raise the price of every real estate by the amount of the loan, making real estate ownership virtually impossible for the young generation.
Read 10 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(