(In case you’re wondering, the title of this post is drawn from this old groaner).
The big news of last week Wednesday was OpenAI releasing, for public use, ChatGPT. People have been having lots of fun with it, including asking OpenAI to “write a science fiction story about observing halachah in space”, or to write divrei Torah. So I decided to give it a shot and evaluate the result.
In my Algorithms class, I like to tie various topics or programming approaches to the parsha. So, for instance, “Backtracking min haTorah minayin?” (Backtracking is an approach in which you comprehensively explore solutions to a multistep problem, and if you hit a dead end in one path, you back out and try something else.) I pointed to parshat Vayeitzei, which begins:
וַיֵּצֵא יַעֲקֹב מִבְּאֵר שָׁבַע וַיֵּלֶךְ חָרָנָה. וַיִּפְגַּע בַּמָּקוֹם וַיָּלֶן שָׁם…
A midrashic understanding is that Yaakov first went to Charan, then realized he’d skipped Har HaMoriah. He turned around to go back, and immediately (via kefitzat haderech) bumped into that place, Har HaMoriah. Thus, backtracking.
Greedy algorithms, in which you can apply a heuristic to assess the best move, and you never second-guess yourself and backtrack, can be related to Sodom, renowned for its greed. Lot’s wife disregarded the command to not look back, and perished.
A Stack, which is a First In, Last Out (FILO) Data Structure, can be related (by an anonymous student) to Toledot and the following verse and Rashi:
כו וְאַֽחֲרֵי־כֵ֞ן יָצָ֣א אָחִ֗יו וְיָד֤וֹ אֹחֶ֨זֶת֙ בַּֽעֲקֵ֣ב עֵשָׂ֔ו וַיִּקְרָ֥א שְׁמ֖וֹ יַֽעֲקֹ֑ב וְיִצְחָ֛ק בֶּן־שִׁשִּׁ֥ים שָׁנָ֖ה בְּלֶ֥דֶת אֹתָֽם:
And afterwards, his brother emerged, and his hand was grasping Esau's heel, and he named him Jacob. Now Isaac was sixty years old when she gave birth to them.
ואחרי כן יצא אחיו וגו': שמעתי מדרש אגדה הדורשו לפי פשוטו, בדין היה אוחז בו לעכבו, יעקב נוצר מטיפה ראשונה ועשו מן השניה, צא ולמד משפופרת שפיה קצרה, תן לה שתי אבנים זו תחת זו, הנכנסת ראשונה תצא אחרונה, והנכנסת אחרונה תצא ראשונה, נמצא עשו הנוצר באחרונה יצא ראשון, ויעקב שנוצר ראשונה יצא אחרון, ויעקב בא לעכבו שיהא ראשון ללידה כראשון ליצירה, ויפטור את רחמה, ויטול את הבכורה מן הדין
And afterwards, his brother emerged, etc.: I heard a Midrash Aggadah that interprets it (the verse) according to its simple meaning: He (Jacob) held onto him lawfully, to restrain him. Jacob was formed from the first drop and Esau from the second. Go forth and learn from a tube that has a narrow opening. Insert two stones into it, one after the other. The one that entered first will emerge last, and the one that entered last will emerge first. The result is that Esau, who was formed last, emerged first, and Jacob, who was formed first emerged last, and Jacob came to restrain him so that he (Jacob) should be the first to be born as he was the first to be formed, and he would open her womb and take the birthright by law. — [From Gen. Rabbah 63:8]
A Queue data structure, which is First In, First Out (FIFO) can be related to Vayeitzei. When Lavan justifies tricking Yaakov and substituting Leah for Rachel, he says:
וַיֹּ֣אמֶר לָבָ֔ן לֹא־יֵֽעָשֶׂ֥ה כֵ֖ן בִּמְקוֹמֵ֑נוּ לָתֵ֥ת הַצְּעִירָ֖ה לִפְנֵ֥י הַבְּכִירָֽה:
And Laban said, "It is not done so in our place to give the younger one before the firstborn.
So how would Chat GPT do with the following prompt? “Write a dvar Torah relating parshat Vayishlach to Priority Queues.”
It answered:
In Parshat Vayishlach, we read the story of Jacob's encounter with Esau, his twin brother from whom he had been estranged for many years. Jacob is filled with fear and anxiety about the encounter, and he prepares for it by sending gifts to Esau and praying for God's protection.
One way to think about this encounter is in terms of a priority queue, a data structure that organizes items according to their priority. In Jacob's case, his encounter with Esau is at the top of his priority queue, and he takes steps to ensure that it is handled in the best possible way.
Similarly, in our own lives, we may have many different tasks and obligations competing for our attention. A priority queue can help us to organize and prioritize these tasks, ensuring that the most important ones are handled first.
Just as Jacob prepared for his encounter with Esau by sending gifts and praying, we can prepare for the challenges and opportunities in our own lives by prioritizing the most important tasks and taking action to address them. In this way, we can ensure that we are making the most of our time and our abilities, and that we are fulfilling our responsibilities in the best possible way.
Ultimately, Parshat Vayishlach reminds us of the importance of prioritization and the need to focus on the tasks that are most important to us. By organizing our lives according to priority, we can make the most of our time and our abilities, and achieve our goals.
This reads like a fine dvar Torah, if a bit blah and formulaic. Indeed, it is formulaic, as other generated divrei Torah adopt essentially the same form and structure.
As for content, the connection to Priority Queues is tenuous. Yes, prioritizing is important in a priority queue — in which you enqueue items, and then dequeue the item with the largest (or smallest) assigned priority. But prioritizing his encounter with Esav, because it was important… just seems forced.
If it really understood the content of the parsha, it might note the different items sent as gifts — sheep, camels, cattle, donkeys, and so on, both female and male, in different numbers. Why send them out in the particular order that he sent them? One could speculate and develop a theory. Or, as Judith suggested in class, it could talk about Yaakov dividing his family, and putting specific subgroups first:
וַיָּ֧שֶׂם אֶת־הַשְּׁפָח֛וֹת וְאֶת־יַלְדֵיהֶ֖ן רִֽאשֹׁנָ֑ה וְאֶת־לֵאָ֤ה וִֽילָדֶ֨יהָ֙ אַֽחֲרֹנִ֔ים וְאֶת־רָחֵ֥ל וְאֶת־יוֹסֵ֖ף אַֽחֲרֹנִֽים:
And he placed the maidservants and their children first and Leah and her children after, and Rachel and her Joseph last.
As Rashi explains:
ואת לאה וילדיה אחרונים: אחרון אחרון חביב:
and Leah and her children after: The further back the more beloved. — [from Gen. Rabbah 78:8]
That is exactly like a priority queue!
As Racheli observed in class, while it isn’t a great dvar Torah, if a human had said it, we wouldn’t necessarily criticize it, and realize how much of kvetch it was, as much. (Although for some folks, criticizing the rabbi’s sermon does make for good Shabbos meal talk.) But once it is a computer, we evaluate it more carefully.
So it might be good at generating bland divrei Torah, but not so much for real creativity and deep insights into the Torah text. That is because, beneath the hood, it isn’t really representing the semantic knowledge, drawing inferences, and making conclusions. It is a predictive text algorithm, with all the limitations that implies.
Humans are still much more capable than this (impressive) AI.
Let’s draw a connection to saying ותן טל ומטר לברכה, which we started this past Monday. It is easy to forget, and then one might need to repeat. See Halachipedia for details.
If we are unsure if we forgot, then within the first 30 days, we assume we forgot, but afterwards, we may assume we said it correctly. Well, this would be if it were mashiv haruach, which we say thrice daily, plus an extra tefillat musaf on Shabbat. But vetein tal doesn’t occur in Shabbat davening at all, so we don’t have as many repetitions. This is discussed:
Shulchan Aruch 114:8 regarding Mashiv HaRuach. Mishna Brurah 114:37 writes that regarding VeTen Tal there's not 90 davenings in 30 days (because of Shabbat and Yom Tov), there's a dispute whether 30 days is sufficient and concludes that we hold leniently that after 30 days it's assumed that one says it correctly. Halacha Brurah 114:14 disagrees and says that if one is unsure whether or not he said it during this period that is after 30 days, but 90 prayers haven't been recited, he should repeat the shemoneh esrei but to avoid any concern, should stipulate that if he is obligated to repeat then he is repeating but if not it should be considered a voluntary prayer.
Repetition trains our own neural network, just as it can be used to train a (speaking) monkey or a parrot:
However, in our tefillah, we should strive to be more than predictive text algorithms. While we often go on autopilot, Rachmana liba ba’iy, and we should attempt to focus and think about what we say, and mean it.