Sebastian Raschka ★ 86 5 min

Language Models for Text Classification: From Bag-of-Words to Jev

🔗 https://magazine.sebastianraschka.com/p/classifier-history-and-jev

📌 從詞袋模型到 Jev:一段文字分類的技術演進史

TL;DR:Jev 爆紅背後,其實是文字分類技術數十年演進的縮影,讀懂歷史才看得懂它的真正定位。

過去兩週,Jev 這個新模型在技術社群掀起一波熱議。乍看之下,它「只是」一個分類器,但知名機器學習作者 Sebastian Raschka 坦言,自己對 Jev 的看法從「這種東西我隨手就能做」轉變成「這比我想像中好用很多」。要理解這個轉折,得先回頭看文字分類技術是怎麼一路走過來的。

🤔 Jev 到底是什麼,為什麼難以一句話說清楚

Raschka 指出,Jev 的定位頗為尷尬。比起最新的 GPT 與開源 LLM,Jev 能做的分類任務它們同樣做得到,而且 LLM 還能處理更廣泛的決策任務;但 Jev 的賣點在於,同樣的分類工作它跑得更快、也更便宜。另一方面,若拿 Jev 對比針對單一任務設計的專用分類器,Jev 在準確度、速度、成本上不見得佔優勢,它真正的優勢是「更泛用」,不必為每個任務重新打造一個模型。這也是為什麼「Jev 本質上是個文字分類器」,卻又「不只是」文字分類器。

🧩 從詞袋模型講起:機器怎麼理解一整段文字

在 Transformer 出現之前,文字分類的標準做法是詞袋模型(bag-of-words)。概念很單純:先用訓練集裡所有出現過的字詞建立詞彙表(vocabulary),可以選擇性去除「a」「the」這類幾乎不帶語意的停用詞(stopword),接著把每份文件轉成固定長度的向量,向量中每個位置對應詞彙表裡的一個字,數值則是該字在文件中出現的次數(也可以改用 TF-IDF 之類的正規化方式)。舉例來說,若詞彙表有 5 萬個字,不論輸入文件是 10 個字還是 30 萬個字,最後都會被壓成一個 5 萬維的向量,而且大多數位置是零,因為單一文件通常只會用到詞彙表裡的一小部分字。

有了這種固定大小的向量,就能套用單純貝氏(naive Bayes)、邏輯迴歸(logistic regression)、SVM、隨機森林、XGBoost 等經典分類器來訓練。Raschka 提到一個流傳已久的說法:Gmail 最早的垃圾郵件過濾器,據稱就是用詞袋表示法搭配單純貝氏模型。這套方法運算成本低,在垃圾郵件過濾這類「某些關鍵字就能強烈暗示標籤」的任務上往往已經夠用。

不過詞袋模型有個致命傷:它完全丟失了詞序。「the dog bites the man」跟「the man bites the dog」在詞袋表示法下會產生一模一樣的向量,儘管兩句話描述的是完全不同的事件。雖然可以加入 n-gram(詞組)當作額外特徵保留一些局部順序資訊,但代價是詞彙表會急遽膨脹。即便如此,Raschka 表示詞袋模型加邏輯迴歸至今仍是他面對任何文字分類問題時的第一個 baseline,因為實作起來實在太簡單。

🧩 embedding 登場:用密集向量取代逐字計數

為了保留句子結構,CNN 與 RNN 等神經網路架構改用詞嵌入(word embedding)取代詞袋表示法。兩者差異在於:詞袋向量是用整份文件裡每個詞出現的次數代表整篇文字,詞嵌入則是把「單一個詞」轉換成一個學習出來的密集向量,運作方式跟 LLM 裡的 embedding 層很類似,都是把輸入 token 轉成密集向量。

