eriktobben/hermes-backup/bert-text-classification

Claude Code and agent skill by eriktobben/hermes-backup

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Fine-tune BERT encoder models for text classification (spam detection, email routing, intent classification). Covers full lifecycle: data prep → training → FastAPI microservice → Laravel/backend integration.

Install

npx vskill@latest install eriktobben/hermes-backup/bert-text-classification

SKILL.md

The same SKILL.md was published earlier as eriktobben/hermes-backup/bert-text-classification.

BERT Text Classification

Fine-tune small encoder-only transformer models (BERT, DistilBERT, RoBERTa, etc.) for text classification tasks — spam detection, email routing, intent classification, sentiment analysis, content tagging.

Why BERT over an LLM for classification

AspectBERT encoderLLM (generative)
Model size85–180 MB1–8 GB (quantized)
Inference speed~50 ms (CPU)~500 ms–2 s (CPU)
Accuracy on classificationExcellentGood, but overkill
Training data needed50–200 per class100–1000+
MacBook Air M220–50 eposter/sek2–5 sek per epost

Rule of thumb: For any task that outputs a single label from a fixed set (spam/not-spam, kategori A/B/C), BERT is the right tool. Reach for an LLM only when you need free-text reasoning or multi-label with complex dependencies.

Quick start

1. Choose a model
python
# Norsk (anbefalt for norske eposter)
MODEL_NAME = "NbAiLab/nb-bert-base" # ~110 MB
# Engelsk (raskest, minst)
MODEL_NAME = "distilbert-base-uncased" # ~85 MB
# Flerspråklig
MODEL_NAME = "bert-base-multilingual-cased" # ~180 MB
2. Prepare data
python
data = {
"text": ["eposttekst 1", "eposttekst 2", ...],
"label": ["kategori_a", "kategori_b", ...],
}

Minimum 50–100 eksempler per klasse.

3. Fine-tune

See templates/train.py for a complete training script.

Key transformers v5 API differences from older versions:

Old (v4)New (v5)
tokenizer=tokenizer (Trainer arg)processing_class=tokenizer
label_id column namelabels column name
Trainer(tokenizer=...)Trainer(processing_class=...)
4. Deploy as FastAPI microservice
bash
python serve.py
# Lytter på http://localhost:8000

See templates/serve.py for the server template.

5. Integrate with Laravel

See references/laravel-integration.md for the controller, routes, and config.

6. Process management (Supervisor)

See templates/supervisor.conf — drop into /etc/supervisor/conf.d/ on a Forge server.

Model selection guide

Use caseModelSizeMSGNotes
Norske eposterNbAiLab/nb-bert-base110 MB20/s🇳🇴 Best for norsk tekst
Engelsk, trenger fartdistilbert-base-uncased85 MB30/sRaskest, minst
Flere språkbert-base-multilingual-cased180 MB15/s100+ språk
Norsk, eksperimentellNbAiLab/nb-bert-small50 MB40/sMindre, raskere

Deployment architecture (Laravel + Python microservice)

Email client → Laravel API (/api/epost/klassifiser)
→ HTTP → FastAPI microservice (:8000)
→ nb-bert → "må_svare" (87%)
→ JSON response → Laravel → client

Training tips

  • Balanced dataset: Roughly equal examples per class prevents bias
  • Real data > synthetic: Label real emails from your inbox
  • More data = better accuracy: 50/class → ~80%, 200/class → ~90%+
  • Early stopping: Monitor eval loss; stop when it plateaus
  • Augment with synonyms if data is scarce

Pitfalls

  • distilbert-base-uncased is English-only — don't use for Norwegian text. The tokenizer strips æøå and lowercases everything. Use nb-bert-base instead.
  • transformers v5 API changes caught many users — tokenizer renamed to processing_class in Trainer, label_id must be labels in dataset. Check version with transformers.__version__.
  • Training on CPU is slow for BERT-base (~3s/step on 100 examples). For 500+ examples consider a GPU (RunPod ~$0.50/hr) or use distilbert.
  • Model memory on server: ~300 MB RAM per model instance. Factor this into server sizing (2 vCPU/4 GB is fine for 1 model).
  • ONNX export is possible but not necessary — PyTorch inference is fast enough on CPU for this use case.

References

  • references/laravel-integration.md — Laravel controller, routes, config, .env setup
  • references/nb-bert.md — Norwegian BERT model details and alternatives

Templates

  • templates/train.py — Complete training script with data prep, tokenization, training loop, evaluation
  • templates/serve.py — FastAPI microservice with health check, classify, batch endpoints
  • templates/supervisor.conf — Supervisor config for Forge/Linux servers

Scripts

  • (none yet)

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/eriktobben/hermes-backup/bert-text-classification/badge)](https://verified-skill.com/skills/eriktobben/hermes-backup/bert-text-classification)

Something wrong with this skill or its page? Tell us.