Views
No views yet
| Label | Precision | Recall | F1-Score | Support |
|---|---|---|---|---|
| 0 | 0.98 | 0.99 | 0.98 | 796 |
| 1 | 0.79 | 0.70 | 0.74 | 60 |
| Accuracy | 0.97 | 856 | ||
| Macro Avg | 0.89 | 0.84 | 0.86 | 856 |
| Weighted Avg | 0.96 | 0.97 | 0.97 | 856 |
pip install transformers1from transformers import pipeline
2
3pipe = pipeline(
4 "text-classification",
5 model="taishi-i/awesome-japanese-nlp-classification-model",
6)
7
8# Relevant sample
9text = "ディープラーニングによる自然言語処理(共立出版)のサポートページです"
10label = pipe(text)
11print(label) # [{'label': '1', 'score': 0.9910495281219482}]
12
13# Not Relevant sample
14text = "AIイラストを管理するデスクトップアプリ"
15label = pipe(text)
16print(label) # [{'label': '0', 'score': 0.9986791014671326}]pip install evaluate scikit-learn datasets transformers torch1import evaluate
2from datasets import load_dataset
3from sklearn.metrics import classification_report
4from transformers import pipeline
5
6# Evaluation dataset
7dataset = load_dataset("taishi-i/awesome-japanese-nlp-classification-dataset")
8
9# Text classification model
10pipe = pipeline(
11 "text-classification",
12 model="taishi-i/awesome-japanese-nlp-classification-model",
13)
14
15# Evaluation metric
16f1 = evaluate.load("f1")
17
18# Predict process
19predicted_labels = []
20for text in dataset["test"]["text"]:
21 prediction = pipe(text)
22 predicted_label = prediction[0]["label"]
23 predicted_labels.append(int(predicted_label))
24
25score = f1.compute(
26 predictions=predicted_labels, references=dataset["test"]["label"]
27)
28print(score)
29
30report = classification_report(
31 y_true=dataset["test"]["label"], y_pred=predicted_labels
32)
33print(report)