Math Skills For AI
What I Aim to Achieve
As a graduate with a Computer Science degree, my time has been primarily dedicated to three core areas:
- Programming: I’ve worked extensively with Python, C++, JavaScript, and Rust.
- Mathematics: My studies have encompassed linear algebra, probability, calculus, and discrete mathematics.
- Core Computer Science: I’ve explored topics like databases, networking, and data structures & algorithms.
During my final year, I realized there were significant gaps in my understanding, despite the courses and books I’d engaged with. I often wish I could start over, but real life doesn’t have a “retry” button.
Currently, I’m involved in:
AI Research: My focus is on medical image preprocessing and natural language processing. I’m also keenly interested in areas like:
- Federated Learning
- Adversarial Neural Networks
- Explainable AI (XAI)
- Generative Art (specifically Stable Diffusion models, Flux, and ControlNet)
Web Development: I primarily use FastHTML and Astrojs for side projects. I enjoy building things and getting paid for them, as I don’t currently have a formal AI job.
The Centrality of Math in AI Research
It’s true that in both engineering and research, you can be an excellent software engineer and earn a substantial income without deep mathematical knowledge, possibly more than many mathematicians. However, to be a good researcher, a strong mathematical foundation is crucial. By that, I don’t just mean a superficial understanding of numerous topics. You need a solid grasp of linear algebra and probability, both theoretically and practically. And by “practical,” I mean the ability to translate mathematical concepts into code.
Of course, other topics are relevant, depending on your specific field. For example:
- Generative AI: You’ll often encounter differential equations and advanced probability and statistical models.
After reading research papers, you begin to see recurring concepts like conditional probability, Bayes’ theorem, and matrix factorization. But you’ll also find complex, novel, or sometimes even older, techniques that are hard to grasp initially.
In my limited time exploring research, I’ve observed that many papers lack significant contributions. Some seem to be primarily workarounds, comparisons of existing models, new data applied to established models, or minor observations. This isn’t inherently bad, but it’s not the kind of impact I’m aiming for. The researchers who are making substantial contributions are often very skilled in both math and coding. They create open-source projects, share their ideas, and actively contribute, like the authors of the Colbert papers in information retrieval. And these contributions are often enabled by math, such as PCA, LORA, and other optimization techniques.
While a strong coding background can certainly be beneficial for optimization and research, I strive for a deeper understanding and to reach a higher level of impact. After all, we only have one life.
I don’t consider myself a “bookworm,” but I genuinely love reading and can become engrossed in books on diverse subjects and levels. I recall reading around four books on linear algebra, completing all the exercises, and summarizing the content. In deep learning, I’ve tackled more than 30 books. For areas like networking, databases, and data structures, I’ve read at least three books on each. When new topics like federated learning, XAI, and adversarial networks emerge, I always read at least one book on each.
If you were to examine my profile, CV, GitHub, or even this blog, you’d probably find that I’m below average for a recent graduate! What’s the problem?
I believe the core issue is that while I’ve read extensively and sometimes coded along with the material, I haven’t committed to projects that demand more time and mental effort. I haven’t really allowed the knowledge to “grow.” For instance, I learned linear algebra theory and did the pen-and-paper exercises, but I didn’t experiment with coding it. And, I didn’t apply the concepts I studied to the fields that truly interested me. There’s also a gap between the libraries we use in deep learning and the underlying skills – they don’t always feel directly connected.
It’s unrealistic to understand every library at a micro-level. But it’s crucial to try and bridge the gap between your fundamental skills and the high-level APIs you use. For example, challenge yourself to implement PCA from scratch with NumPy on a Kaggle dataset. Try coding the matrix components of LORA with PyTorch. Take probability concepts and apply them to datasets you care about – for me, that might be datasets related to fitness or Arabic language processing. Build projects you love using these new tools, and consciously choose what skills to prioritize. For example, I might be okay with letting go of some discrete math knowledge, but not linear algebra.
The Days of Problem Solving
During my second year, I began exploring problem-solving but initially struggled with platforms like Codeforces. However, after two months of encouragement from friends, I decided to give it another shot.
I was using Edabit to practice Python problem-solving with easy problems and then moved to Codeforces without a solid grasp of C++. It took time and many hours struggling with error messages (I once learned a painful lesson that “” and ’’ are different in C++ unlike Python!).
After about two months of this, my skills in both thinking and implementation improved dramatically. I recall one of my earliest achievements was writing a 300-line C++ solution without relying on Google, and of course, LLMs weren’t around at that time. This feeling of self-sufficiency was incredibly rewarding. After four months, my problem-solving skills had improved considerably, and I had reached the next level. However, I then decided to shift my focus to web development to improve my financial situation, and I never went back. I also remember failing a technical interview in my third year because I struggled to solve linked list problems in Python, despite being able to do so in C++. I felt lost throughout my college years
But that feeling of deep understanding, of being able to solve problems independently, is amazing and builds confidence. It’s a virtuous cycle.
Things I Remember
I’m revisiting linear algebra and realized I’d forgotten how to calculate eigenvalues, though I understand their role. However, I haven’t forgotten how to calculate the determinant of a 2x2 or 3x3 matrix. Why? Because I solved countless exercises with determinants, but with eigenvalues, I had primarily read the solutions or tried simple examples. When using PCA in code, it’s easy to rely on a library and not think about the underlying operations. While that’s okay to some degree, we should occasionally revisit how things work behind the scenes.
The MBZUAI Exam in Two Days
A friend told me about a scholarship at MBZUAI with a deadline in three days. Although I didn’t have the necessary English test scores, I applied anyway. They’ve scheduled an exam in 7 days from when I applied, and today was the first day I started preparing.
I completed the linear algebra and probability specializations on Coursera taught by Luis G. Serrano. While it was a good refresher, I dislike relearning the same concepts every year! The exam will cover probability, linear algebra, calculus, algorithms, trigonometry, optimization, and some NLP questions.
I honestly don’t remember much about trigonometry, and when I studied it before, it was in Arabic, not English, and the transition isn’t so simple. I also dislike cramming things for two days only to forget them immediately after – that feels like a waste of time.
Despite the odds, I’m determined to apply, even if the acceptance rate for the scholarship is only 5%. Working with the people at MBZUAI would be a great experience. If I’m not accepted, I’ll continue to focus on mastering math and keep moving forward.
Maslakiat
when i have a stress and a lof of taskes i go to reading books I have final exams in the comming days, MBZUAI exam, research paper review comments needed to be corrected, open source problem i must finish this week, some websites and a lot of things. I start reading the first the page and the author was talking to me and the words touch my soul deeply for example some qoutes from the book I will write them in arabic and you can translate them with GPT.
Translations of the Arabic Quotes (with slight interpretations for clarity):
“ولكن ثمة عامل له في نفسي حفاوة خاصة ، عامل يفسر كثيرا من فشل الطموحات و الأحلام … هذا العامل بكل اختصار: هو أن الخطط فوق الصخور و الارجل مازالت ناعمة ما حفيت بعد…”
- Translation: “But there is a factor that resonates deeply within me, a factor that explains much of the failure of ambitions and dreams… This factor, in short, is that the plans are laid on rocks, but our feet are still tender, not yet calloused.”
- Interpretation: This emphasizes the gap between grand plans and the lack of practical experience or the “hard knocks” that build resilience and skill.
“إذا كان المرء ينام حتي تجهرك أشعة الحمرة في عينية و يبسط خوان الطعام كلما اشتهي ، ويخصص الأوقات الطويلة للقهوة و الشاي و العصائر و الفطائر ، ولا يسمح لنفسه بأن تتنازل عن أي فرصة فسحة أو مسامرات مع أصحابة ، و لا يستطيع كبح جماح تصفح الإنترنت أن يسرق ساعاته ، اذا كان المرء كذلك .. وما زال يرجو ان تتحقق يوما ما خططه العلمية و الدعوية و الإصلاحية ، فمثل هذا الشخص قد استأصل عقله ، و زرع بدلا منه مصباح علاء الدين”
- Translation: “If a person sleeps until the red rays of the sun glare in their eyes, lays out a feast whenever they desire, dedicates long periods to coffee, tea, juices, and pastries, never allows themselves to miss an opportunity for leisure or socializing with friends, and cannot restrain themselves from internet browsing stealing their hours—if a person is like this and still hopes that their scientific, religious, or reformist plans will one day be realized, then such a person has removed their mind and planted Aladdin’s lamp in its place.”
- Interpretation: This strongly condemns a life of indulgence and procrastination, suggesting that those who wish to achieve great things must sacrifice leisure and work diligently. They cannot expect to magically fulfill ambitions like Aladdin with his lamp.
“لا يستطاع العلم براحة الجسم”
- Translation: “Knowledge cannot be attained with bodily comfort.”
- Interpretation: This is a concise statement emphasizing the necessity of effort and sacrifice in the pursuit of learning.
“الكمالات كلها لا تنال إلا بحظ من المشقة و لا يعبر إليها إلا علي جسر من التعب”
- Translation: “All perfections are not achieved except through a portion of hardship, and they cannot be crossed except on a bridge of fatigue.”
- Interpretation: This highlights that excellence and mastery require sustained effort, difficulty, and resilience.
“تلمح فجر الأجر يهن ظلام التكليف”
- Translation: “You perceive the dawn of reward makes the darkness of duty pale.”
- Interpretation: This suggests that the hope of reward and the meaningful impact of your work make the hard work and sacrifice worthwhile.
“بقدر ما تتعني تنال ما تتمني”
- Translation: “To the extent that you exert yourself, to that extent you will achieve what you desire.”
- Interpretation: This is a direct statement of the relationship between effort and achievement.
“ولم تعطني الأيام نوما مسكنا ألذ به ، إلا بنوم مشرد”
- Translation: “The days have not given me a comforting sleep more delicious than a scattered one.”
- Interpretation: This beautifully evokes the idea that true rest is often earned by hard work and might not always be the most comfortable.
“و اذا كانت النفوس كبارا تعبت في مرادها الأجسام”
- Translation: “If the souls are great, the bodies will toil in pursuit of their desires.”
- Interpretation: This highlights that ambitious goals require a commitment to hard work that will test the physical body.
“وكذلك يحذر من التنقل من كتاب الي كتاب من غير موجب فإنه علامة الضجر وعدم الفلاح”
- Translation: “Likewise, he warns against moving from book to book without a valid reason, for it is a sign of boredom and lack of success.”
- Interpretation: This advises against haphazardly abandoning study materials, highlighting that deep learning comes from thorough exploration.
“وإن من الحكمة أن من ابتدأ بعمل وارتاح له فليستمر عليه ، فمن بورك له في شئ فليلزمه ، وبعض الناس يبدأ الأعمال و لا يتممها ، فيمضي عليه الوقت سبهللا من غير فائدة فمثلا يقراء في هذا الكتاب او هذا الفن ، ثم يدعه من غير ان يكمله وينتقل الي غيره ، ثم الي اخر ، من غير تكميل الأول فيضيع عمله وينقضي عمره بلا فائدة ، وكذلك في الأعمال الاخري كل يوم له عمل وكل عمل له راي فيضيع الوقت عليه من غير فائدة” - Translation: “And it is wisdom that whoever begins a work and finds comfort in it should continue with it. For whoever is blessed in something should stick to it. And some people begin tasks and do not complete them, so their time passes in vain without benefit. For example, they read in this book or this discipline and then leave it without completing it and move on to another and then another without completing the first, so they waste their work and their lives pass without benefit. And likewise in other works, each day has a work and each work has its own approach, so they waste time on that without benefit.”
For opensource project i have a lot of coold projects that i strated and will start soon but didn’t complete any one yet and i know when i finish one i will get a job easly but this is what happend.
Imam Al-Nawawi
Al-Nawawi began his pursuit of knowledge relatively late, in the year 649 AH. He was, as he himself stated, 19 years old at that time. This was considered a late start compared to the custom of their time, where people would begin seeking knowledge before reaching puberty. As Al-Nawawi himself said, “When I was nineteen years old, my father brought me to Damascus in the year forty-nine, and I resided in the Rawahiyya School.”
Al-Nawawi, may God have mercy on him, passed away in the year 676 AH, at the age of 45. Scholars in their forties typically begin to produce their most refined and meticulously researched scholarly work. Thus, the Sheikh, may God have mercy on him, did not live long.
Well then… when did the Sheikh begin writing and authoring? The Sheikh himself stated that he spent six years in the pursuit of knowledge, and then began authoring, i.e., he began authoring at the age of 25.
Al-Nawawi also informed his student, Ibn al-Attar:
“He mentioned to me, may God have mercy on him, that he did not waste any time, night or day, except in a task of engaging with knowledge. Even while walking on the streets, he would engage in reviewing what he had memorized or studying. He remained engaged in acquiring knowledge in this manner for about six years, and then he began writing.”
This means that most of Al-Nawawi’s works that we circulate today were authored during his twenties and thirties!
Al-Isnawi explains: “This phenomenon with Sheikh Muhi al-Din al-Nawawi was quite common. It is that, when he became qualified to study and acquire knowledge, he saw that it was part of his striving towards good deeds to make what he acquired and understood into an authorship, from which the reader could benefit. Thus, he made his authoring a means of acquiring knowledge, and his acquiring knowledge a means of authoring. Without this, he would not have been able to produce the amount of authorship he did. He entered Damascus to study when he was eighteen years old, and died before he reached forty-six.”
Al-Isnawi’s point is that Al-Nawawi made his authoring a way to acquire and seek knowledge. He immediately put his seeking and acquiring of knowledge into the form of authorship, i.e., his notes during his pursuit of knowledge, he would convert them into a form of authorship, rather than allowing the notes of his youth to be wasted.
Was this a coincidence for Al-Nawawi, or was it a conscious behavior? Meaning, did Al-Nawawi keep in mind the benefit of authorship in educating the author himself? In fact, there is a statement of Al-Nawawi in his other book, Sharh al-Muhadhab, which reveals that his early attention to authorship was for the purposes of self-learning. In his introduction, where he explained the etiquette of a seeker of knowledge, Al-Nawawi stated:
“One should pay attention to ‘authoring’ when one is qualified for it, for through it one discovers the realities and subtleties of knowledge, and it becomes established in one’s mind. It forces one to engage in extensive searching, studying, investigating, and reviewing, and to become acquainted with the different opinions of the Imams, their agreements, what is clear, what is ambiguous, what is authentic, what is weak, what is eloquent, what is feeble, what is not subject to objection, and what is. Through this, a researcher takes on the qualities of a mujtahid (one who can exercise independent legal reasoning).”
Here, Al-Nawawi is not just encouraging authoring, but he is revealing the motivations that drive authoring and expands on the effect it has on the advancement of the student’s understanding by obliging them to delve deeply.
Also, Al-Khatib Al-Baghdadi said: “Whoever wants to benefit, let them break the pen of copying and take up the pen of research.”
And I’ve noticed that a lot of prominent figures in Deep Learning (DL) are doing this. For example:
Michael Lanham (https://www.amazon.com/stores/author/B07BPS6WQL): The author of:
- Evolutionary Deep Learning
- Practical AI on the Google Platform
- Learn Python Game Development with ChatGPT
- and many other books.
Christoph Molnar (https://christophm.github.io/interpretable-ml-book/): The author of Interpretable Machine Learning.
Christopher M. Bishop (https://www.amazon.com/stores/Christopher-M.-Bishop/author/B001IGLMNY?ref=ap_rdr&isDramIntegrated=true&shoppingPortalEnabled=true#): The author of the famous book, Pattern Recognition and Machine Learning. He once mentioned that he wrote this book to ensure his own understanding of these concepts.
… and the list goes on.
My Approach: Building, Not Just Reading
I don’t necessarily aspire to write a book, but rather to recreate knowledge from the sources I’ve studied (books, courses, and papers). I don’t advocate for simply “writing a book” as a goal. Instead, I aim to create accessible pieces of knowledge that I can iterate on and use to help others understand these concepts.
This is my intended approach, and I will start with:
- “Building DL from Scratch” Series: Based on the fastai course and the Deep Learning from Scratch book.
- “Math Level Up for DL”: Based on multiple books, courses, and some experiments I want to conduct.
Then, I will expand on these approaches in blog posts and other materials on topics like federated learning and other areas I’m interested in. I’ll try my best to do all of this effectively.
NOT Just the Math
This approach isn’t limited to math. It extends to every skill, including CSS, Deep Learning implementation with pure PyTorch code, and so on.
…to be continued.
you can read: