Semantics Illustrated

This is a longer version of my recent Language Corner post. Language Corner is a feature I write regularly on LinkedIn. It is focused on linguistics, so I cut most of the quantitative material and moved it here. I motivated that post with a reference to Semantle, a popular online word game, and showed how the game uses cosine similarity.

Cosine Similarity

The target word that day was “inmate.” The nearest word to “inmate,” with a similarity score of 81, is “inmates,” plural. The nearest word after that is “prisoner,” a synonym, with a score of 72. These scores can be a little misleading because they’re not a straight scale. They are “cosine similarity” in the Word2Vec pretrained embedding model.

Most of my coursework in linguistics focused on syntax – why words and word-parts are where they are in a sentence. The state of the art in semantics was observing that words reside in “semantic fields.” Today, thanks to AI language models, we can study semantic distance with precision.

For instance, “gold” denotes both a metal and a currency. It occupies the intersection of at least two different semantic fields. One, it shares with iron and tungsten. The other, with bitcoin and chalcedony beads. Instead of sets intersecting, as in a Venn diagram, I always pictured them as axes crossing.

Gold sits at the corner of metals and currency. Gold is also a color, so we’re going to need at least three dimensions. Word2Vec uses 300 – which is small, as embeddings go.

Word Embeddings

The great success of Large Language Models (LLMs) owes to their training data being self-labeled. Training a neural network generally requires tons of pre-labeled data. You feed in images from ImageNet, your neural net tries to guess the subject, and the labels provide feedback. By the way, I wrote an explainer on deep neural networks back in 2021, before the LLM mania took over.

The task assigned to an LLM is simply to predict the next word in a text. So, each word is a test case. The context leading up to the word is the input, and the word itself is the label. Word embeddings arise as a byproduct of this activity.

Inputs to a neural network need to be encoded in some way. Quantitative variables are straightforward, but others are not. An embedding is a layer in the neural network that allows it to learn the most suitable representation for a given input. Here is an example from a project where I needed to accept car models as input:

carmodel_inputs = keras.layers.Input(shape=[], dtype="string")
carmodel_indices = keras.layers.Lambda(
    lambda carmodel: table.lookup(carmodel)
)(carmodel_inputs)
models_embed = keras.layers.Embedding(input_dim=table_len, output_dim=10)(
    carmodel_indices
)
all_inputs = keras.layers.concatenate([num_scaled, cats_encoded, models_embed])

 

This is an efficient way to handle the encoding problem, and it has the advantage that you can save the embedding for later use. The developers of Word2Vec ran their text-completion training including an embedding with output_dim = 300, and then saved the embedding.

It’s important to note that word embeddings are built on syntactic substitutability. The word nearest to “north” is “south.”

The Word Globe

Semantle calculates similarity as the cosine (times 100) of the angle between the two vectors that represent the words. Imagine if all the words in the language were arranged on the globe, in three dimensions instead of 300, with word-vectors radiating from the center of the Earth.

The cosine of 44 degrees is 0.72, the similarity between “inmate” and “prisoner.” An arc of 44 degrees, on planet Earth, would be roughly 3,000 miles – the distance from Boston to Dublin. If that seems like a long flight to reach the next synonym, think of how many words are totally unrelated (cos = 0) and how much room they have to spread out in 300 dimensions.

A single vector in 300-D space has an entire 299-D subspace (its orthogonal complement) of words totally unrelated to it. Below is the distribution of similarity scores relative to “inmate,” calculated on the Word2Vec embedding. Most words are near zero. Those above 0.60 are too few to see on the chart.

Nonetheless, this word-globe is key to understanding how to beat Semantle. The first guess gives the absolute distance from “giant.” That’s a circle. The second guess gives the absolute distance from “enemy.” That’s another circle (actually, they’re 298-dimensional hyperspheres, but you get the idea).

You can now load the Word2Vec embedding into a short Python script and calculate where the two circles cross.

Principal Component Analysis

Now that Semantle is licked, we come back to the semantic fields containing “gold.” Gold is the textbook example because it participates in a few distinct fields. I chose a handful of words, all within striking distance, and projected them down to three dimensions – from fifteen hundred. For this exercise, I have switched to OpenAi’s text-embedding-3-small, which I have written about previously.

