0Pricing
NLP Academy · 课时

在全新文本上进行预测

对未见过的输入执行推理

在全新文本上进行预测 是 CoddyKit 上的免费 NLP Academy 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 NLP Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 NLP Academy 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

Inference Time

Training is done. Now comes inference: feeding brand-new, unseen text to your saved model and reading back its prediction. 🚀

Load the Model First

Start every prediction script by loading the saved pipeline. From here it behaves exactly like the model you trained.

import joblib
model = joblib.load("models/sentiment.joblib")

Predict Expects a List

The predict method takes a list of texts, not a single string. Even one example must be wrapped in a list.

model.predict(["the food was amazing"])

Predict Many at Once

Pass a whole list to score many texts in one go. Batch prediction is far faster than looping one item at a time.

texts = ["loved it", "total waste of money"]
print(model.predict(texts))

Get Probabilities

Want confidence, not just a label? Call predict_proba to see how sure the model is about each class.

model.predict_proba(["it was okay i guess"])

Same Cleaning as Training

New text must go through the same cleaning as your training data. The pipeline handles this, which is exactly why you saved it whole.

Unknown Words Are Fine

Words the model never saw are simply ignored by the vectorizer. Your vocabulary is fixed at training time, so prediction stays stable.

Map Labels to Names

Models often return numbers like 0 and 1. Turn them into a readable label name so people can understand the output.

names = {0: "negative", 1: "positive"}
print(names[model.predict(["great"])[0]])

Wrap It in a Function

Wrap loading and predicting in one helper function. Now any part of your app can classify text with a single clean call.

def classify(text):
    return model.predict([text])[0]

Watch for Drift

Real text changes over time. When accuracy slips, that is data drift, a signal it is time to retrain on fresh examples.

Serve It Anywhere

Your classify function can sit behind a web API or a script. The same saved model now powers real predictions in production. 🎯

Quick Check

Think about the input format predict requires.

Recap

You loaded the model, predicted on new text in batches, read probabilities, mapped labels, wrapped it in a function, and watched for drift. 🏁

常见问题解答

「在全新文本上进行预测」课时是免费的吗?

是的 — 「在全新文本上进行预测」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 NLP Academy 课程的其余内容,请升级到 CoddyKit PRO。 NLP Academy 课程共包含 4 节课。

「在全新文本上进行预测」这节课中我会学到什么?

对未见过的输入执行推理 你通过在浏览器中直接运行的动手代码来练习 NLP Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 NLP Academy 需要有经验吗?

无需任何先前经验。CoddyKit 上的 NLP Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。

「在全新文本上进行预测」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 NLP Academy 课中编写并运行代码吗?

能。每节 NLP Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 构建一个真正的自然语言处理项目
  2. 端到端使用 scikit-learn 流水线
  3. 保存与加载您的模型
  4. 在全新文本上进行预测
← 返回 NLP Academy