Skip to main content

Command Palette

Search for a command to run...

Einstein summation or einsum

Updated
โ€ข1 min read
R

I am a passionate AI and machine learning expert with extensive experience in deep learning, TensorFlow, and advanced data analytics. Having completed numerous specializations and projects, I have a wealth of knowledge and practical insights into the field. I am sharing my journey and expertise through detailed articles on neural networks, deep learning frameworks, and the latest advancements in AI technology.

So today I was studying the paper dEFEND: Explainable Fake News Detection and their code, where there was a line using einsum, short for Einstein summation.

What is einsum?

So basically, you give it an equation, and it will give you output according to the equation. For example, if we have two matrices m1 and m2, m1 has shape ij and m2 has shape jk, so after multiplication it will have shape ik, so the equation becomes,

ij,jk โ†’ ik

In TensorFlow, it becomes like this:

tf.einsum('ij,jkโ†’ik',m1,m2)

But if we have three matrix multiplications like the paper code,

tf.einsum('btd,dD,bDn->btn', m1, m2, m3)

So in the above line, the first matrix multiplication is performed between m1 of shape btd and m2 of shape dD, and the output will be of shape btD, which will be multiplied with m3 of shape bDn, and the output will become of shape btn. If you want to read further about it, please go to the TensorFlow documentation.

Deep Learning Unplugged

Part 5 of 5

This series explains deep learning concepts in the simplest way possible. It aims to share hard-earned knowledge in an accessible way. Whether you're a beginner or an expert, it provides a clear, practical guide to mastering AI complexities.

Start from the beginning

How to Create Custom Layers in TensorFlow?

In TensorFlow, layers are the fundamental building blocks for creating machine learning models. While TensorFlow offers a wide variety of ready-to-use built-in layers, there are situations where these standard layers are not enough to meet specific n...

More from this blog

๐Ÿ” ๐”๐ง๐๐ž๐ซ๐ฌ๐ญ๐š๐ง๐๐ข๐ง๐  ๐“๐ž๐ง๐ฌ๐จ๐ซ๐…๐ฅ๐จ๐ฐ ๐•๐š๐ซ๐ข๐š๐›๐ฅ๐ž๐ฌ: ๐€ ๐๐ฎ๐ข๐œ๐ค ๐†๐ฎ๐ข๐๐žย ๐Ÿ”

Have you ever tried to reassign values in a TensorFlow tensor like you would in NumPy, only to hit the frustrating "EagerTensor object does not support item assignment" error? ๐Ÿ˜ค Letโ€™s break down why this happens and how TensorFlow handles mutable da...

Jul 5, 20241 min read8
๐Ÿ” ๐”๐ง๐๐ž๐ซ๐ฌ๐ญ๐š๐ง๐๐ข๐ง๐  ๐“๐ž๐ง๐ฌ๐จ๐ซ๐…๐ฅ๐จ๐ฐ ๐•๐š๐ซ๐ข๐š๐›๐ฅ๐ž๐ฌ: ๐€ ๐๐ฎ๐ข๐œ๐ค ๐†๐ฎ๐ข๐๐žย ๐Ÿ”

Neural Notes

10 posts

Welcome to Rashid's Neural Notes, exploring Python, AI, and machine learning with deep dives into neural networks, frameworks, and innovative applications.