Readers of this blog are probably familiar with Principal Component Analysis (PCA). This algorithm finds the one dimension that captures the most variance across the sample, and then the second most, etc., finally projecting the points onto this subspace.

I feel good about this projection. The three principal components explain a respectable 35% of the total variance:

  • PC1: 16.2%
  • PC2: 11.0%
  • PC3: 7.4%

PC1 is the color-wealth axis, with ordinary colors on the right, “money” and “wealth” on the left, and “gold” in the middle. It’s not surprising that PC1 captures most of the variance. Apart from “gold,” colors have nothing to do with wealth.

PC2 captures the “metal” concept omitted by PC1. Industrial metals like “iron” and “palladium” are on the right. Lastly, PC3 is the wealth-metal axis, with “bullion” on the left and “iron” on the right. Colors sit this one out, with values near zero.

Knowledge Engineering Redux

We could use a semantic layer for our Snowflake database, and maybe a context layer for some AI agents. There are three different disciplines all chasing roughly the same goal, which is to provide AI with background knowledge about the business. Today, I will provide a brief survey of the field, so you can decide which one(s) you need.

  1. Semantic layers
  2. Context engineering
  3. Ontologies and graphs

Semantic Layer

Snowflake calls them semantic views. A complete set of semantic views makes up a semantic layer. The word “semantic,” of course, means that the layer contains meaning instead of mere syntax. Syntax is what a data element looks like in the schema. Semantics is what it means. As a Linguistics grad, I still have my textbook on (natural language) Syntax and Semantics.

CREATE OR REPLACE SEMANTIC VIEW sales_rev_analysis 
TABLES (
  orders AS source.orders,
  customers AS source.customers
) 
RELATIONSHIPS (
  o_to_c AS orders (cust_id) REFERENCES customers (id)
) 
FACTS (
  orders.total_price AS amount
) 
DIMENSIONS (
  customers.region,
  orders.order_date
) 
METRICS (
  total_revenue AS SUM(amount)
);

It’s reasonable to call this a “layer,” in the architectural sense, because it sits between the AI model and the database. Extending SQL DDL to include AI artifacts reminds me a lot of Google’s BQML. Note how the Snowflake example enforces Kimball’s modeling style.

Apart from Snowflake, any database-linked metadata, like E-R diagrams, catalogs, and data dictionaries can serve as a semantic layer – as long as they’re accessible to the AI model. If you’re a Sigma-heavy Snowflake shop like ours, Sigma will consume your Snowflake definitions automatically.

If you prefer your semantics as YAML code, dbt does that. Everybody in the analytics space has their own approach to semantic data, leading to the Open Semantic Interchange, which is meant to be the lingua franca among them.

Context Engineering

To understand the importance of context engineering, you need to understand how context works. An LLM doesn’t keep mental track of the conversation the way you and I do. Each turn of the dialogue must feed the entire context window through the LLM again. The longer the context, the less likely the model’s response will be on point.

Running a company is just context engineering internally – Shopify CEO Tobi Lutke

As Andrej Karpathy explains here, this has led to a “thick layer of non-trivial software” to maintain succinct context. You want to spawn a new agent, for instance, with only the context for a specific task – undiluted by the broader context – and you might even wish to arm it with specific skills.

Skills allow AI agents to maintain succinct context by progressively pulling in text (as markdown and YAML) only as needed for the task at hand. This is also a great way to provide business knowledge. Don’t let the simplicity fool you – give your context files the same governance and security that you would any sensitive code.

The Karpathy post is part of a dialogue, including Shopify CEO Tobi Lutke, on the importance of documenting business context. Fortunately, markdown is readable by humans, too. Am I the first cynic to note that we never got this kind of documentation until AI came along?

Knowledge Ontology

Jessica Talisman makes the case for formal representation of knowledge using tools like OWL and RDF. This is about specifying knowledge in the abstract, which will be familiar to designers of OO class models. Her examples are large bodies of knowledge, abstract in the sense that they transcend an individual business.

This is probably overkill for my Snowflake use case, but I can see where it would be useful for, say, Palantir. It’s too bad the term “knowledge engineering” has been co-opted because, of the three disciplines, this one seems the most technical – and they had it first.

