Tales from the jar side: LangChain4J services, Stochastic parrot images, Now and Then, Managing Your Manager talks, and the usual tweets, toots, and skeets
My wife and I considered replacing our roof. She was worried about the expense, but I told her it was on the house (rimshot) #sorrynotsorry
Welcome, fellow jarheads, to Tales from the jar side, the Kousen IT newsletter, for the week of October 29 - November 5, 2023. This week I taught my Getting Started with Spring and Spring Boot course on the O’Reilly Learning Platform, as well as my regular Software Design course at Trinity College in Hartford, CT. I also gave a presentation at the International Developer Days conference online.
Regular readers of and 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 using this button:
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.
The Magic of LangChain4J Services
I’ve been spending a lot of time with the LangChain4J project lately. It’s a framework for working with AI tools like ChatGPT, but implemented in Java. The original LangChain project is a framework for Python, so this is a port from there.
Simple cases are very straightforward. For example, if you want to translate an English phrase into German, simply do this:
You create the language model you want to use, like OpenAI, using a builder. Then you fill in the prompt template and invoke the generate
method on the model to get your response.
I like the PromptTemplate
class, and it automatically assumes that variables enclosed in double braces {{variable}}
are supplied from a map. If that’s all it had, I would be happy with it, but they take a step beyond that feels like magic.
Instead of creating the prompt manually and invoking the generate
method, instead you can make an interface, like this:
The @V
annotation is used to extract the template variables and use them in the translate
method as arguments. But there’s no actual implementation. Instead, the way you call this “service” is:
The static create
method of AiServices
needs the interface and the model, and it generates an implementation of the interface for you. Then you call the translate
method and it works.
That’s impressive, but I like the following example even better. Say you want to extract information about a Person
from some text. You can make a Person
record:
Then you define your interface, here called PersonExtractor
:
And now you can supply the text, and the framework will not only get the response from OpenAI, it will extract person information and instantiate the record:
Seriously, how cool is that? The OpenAI system reads the text, extracts the fields for the Person
record from it, and populated an instance. To me, that all feels close to magical.
So far, my videos on AI tools have involved building the infrastructure manually, or using the Spring framework to do it. LangChain4J uses libraries like Retrofit and Gson, and does all the plumbing for you. As the last example showed, it can use reflection to populate a supplied class from a response. That’s extraordinary. What it tells me, is that a lot of user interfaces are going to become a lot more forgiving about the structure of user inputs. If it was able to extract the needed data here, think what it could do with addresses, phone numbers, or any other structured data imbedded in raw text.
LangChain4J goes way beyond this, but I’ll get into some of that in future newsletters. These examples, and many more, come from the langchain4j-examples project on GitHub, though I’m porting them to Java 17 so I can use records, text blocks, and so on.
Update: I finally put together a video about all this:
For more on that parrot on the coffee cup, keep reading.
Stochastic Parrot
From the Wikipedia article on stochastic parrots:
The phrase “stochastic parrot” is a rather derogatory term applied to large language models like ChatGPT, because while they’re great at pattern matching, they have no idea what they’re actually saying. That reminds me of this gag that I heard recently:
Me: Hey ChatGPT, what’s 9 + 7?
ChatGPT: 0.
Me: No, it’s 16.
ChatGPT: I’m sorry, you’re right. The answer is 16.
Me: Good. Now, what’s 10 + 12?
ChatGPT: 16.
I find it amusing that the logo for LangChain4J’s twitter feed is a parrot resting on a saucer holding a cup of coffee (Java, get it?):
(There’s a Dead Parrot joke in there somewhere, but I haven’t found it yet. Maybe next newsletter.)
I decided to ask DALL-E 3 to draw an image of a stochastic parrot:
Gee, sensitive much? I tried again with Midjourney:
(Inside Discord server)
Me: /imagine a stochastic parrot
Midjourney:
Apparently, to Midjourney, the word stochastic means lots of random colors. I can live with that.
If you go into WhatsApp, you can also generate images (assuming you’re in the US) by sending an “/imagine” message to the Meta AI bot:
Me: /imagine a stochastic parrot
Meta AI:
I think the resolution might be a bit lower, but still, lots of pretty colors. Again, that works.
Addendum: I just tried again with DALL-E 3, and this time I got an answer:
I guess that goes back in the “win” column. I’ll take it.
Now and Then
As yet another event related to AI this week, the Beatles released their very last song, Now and Then (video, audio). The story goes that when they were working on the Anthology releases back in the mid-90s, Paul, George, and Ringo talked to Yoko and she gave them an old cassette tape of some demos John recorded back in the 70s. The tape contained three songs, which were in rough shape:
I never really cared for Free as a Bird. It works, more or less, but it’s kind of lumbering and not terribly interesting. I like Real Love, but that’s partly because I’ve found many cover versions of it (In fact, I have a YouTube playlist of them here). I feel like even the Beatles version of Real Love is a cover version, since it’s John’s song and he wasn’t there to finish it. Apparently the guys didn’t enjoy finishing that one either, since it was so close to finished already they felt reduced to just background players.
Back in 1995, though, Paul and George (and producer Jeff Lynne) decided the quality of the audio on the Now and Then recording was not salvageable, mostly because John’s singing was too mixed with the piano that they couldn’t separate them. They gave up on it.
Last year, however, Peter Jackson completed a project the resurrected the old footage from the Let It Be movie, and with modern AI tools, was able to restore the audio to pristine form. He released the three-part, 20-hour documentary Get Back, and it was great.
Btw, there were two major revelations I got from the Get Back documentary:
The director of Let It Be (Michael Lindsay-Hogg) really had it in for Paul. Not only did he make him look bad frequently (like showing only part of the famous argument with George about how to play a particular passage), but from Get Back we now know that he had film of Paul creating the classic song Get Back in real time, on camera, and chose not to include the footage. That might be the most compelling part of the entire documentary, and they left it out of Let It Be entirely.
Billy Preston saved not only that album, but maybe more. His entrance into the movie not only improved the music immeasurably, his very presence lightened the mood and made it fun again. He played a key role in the entire production, and, once again, the director pretty much left him out entirely.
Maybe both of those are related, meaning maybe Michael Lindsay-Hogg is just a horrible director.
Anyway, after another 25 or so years, the AI tools have improved enough that Paul and Ringo were able to complete Now and Then. In case you haven’t heard it, here’s a link to the video:
What did I think? I liked it, of course. After all, I’m the target audience, though I was never a huge John Lennon fan. I much preferred Paul’s creativity with his songs, though I too grew increasingly frustrated at his laziness and inability to actually finish something great. He always felt to me like his generation’s version of Mozart, which the Get Back documentary displays in abundance, but he never seemed to quite get there. Oh well.
Here, however, he stayed in the background, though I really liked his bass parts in the song. I could barely hear his vocals, but since he’s 81 now (!), maybe that’s for the best.
I have to admit, though, I found the whole thing rather melancholy. Maybe that’s because it’s such a reminder of how long it’s been, how old everyone has gotten (at least for the two survivors), and therefore how much older I am as well. Still, I liked the song and I’ve probably listened to it a couple dozen times already. As a “last” Beatles song, it works.
Stackd podcast
I want to mention that on Friday I got to appear on the Stackd podcast (part of the Java PubHouse network), with hosts Dan Hinojosa and Kito Mann, who I’ve known for years, and Ian Hlavats. We had a great time talking together.
That podcast actually has production values, however, which means it may be a little while before that episode is available. I’ll let you know when it’s out.
Managing Your Manager talks
This week I gave my Managing Your Manager talk to two separate audiences:
I was invited to give the talk as part of their Decoding the Future lecture series. The audience was primarily students (who apparently had nothing better to do on the Thursday evening, though there were cookies available). I’ve always felt this talk worked best for younger people, so that was nice.
I presented it online as part of International Developer Career Day, held by Bruno Souza for developers looking to advance their careers. That worked pretty well, too.
The toughest part of each talk was staying within the one hour time constraint. I’ve written a whole book about this stuff, and I teach a related four-hour course on the O’Reilly Learning Platform, so it’s not like I don’t have things to say.
Incidentally, during my Trinity course this week I made a reference to the movie Office Space, and the kids had no idea what I was talking about. I also mentioned Caddyshack, and again they stared at me blankly. Sure, that’s an old movie, but come on, it’s Caddyshack. It’s practically the definitive Rodney Dangerfield movie, but when I told them that, they had no idea who Rodney Dangerfield was, either.
Somehow I managed not to shrivel up and collapse to dust from old age at that point, but it was close. I may have to start next week’s class with scenes from Monty Python and the Holy Grail. After all, if you haven’t seen that movie, you can’t really call yourself a developer.
Tweets, Toots, Skeets, etc
Dev Career Day talk
Here’s a tweet about my talk there:
Those are some very early slides in the presentation. Just FYI, I guess. I hope the person who tweeted that stayed longer than just those slides. :)
2038 is not that far away
In case you don’t get the reference, the Unix timestamp for the current era, which officially began January 1, 1970, at midnight GMT. The current value, unfortunately, is stored as a signed 32-bit integer. That integer will overflow its max value at 3:18:08 am, 19 January 2038. That’s known as the Year 2038 problem, and any systems still running on 32-bit operating systems will spontaneously see their system clocks roll over to 12 December 1901 at that time.
It would be bad luck indeed to be on a respirator running an embedded system using an old 32-bit version of Windows at that moment. Let’s hope it doesn’t come to that.
Cubicle Life
Hey, even Peter Gibbons at Initech* has his own cubicle, at least until he knocked down one of the walls to get a window view.
*For you kids out there, that’s an Office Space reference. So are “I have people skills!” “They took my red stapler and I may burn the place down,” “What’s happening, Peter?” “A Jump to Conclusions game,” and “I see you’ve been missing a lot of work, Peter — I haven’t actually been missing it, Bob.” The movie also includes a very young Jennifer Aniston, so there’s that.
Venn Diagram
This was part of an extended post that built up that diagram piece by piece. The only part I have a quibble with is I didn’t recognize how Oxford was a chess opening. Apparently there’s a variation of the Four Knights Game, Scotch Variation, called the Oxford Gambit. Still, that feels like a reach. The rest of the diagram, yeah, okay.
Capital
That needs a rimshot. I’ll add one on tomorrow’s video version of this newsletter.
Correlation vs causation
Of course, so does every single person who does NOT confuse the two.
VC funding opportunity
Zeno got us halfway there
I know I included this one last week, but I didn’t explain it, and I’m afraid it was lost on a lot of people.
One of Zeno’s paradoxes goes something like this: In order to get from me to you, first I have to go halfway to you. Then I have to go half the remaining distance, and then half the remaining distance after that, and so on. Therefore, I never get there.
Mathematicians would reply that the sum of 1 over 2^n from 0 to infinity is a convergent series that equals 2. Non-mathematicians would simply say, maybe, but you get close enough.
Now maybe with that explanation you can just enjoy the only Bon Jovi song reference I’m ever likely to make in this newsletter.
That’s not my name
I posted that one, mostly because my music service has been playing the Ting Ting’s song That’s Not My Name over and over. I’m sorry, but I refuse to use the name X (Twitter), Meta (Facebook), or Alphabet (Google), to say nothing of travesties like Stellantis (Chrysler), Altria (Philip Morris), Academi (Blackwater), American Outdoor Brands (Smith and Wesson), WW (Weight Watchers, seriously), or any of the other silly rebrands companies to do to avoid negative associations with their original names.
On the other hand, maybe I should just include this image now and get it over with.
Have a great week, everybody!
The video version of this newsletter will be on the Tales from the jar side YouTube channel tomorrow.
Last week:
Getting Started with Spring and Spring Boot, on the O’Reilly Learning Platform
Software Design, my course for undergrads at Trinity College
Managing Your Manager, at Trinity College, open to the community
International Developer Career Day, online conference
This week:
Functional Programming in Java, on the O’Reilly Learning Platform
Java and Spring, private class
Software Design, my course for undergrads at Trinity College