返回提示词目录第 1395 页

训练评估并保存文本分类模型

检查数据并训练传统分类基线,按需微调模型,交付性能对比、错误分析与可加载预测代码。

完整提示词

<context>
For many text classification tasks a TF-IDF plus logistic regression baseline trains in seconds and lands within a few points of a fine-tuned transformer. Teams that skip it cannot tell whether the transformer is worth its serving cost. Other common mistakes: random splits when the same customer or template appears many times, so near-duplicates leak across splits; truncating long texts at 128 tokens without checking how much is lost; reporting accuracy on imbalanced classes; ignoring the label noise that the highest-confidence errors usually reveal; and picking an English-only model for multilingual data. A transformer fine-tune also needs the right head for multi-label (sigmoid with binary cross-entropy, not softmax) and a saved label mapping, or predictions get decoded wrong in production.
</context>

<task>
Train a classifier for: {{task}}

Data: {{data}}
{{#constraints}}

Constraints: {{constraints}}
{{/constraints}}

1. Read the repository's data code and any training scripts; follow its structure, config style and dependency manager.
2. Check the data: label counts, duplicates and near-duplicates (normalised text hash), empty or very short texts, languages, and token length percentiles. Choose the split: grouped by customer, thread or source where the same origin repeats, stratified by label, with a test set locked until the end.
3. Train the baseline: TF-IDF (word and character n-grams) with logistic regression, class weights if imbalanced, tuned on validation only. Report macro-F1, per-class precision and recall, and the confusion matrix.
4. Decide if a transformer is justified: if the baseline already meets the need, say so and stop. Otherwise fine-tune a small pretrained encoder suited to the language and length (a multilingual one for mixed languages), with max length chosen from the token percentiles, the correct head and loss for single- or multi-label, early stopping on validation macro-F1, and a fixed seed.
5. Compare both on the same validation and, once, on the test set. Include inference latency per item on the stated hardware.
6. Review errors: the 30 most confident wrong predictions and the most confused class pairs. Separate label noise, ambiguous definitions and true model errors.
7. Save the chosen model with its label mapping, preprocessing and the versions of the libraries used, plus a small prediction function and a test that loads it and predicts on a fixed example.
8. Run the tests and report what was verified.
</task>

<constraints>
- Do not touch the test set until both models are final.
- Use the library versions already pinned in the project; if adding one, say which and why.
- Do not claim the transformer is better unless the gain exceeds the run-to-run variance; run at least two seeds when the gap is small.
{{> guardrails/scope-discipline}}
{{> guardrails/verify-before-done}}
</constraints>

<output_format>
## Data check
Bullets: counts, duplicates, length, split choice.
## Baseline
Code blocks with file paths and its validation metrics.
## Transformer model
Code blocks with file paths, or why it was not needed.
## Results
Table: model | macro-F1 | weakest class | latency.
## Error review
Patterns found, with examples and their cause.
## Check
Commands run and real results.
## Next steps
Up to three, ranked.
</output_format>

可替换内容

  • {{task}}
  • {{data}}
  • {{#constraints}}
  • {{constraints}}
  • {{/constraints}}
  • {{> guardrails/scope-discipline}}
  • {{> guardrails/verify-before-done}}

分类与标签

编程开发、文本分类、模型训练、基线评估、模型微调、错误分析

前往 AI 图片创作