Palantir Ontology

Ontology is also a “layer” at Palantir, analogous to the application layer in a software stack. Palantir CEO Alex Karp says that the client’s value-added knowledge belongs in an explicit ontology layer instead of handing it off to an AI model controlled by a third party.

Karp argues that if you hand your business data and context to an AI vendor, you risk transferring your company’s “alpha” to a third party. Palantir’s solution is to confine this knowledge in the ontology layer, where it can be executed using any model.

The alternative to this approach is “sovereign” AI, which means that the model is private, either to the vendor, or to the business itself. This doesn’t mean that you have to become a frontier AI lab. It just means that you acquire the initial weights and then train it for your application.

Conclusion

My knock on ontology is that it strikes me as terribly effortful. It seems that every time we try to “help” AI, with prompts and orchestrators and harnesses, AI turns around and renders our help obsolete.

I remember researcher Douglas Lenat trying to code all background knowledge, like “if an item is in a box, and the box is in a room, then the item is also in the room.” Sound ontological? Lenat wasn’t wrong. There was no better alternative, circa 1985, but then the technology improved.

Snowflake’s Semantic View Autopilot (SVA) is another example. Instead of reading your painstakingly crafted semantic views, Snowflake’s AI can discover them by watching your usage patterns. I can, equally, imagine an LLM producing an ontology on its own.

Talisman may be right that ontology is a grand, scientific enterprise, and analytics is small beer. Karp is betting his company on it. Me, I just want to make sure everyone in my shop has the same definition of “back-end gross.”

Switching to Linux

I recently switched from Windows to Linux. It was time for a new laptop anyway, and I just couldn’t handle the Windows crap any longer. It started when my favorite AI libraries stopped being supported on Windows, and I found myself using the Linux Subsystem (WSL) more and more.

In this article, I’ll motivate the switch to Linux, and give you some pointers from my recent experience. You can make the switch, too. It’s not as hard as you may think.

What 365 means is: you pay Microsoft every day of the year.

Most of you will recognize what I mean by Windows crap. It conveniently forgets that I own paid licenses, and tries to jam me into the “365” program. Apps I’ve already paid for suddenly stop working, and then I lose time fixing them.  What 365 means is: you pay Microsoft every day of the year.

Then, it’s always trying to badger me into using Copilot which, by the way, is spyware. After updating my registry to turn off Copilot for good, I was not looking forward to the next release, with integrated “kernel level” spyware. If you want a privacy horror story, check out Microsoft Recall.

The Linux ThinkPad

I’ve used ThinkPads forever, like, since they were IBM. I was tempted to buy a Mac but, for this exercise, I wanted to have familiar hardware and change only the operating system. Lenovo sold me the accustomed T16 preloaded with Ubuntu Linux, which probably saved about $100.

One fun thing I learned is that hardware manufacturers feel the pain from Windows, not only because the license takes a big slice of their gross, but because they end up fielding the support calls! Here is Dell opting out, and here is HP.

You can set up Linux to look and feel exactly like Windows, if you wish, using distros like Zorin and Mint. It’s a testament to Ubuntu’s flexibility that people are running around creating distros that emulate other operating systems – MacOS, too.

My Ubuntu Stack

What I wanted, though, was the most vanilla, mainstream Linux experience I could get – and still be compatible with my Microsoft-oriented day job. That’s Ubuntu Linux with Gnome. Here are the apps:

  • VS Code – Obviously. I miss Notepad++ but, if you live in VS Code anyway, you can use it as a general-purpose file editor.
  • Kate – This is my one concession, so far, to the KDE ecosystem. I installed it mainly to handle markdown files. I also use the default Gnome text editor.
  • Only Office – This is for compatibility with MS-Office files. Libre Office is also popular. I can also run the MS 365 web versions (on my employer’s tenant) in Chrome.
  • Chrome – Again, for Microsoft compatibility. I run Outlook and Teams in Chrome – as Progressive Web Apps (PWA) to be exact, so they launch from my dock just like they do on Windows.
  • Firefox – This is my default browser, not Chrome – for privacy purposes. Did I mention privacy? I’m only running Chrome for the work stuff.
  • Thunderbird – I remember running Thunderbird email twenty years ago, and it still looks the same. Battle tested. This for my Virag Consulting mail. My work mail stays in Chrome.
  • Nemo – I replaced the default Gnome file manager with Nemo because I prefer its tree view. Much like File Explorer on Windows.
  • Network Share – Linux can access files on my Windows computer using the SMB protocol. This is the mount command in bash, but it’s much easier just to connect with Nemo.
  • Syncthing – I like to keep an offline copy of my network share on the laptop. It’s rare these days to be without an internet connection, but you never know.
  • Clipboard Indicator – This is Win-V on Windows, one of those little things you don’t notice until you don’t have it.
  • Flameshot – You’ll need a replacement for Snagit. There are a bunch. I chose Flameshot.
  • Slack – No surprise, Slack runs on Linux. Download the DEB version. Ubuntu is Debian-based, and you’ll be installing with APT.

