Datasets:
Tasks:
Text Classification
Formats:
parquet
Sub-tasks:
multi-class-classification
Languages:
Chinese
Size:
1K - 10K
Tags:
poetry
chinese
classical-chinese
sentiment-classification
fine-grained-sentiment
multi-class-classification
License:
Rebuild FSPC Dataset Card + schema (poem/label) + supporting materials (train/test only, no validation)
464033f verified | # -*- coding: utf-8 -*- | |
| """Baseline evaluation for PoetryMTEB/FSPC (holistic 5-class sentiment). | |
| Metrics: accuracy, macro-F1, micro-F1. | |
| Default probe: TF-IDF + LogisticRegression (no GPU required). | |
| Usage: | |
| python evaluate_fspc.py | |
| python evaluate_fspc.py --repo PoetryMTEB/FSPC --max-features 50000 | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| from collections import Counter | |
| from datasets import load_dataset | |
| from sklearn.feature_extraction.text import TfidfVectorizer | |
| from sklearn.linear_model import LogisticRegression | |
| from sklearn.metrics import accuracy_score, f1_score, classification_report | |
| from sklearn.pipeline import Pipeline | |
| def main() -> None: | |
| p = argparse.ArgumentParser() | |
| p.add_argument("--repo", default="PoetryMTEB/FSPC") | |
| p.add_argument("--max-features", type=int, default=50000) | |
| p.add_argument("--seed", type=int, default=42) | |
| p.add_argument("--out-json", default="") | |
| args = p.parse_args() | |
| ds = load_dataset(args.repo) | |
| train, test = ds["train"], ds["test"] | |
| x_train = list(train["poem"]) | |
| y_train = list(train["label"]) | |
| x_test = list(test["poem"]) | |
| y_test = list(test["label"]) | |
| id2name = {} | |
| for lab, name in zip(train["label"], train["label_name"]): | |
| id2name[int(lab)] = name | |
| target_names = [id2name[i] for i in sorted(id2name)] | |
| clf = Pipeline( | |
| [ | |
| ( | |
| "tfidf", | |
| TfidfVectorizer( | |
| analyzer="char", | |
| ngram_range=(1, 3), | |
| max_features=args.max_features, | |
| ), | |
| ), | |
| ( | |
| "lr", | |
| LogisticRegression( | |
| max_iter=2000, | |
| random_state=args.seed, | |
| multi_class="multinomial", | |
| ), | |
| ), | |
| ] | |
| ) | |
| clf.fit(x_train, y_train) | |
| pred = clf.predict(x_test) | |
| metrics = { | |
| "accuracy": float(accuracy_score(y_test, pred)), | |
| "macro_f1": float(f1_score(y_test, pred, average="macro")), | |
| "micro_f1": float(f1_score(y_test, pred, average="micro")), | |
| "n_train": len(y_train), | |
| "n_test": len(y_test), | |
| "label_counts_test": dict(Counter(int(x) for x in y_test)), | |
| "report": classification_report( | |
| y_test, pred, target_names=target_names, digits=4 | |
| ), | |
| } | |
| print(json.dumps({k: v for k, v in metrics.items() if k != "report"}, indent=2)) | |
| print(metrics["report"]) | |
| if args.out_json: | |
| Path = __import__("pathlib").Path | |
| Path(args.out_json).write_text( | |
| json.dumps(metrics, ensure_ascii=False, indent=2), encoding="utf-8" | |
| ) | |
| if __name__ == "__main__": | |
| main() | |