embedding 可以在模型外部先訓練好,例如 Word2Vec、GloVe 這兩個經典方法,也可以直接作為神經網路架構的一部分,在訓練過程中一併學習與調整。但這些傳統 embedding 有個共同限制:查詢時是與上下文無關的(context-independent)。也就是說,「bank」這個字不管出現在「river bank」還是「bank account」裡,拿到的都是同一個向量,這也是後來 attention 機制被拿來解決上下文問題的原因之一。

💡 Jev 的座標:介於專用分類器與通用 LLM 之間

把這段歷史放回 Jev 身上,會更容易看懂它的定位。從詞袋模型、傳統 embedding 加 RNN/CNN,一路走到 Transformer 與 LLM,文字分類技術其實是沿著「犧牲泛用性換效率」與「犧牲效率換泛用性」這條軸線持續拉扯。Jev 選擇了一個特定的位置:比通用 LLM 更快更便宜,比專用分類器更泛用,這正是它能在技術社群引發討論的原因。

🎯 實務啟示

在動手為新任務訓練或呼叫一個專用分類模型之前,不妨先想清楚自己真正需要的是「泛用的決策能力」還是「特定任務的極致效率」。詞袋模型加邏輯迴歸這種老派做法,至今仍是驗證問題可行性最快的 baseline;而像 Jev 這樣介於兩者之間的模型,也提醒我們分類技術的選型不是只有「上 LLM」或「土法煉鋼」兩個選項。

🔗 來源

#Jev #TextClassification #NLP #BagOfWords #WordEmbeddings #Word2Vec #MachineLearning #LLM #SebastianRaschka #NaiveBayes

原始資料 Sebastian Raschka · 收集於 2026-09-29
來源原標題
Language Models for Text Classification: From Bag-of-Words to Jev
作者
Sebastian Raschka
原始標籤
blog
原始連結
https://magazine.sebastianraschka.com/p/classifier-history-and-jev

摘要原文