That’s pretty much everything I need to work, travel, and code both personal and job-related. The Interactive Brokers trading app is a little rough, but they’re trying. At least they have a Linux app, and you can always trade on a web site – or your phone.

Claude, help me remap the Copilot key

I run four “workspaces,” which roughly match the four monitors I have at home. Teams and Outlook sit at the end, and I just Super-4 over there when I want to check my work messages. This is an old Linux feature that Windows recently caught up with.

Not only is TensorFlow happier on Linux, but so is Claude Code. It was always weird running Claude in a WSL window, with program files and test data in Windows. And, you don’t need to be coding! You can just start Claude in a terminal window and ask, “Claude, help me remap the Copilot key.”

Online Training

I have used Linux off and on over the years, but I needed a refresher, so I took Coursera’s online class, The Software Developer’s Guide to Linux. This lived up to the name. It was spot-on what I needed – Linux topics tailored for a developer, with enough of the sysadmin stuff to keep me out of trouble. I love being able to get just-in-time training for whatever my current project is.

I find that my usage style has changed with Linux. With Windows, I would faithfully shut down the laptop between sessions, and I’d be careful always to have power. Linux doesn’t seem to use much power, so I mostly just close the lid and let it suspend. I do a restart about once a week, for good measure.

The whole user experience, once you get used to it, just seems less brittle. If you’ve been fatigued with the Windows crap, as I was, hopefully this article encourages you to give Linux a try.

Saaspocalypse Now

For my sins, I have joined the “AI not kill SaaS” debate. I am motivating this with the Salesforce stock chart, which went off 30% in the recent “Saaspocalypse.” Charts for Thomson Reuters, Service Now, and Atlassian look about the same.

By 2030, more than 60 percent of software economics could flow through agentic systems rather than legacy SaaS seats.

So, why are people debating an accomplished fact? Because of a faulty thesis. This thesis (which I have actually read, not naming names) is that someone can vibe code a new Salesforce. This is a strawman. That’s not the thesis that wiped out $300 billion of market cap.

Someone probably could vibe code a new Salesforce app, but – that’s obviously not the same as killing Salesforce, the company, nor SaaS in general.

The thesis, according to Satya Nadella, is that business logic will come to reside in AI agents, leaving SaaS systems as mere databases. According to Goldman Sachs, by 2030, more than 60 percent of software usage could flow through agentic systems rather than legacy SaaS seats.

The fact that a single, well-prompted AI agent can now do the job of five or ten “seats” does not bode well for the old framework.

The more recent stock tankage in February – that 16% gap down in Thomson Reuters – is attributable to Claude Cowork, coupled with that day’s release of a prompt that does legal contract review. Yes, one single prompt. Again, it’s not feature coding – it’s the pricing model.

Consider Salesforce, for example. Each literal headset-wearing agent needs a “seat license.” With Claude Cowork, no human agent would ever interact directly with Salesforce. Robots talk to Salesforce, with 10X efficiency, and only escalate to humans when they have to.

As Phil Rosen puts it, “the fact that a single, well-prompted AI agent can now do the job of five or ten seats does not bode well for the old framework.”

None of this says that SaaS is dead, exactly. What it says is that SaaS vendors need to reinvent themselves – something legacy “growth to value” companies have historically failed to do.