# ai_tnews **Repository Path**: soft_study/ai_tnews ## Basic Information - **Project Name**: ai_tnews - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-18 - **Last Updated**: 2026-06-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # TNEWS 文本分类(PyTorch + sklearn) 满足:数据预处理 + 4类模型(NB/TextCNN/BERT/Prompt API)+ 统一评测指标 + TensorBoard。 ## 1. 安装 ### 1.1 使用 pip 建议使用虚拟环境,然后: ```bash pip install -r requirements.txt ``` ## 2. 快速开始 ### 2.1 朴素贝叶斯(字符 n-gram) ```bash python run.py --model nb --vectorizer char --ngram_max 4 --run_name nb_char4 --seed 2025 ``` ### 2.2 TextCNN(字符级) ```bash python run.py --model textcnn --max_len 128 --embed_dim 200 --num_epochs 5 --batch_size 64 --run_name textcnn_char --seed 2025 (tnews) PS D:\gitee\ai_tnews> cat .\outputs\textcnn_char\metrics_test.json ``` TensorBoard: ```bash conda activate tnews python -m pip uninstall tensorboard -y powershell by admistrator new powersehll by common user (base) PS D:\gitee\ai_tnews> conda activate tnews (tnews) PS D:\gitee\ai_tnews> where.exe tensorboard C:\ProgramData\miniconda3\envs\tnews\Scripts\tensorboard.exe (tnews) PS D:\gitee\ai_tnews> Get-Command tensorboard CommandType Name Version Source ----------- ---- ------- ------ Application tensorboard.exe 0.0.0.0 C:\ProgramData\miniconda3\envs\tnews\S... (tnews) PS D:\gitee\ai_tnews> tensorboard --logdir runs or python -m tensorboard.main --logdir runs copy http://localhost:6006 to edge and enter ``` ### 2.3 BERT(bert-base-chinese) ```bash python run.py --model bert --model_name bert-base-chinese --max_len 128 --num_epochs 3 --batch_size 16 --lr 2e-5 \ --run_name bert_base ``` ### 2.4 Prompt + API(可选) 需要 OpenAI 兼容接口: ```bash export OPENAI_API_KEY=xxx export OPENAI_BASE_URL=https://api.openai.com/v1 export OPENAI_MODEL=gpt-4.1-mini ``` 运行: ```bash python run.py --model prompt --run_name prompt_api ``` ## 3. 输出 每次运行会在 `outputs//` 下生成: - `metrics_val.json` / `metrics_test.json`(含 accuracy/precision/recall/F1 + confusion matrix) - `errors_val.jsonl` / `errors_test.jsonl`(错误样例与预测信息) - `pred_test.jsonl`(对无标签 test 的预测,包含 id/label) 深度学习模型的 TensorBoard 日志在 `runs//`。