Tales from the jar side: Conversations in LangChain4j, My lowest grade ever, JVM Weekly rules, Braxit, and other tweets and toots
Is it crazy how saying sentences backwards creates backwards sentences saying how crazy it is? (rimshot, @DadJokes on Twitter)
Welcome, fellow jarheads, to Tales from the jar side, the Kousen IT newsletter, for the week of August 25 - September 1, 2024. This week I taught my first LangChain4j course.
Regular readers of, listeners to, and video viewers of this newsletter are affectionately known as jarheads, and are far more intelligent, sophisticated, and attractive than the average newsletter reader or listener or viewer. If you wish to become a jarhead, please subscribe:
As a reminder, when this message is truncated in email, click on the title to open it in a browser tab formatted properly for both the web and mobile.
Conversations in LangChain4j
This week I taught my first course on the topic of the LangChain4j framework for accessing AI tools from Java. The first time I teach a new course or give a new presentation is always stressful, because I’m not sure what the timing is going to be. I could give the talk ahead of time, but what fun would that be? More seriously, I don’t know what questions I’m going to get or what topics the attendees are going to care about, so I’m never quite sure how the class is going to go.
As part of my preparation, I wanted to deal with the topic of conversations. A lot of AI users don’t realize that when you access the programmatic API, all the questions are independent of each other. For example, here’s a test case:
Here are the two responses I get back:
First: Hello, Inigo. You’ve got quite the famous line there! What can I do for you today?
Second: I'm sorry, but I don't have access to personal information about you unless you've shared it during our conversation. If you'd like to tell me your name, feel free to share!
That’s from the GPT-4o-mini model, which is fast and cheap. The point is, even though I just told it a name, the second request didn’t remember it.
The reason developers don’t know this is because on the ChatGPT web site, that’s not how it works. If you ask a question during a session, the AI remembers the previous responses, at least for a while. But that’s contrived. The code behind the site is doing the work of taking all the previous requests and responses and adding them to the current request.
How do you do that programmatically? LangChain4j provides an interface called ChatMemory
, with two implementations: MessageWindowChatMemory
, which stores a fixed number of messages, or TokenWindowChatMemory
, which keeps track of a set number of tokens. You can then add questions and responses to the memory, and the next time you ask a question, you can ask for all the current messages to be included.
Now the response is better:
First: Ah, Mr. Bond! A pleasure to meet you. How can I assist you today?
Second: Your name is Bond. James Bond.
All that mucking about with the ChatMemory
instance gets tedious, however, and the framework has an alternative. If you use their AI Services capability, you can just add the memory to the service and it handles all the exchanges for you:
That’s way easier. The response is:
First: That’s a powerful and iconic quote from the film *Gladiator*! Maximus Decimus Meridius, played by Russell Crowe, delivers this line to convey his deep sense of loss and his relentless quest for vengeance against those who wronged him. It captures the themes of honor, loyalty, and the quest for justice that run throughout the movie. What do you like most about this character or the film?
Second: Your name is Maximus Decimus Meridius. It's a character from the film *Gladiator*. If you're referring to something else or have a different name in mind, please let me know!
Pretty sweet. Other demos I have are using a separate ChatMemory
instance per user, and implementing persistence. I did some of those examples during my training class, but I’m doing a lot more in an upcoming video that I plan to release in the next day or two, video clips and all.
As you can see, part of my approach is Fun With Names. So far I have Inigo Montoya, James Bond, Maximus Decimus Meridius, Heisenberg from Breaking Bad, Shake Zula from Aqua Teen Hunger Force, and even Mok from the animated Rock & Rule movie from way back in 1983, which is a seriously obscure reference. The biggest problem is that now I have the Aqua Teen Hunger Force theme song going through my head yet again.
Number One in the Hood, G.
Look for that video before next week’s newsletter, during which time I expect to learn how many video snippets I can include without getting a copyright strike.
My Lowest Grade Ever
One of the Substack newsletters I subscribe to is called One Useful Thing, from Ethan Mollick. This week he published an article called Post-apocalyptic education:
Ethan Mollick is a professor at the Wharton school of business at the University of Pennsylvania, and he writes frequently about AI topics, especially in relation to education. Since I am now (slowly coming to grips with the fact that I am) an academic, I’m quite interested in that topic. One of the points he makes in his post is that a huge percentage of students are already using AI tools for homework assistance, whether you know it or not, and the result is that the grades are higher but the understanding is, if anything, lower.
Back when I was an undergrad (and dinosaurs roamed the Earth), I was a double major, eventually earning BS degrees in both Mechanical Engineering and Mathematics. That was a very unusual double, btw. There were tons of Math/Physics doubles, or Math/Electrical Engineering, or Math/Computer Science doubles, but I was the only Math/Mechanical Engineering double in the school at the time. That was my way of majoring in Physics without majoring in Physics.
For the math degree, the only requirement was that you had to take eight courses of essentially different content beyond differential equations. So among my courses were Linear Algebra (really good), Advanced Calculus for Engineers (really good), Probability and Statistics (a near disaster), Analysis (very tough), and a brutal course called, simply Algebra (yikes).
Algebra was probably the most castles-in-the-sky theoretical course I took. When they used the word “applications,” they meant how do we use this theorem that we just proved to prove a different one. What I learned from that course was:
I really couldn’t compete with pure mathematicians.
Every polynomial equation of degree N with complex coefficients has exactly N complex roots, counting multiplicities.
Seriously, it took over half the semester to prove that result, also known as the Fundamental Theorem of Algebra.
As I recall, my understanding of that course ranged from vaguely following what was going on down to completely lost. The reason the course wasn’t a complete failure is that another student in my dorm, Peter, was a real math major and he was taking it with me. We worked “together” on all the homework problem sets, which meant I would stare blankly at each problem until he figured it out and explained the answer to me. Then I would nod, assure him that I got what he was saying, write down the answer, and go on to the next problem.
Perhaps you can see where this is headed. Our first real exam was the midterm. As it happened (and I still remember this, even though I took the course in the early Cretaceous period), the total number of available points on the midterm was 57, which was weird enough, but go with it. Class average was 19.
I got 7.
Right, seven. SEVEN. That’s a whopping 12%. Of course, class ave was only 33%, but still, I was nowhere near that.
Fortunately I was a junior at that point, so I knew how to handle it. I went to visit the professor, assured him that my homework grades were good (for the reasons specified above, though I certainly didn’t tell on Peter), found out what basic concepts I completely missed or misunderstood on the midterm, and assured him that my final exam grade would be better. It was better, too, since the professor, after destroying a room full of MIT math majors on the midterm, backed off on the final and gave us something reasonable. Somehow I scraped by with a very low B.
Bringing this back to the present day, this semester at Trinity College (the one in CT, https://trincoll.edu), I’m teaching a couple of courses where I’m not only assuming the students will work with AI assistance, I’m actually counting on it. I expect that, with the AI’s help, they’ll probably do well on any assignment I give them, though AI tools can be dicey at times so you never know. I also fully expect the students will convince themselves they know a lot more than they actually do, for the same reasons I thought I understood something about groups, rings, and field theory in my Algebra course when in reality all I really understood was how to work with Peter, which I suppose was an early form of prompt engineering.
There’s an old saying in education that if you make people think, they’ll hate you, but if you make them think they’re thinking, they’ll love you. The needle I’d love to thread this semester is to make the students actually think while thinking they’re thinking. Yeah, I know, good luck with that, but hey, I’ve got subscriptions to more AI tools than they do.
Trying to figure out how to get the students to learn something, even knowing they have AI tools handy, hardly makes me unique. The entire education industry is grappling with that issue these days, so I expect I’ll be mentioning it periodically in upcoming newsletters.
JVM Weekly Rules
As long as I’m bringing up Substack newsletters, I have to mention JVM Weekly by Artur Skowronski again.
JVM Weekly is perfectly complementary (that’s with an “e”, not an “i”, though he has also been kindly complimentary, too) to my newsletter. I’m a Java user, and have been for nearly 30 years. Artur understands Java under the hood, and lets me know what’s going on and why it’s important. He covers everything that I miss until it’s in the next released version. Seriously, if you are in the Java community and you want to understand what’s coming, you need to subscribe. This week I saw him post something about nearly reaching 4000 subscribers, and that seems really low to me. At minimum, half the Java developers in existence should be following him.
By contrast, in case you’re interested, I have about 2400 subscribers, but this is a company newsletter for a one-person company. I’m in awe every week that I have any readers at all.
Of course, most of you are here for the ….
Tweets and Toots
Minnesota nice
I’ve got some friends from Minnesota I need to send this, to verify it. If you’re one of them, please let me know how accurate it is. One of the comments said it’s “no, yah,” but that doesn’t change it too much.
Braxit
I don’t know if there’s a term yet for the exodus of Brazilian users from Twitter this week. Claude AI suggested Braxit, which is pretty good, or the Amazonian Migration, or a few other less catchy terms.
In case you’re not aware, Elon Musk, whose desire to shoot himself in the foot will eventually take off his whole leg, is in a stupid battle with the Brazilian government. Brazil emerged from decades of dictatorship relatively recently, and their current system is designed to avoid that happening again. The result is that they have actual bans against fake news and misinformation, meaning they want Twitter to moderate its feed, particularly its vile right-wing aspects. Since Elon himself is a vile right-wing clown, there’s a conflict. As this excerpt from a Reuter’s article explains:
The result has been a flood of new Brazilian users of alternative social media platforms. On Mastodon, where I mostly hang out, I saw this:
That’s one tiny server in the huge Mastodon distributed system. As for Bluesky, this article in The Verge says
I thought this tweet was telling:
It’s really hard to get people to leave a social media site they’ve adopted. See this excellent article for an explanation. You have to go out of your way to make their experiences a miserable one. Twitter has already lost a huge fraction of its user base, and advertisers are reacting accordingly, causing Elon to have the temerity to sue them for a de facto boycott. Yeah, I’m sure suing your customers will get them to spend more on your platform.
Maybe completely driving away one of his biggest markets will finally be the nail in the coffin for Twitter. We’ll see.
That would do it
Doesn’t explain how to fix it, though.
What’s my name, redux
Here’s the direct link to that site. I have no idea what to do with that information, but maybe you’ll think of something clever.
Enjoy your Bell riots
According to the Star Trek: Deep Space Nine two-part episode Past Tense, the other day (Aug 30, 2024) Sisko, Dax, and Bashir accidentally arrived in San Francisco in time to witness the rebellion against the system by the homeless and unemployed population, led by a man named Gabriel Bell. The resulting Bell Riots began on September 1 and were one of the most violent uprisings in American history.
For all I know, they started this morning. I’ll have to check social media later.
Star Trek: Severe Burn Unit
In the off-chance you don’t know or remember, Robert Picardo played the role of the Emergency Medical Holographic program on DS9.
Crocheted door-stops
Here’s the direct link, so you can check out those awesome images.
Have a great week, everybody!
Last week:
My first NFJS Virtual Workshop on LangChain4j
This week:
My Trinity classes start: Software Design, Computer Science Seminar, and Special Topics: AI Integration. Wish me luck.
Please do report on what you experience as you teach, assuming students use AI as Mollick does. I want to know about the learning/understanding that people do or do not gain. I'm one of those people who seemed to learn the content during the final exam. Sigh. Especially for those crazy math classes. (My 1977 BS in Computer Science must be a good 10 years older than yours, so I took a bunch of EE and advanced math classes. "Hard" was a total understatement. We will not discuss my grades in those classes!)
So far, I'm seeing way too many people create and then reuse AI content with the result of regression to the mean--an increase in mediocrity. However, I'm only seeing people use AI for writing prose, not programming. When people do that, they don't realize what they learn through the effort of working through what they do and do not know.
I look forward to what you learn!! Thanks.
I’m blushing, Ken 😳
Just a correction – I’ve only just managed to surpass 3,000 on Substack (+ an additional 1.4k on LinkedIn, where I also publish).
I’m still surprised that my somewhat over-the-top messages on a rather niche topic (delving into JEPs and updates in the Java platform and ecosystem - not something truly interesting for most of the developers) have found so many readers 😀 So every new subscriber brings me lot of joy.