The recently released Jev AI model has been quite a cultural phenomenon in technical communities in the past 2 weeks. While Jev aims to classify things, it’s easy to dismiss Jev as “just a classifier,” and my own view of Jev has evolved quite a bit over the past few days. In particular, my thoughts went from “classifiers used to be my bread & butter; I can easily build this myself” (more on this later) to “wow, this actually works better than I thought.” Sure, the latest state-of-the-art GPT and open-weight LLMs can do the same kinds of classification tasks as Jev, while also being capable of much more general decision-making. But Jev’s advantage is that it can handle those classification tasks much faster and more cheaply. At the other end of the spectrum, for a narrow, well-defined problem, Jev probably won’t classify anything better, faster, or cheaper than a special-purpose classifier. But its selling point is that it is far more general than those task-specific models. So, what is the methodology behind Jev (based on an educated guess), what can it do, and why is it so popular? I aim to answer all of these later in this article. However, I thought starting with a brief history of language models for decision-making would be a great way to begin. And it hopefully helps demystify some of the hype and show what Jev does very well (”Jev is essentially a text classifier,” but “Jev is also not ‘just’ a text classifier.”) PS: I am not affiliated with Jev in any way. Also, I am not offered free access to Jev, and this is also not a product endorsement, just a technical article to offer some insights into the history of text classification to help you make sense of the recent hype. Since this is a long article, I recommend reading it in your browser , where you can access the table of contents menu on the left side. For completeness, before we put Jev in context (no pun intended), I thought it made the most sense to start chronologically. In this section, I want to take a brief tour of applied text classification via naive Bayes, logistic regression, and the more classic (deep) neural networks before transformer-based models came along. Back in the day, when I was a grad student 15 years ago, even though recurrent neural networks already existed (more on that later), text classification was usually done with a bag-of-words representation because it was straightforward and could get good results on moderately sized datasets. In short, we can think of the bag-of-words representation as a method that makes free-form text input of different lengths compatible with classic classifiers (naive Bayes, Logistic Regression, SVMs, Random Forest, XGBoost, to name a few), which expect a fixed-size input vector. Popular real-world applications include anything from news article classification to email spam filtering. And yes, allegedly even Gmail’s original spam filter used a Naive Bayes model with a bag-of-words representation. As a side note, I wrote about this approach exactly 12 years ago. It was one of the first things I shared on arXiv. So, what exactly is this bag-of-words representation? It’s a way to convert free-form texts with different lengths, e.g., Training example 1: “Zentropa is the most original movie I’ve seen in years. If you like unique thrillers that are influenced by film noir, then this is just the right cure for all of those Hollywood summer blockbusters clogging the theaters these days. Von Trier’s follow-ups like Breaking the Waves have gotten more acclaim, but this is really his best work.” Training example 2: “This film is just plain horrible. John Ritter doing pratt falls, 75% of the actors delivering their lines as if they were reading them from cue cards, poor editing, horrible sound mixing” Training example 3: “Zentropa has much in common with The Third Man, another noir-like film set among the rubble of postwar Europe.” into a fixed-size representation for the aforementioned “classic” classifiers. (The example above is an excerpt from the popular IMDb movie review classification dataset .) A bag-of-words model starts by building the vocabulary, which consists of all unique words in the training set (optionally, one can get rid of so-called stopwords like “a” and “the”, which are words that carry little to no semantic meaning in most contexts). A bag-of-words representation results in these fixed-size inputs by assigning each word in a vocabulary its own position in a vector. We then count how often each word occurs in a document. For example, if we have a vocabulary of 50,000 unique words, it produces a fixed-size vector with 50,000 entries, regardless of whether the input consists of only ten words or 300k words. Note that most entries are zero because each document contains only a small subset of the vocabulary. (Instead of representing the raw counts, there are also normalization schemes like TF-IDF.) Then, once we have these word frequency vectors, we can train a classifier on a labeled training set, such as emails labeled as spam or non-spam. For example, a logistic regression model would then learn feature weights that correlate certain words (and word counts) with particular labels. For instance, certain words might increase the predicted spam probability, and others may decrease it. This approach is computationally cheap and can work well when particular words provide strong clues about the label. In a simple classification task such as spam classification, this is often enough to get quick, reasonably accurate results. But one of the biggest downsides of this approach is that, because of the nature of the bag-of-words representation, it loses word order. So, for example, “the dog bites the man” and “the man bites the dog” produce identical vectors despite describing different events. (There are some workarounds to preserve some local order by adding word pairs or longer sequences, called n-grams, as features, although this increases the vocabulary size.) Despite the shortcomings, I still think that a bag-of-words has its place in certain low-stakes applications because it’s so cheap, and a bag-of-words representation + logistic regression remains my go-to baseline for every text classification problem, since it’s so easy to implement. The aforementioned bag-of-words model would also work with (simple) deep neural networks, like multilayer perceptrons. But the downside still is that we would lose the sentence structure and word order. However, more sophisticated neural network architectures avoid the bag-of-words workaround: convolutional neural networks (CNNs) and recurrent neural networks (RNNs), which can take word embeddings as input. First, before feeding the input texts into a model, we have to convert them into a suitable representation. One such representation is bag-of-words. Another is word embedding vectors. The difference is that a bag-of-words vector represents the entire text by counting how often each vocabulary word occurs, while a word embedding represents an individual word as a dense vector of learned numbers. Word embeddings work similarly to embedding layers in LLMs, i.e., they convert input tokens into dense vectors. Embeddings can happen outside the model (e.g., two classic, popular methods for learning them are Word2Vec and GloVe ), or the embedding layer can be part of the neural network architecture itself and be learned and tuned during model training. These classic embeddings are context-independent at lookup time. The word “bank”, for example, gets the same vector in “river bank” and “bank account” (as you may know, context can be handled via concepts like attention). For additional resources on embeddings, you may find the following ones helpful: Chapter 2: Working with Text Data (this is an LLM chapter but should give you the gist of embedding words or tokens; in LLM tokenizers, we split words into subword tokens; in Word2Vec, 1 word is usually 1 token.

由 claude-code/sonnet 自動生成