Views
No views yet
1from typing import List
2import re
3from huggingface_hub import hf_hub_download
4import fasttext
5
6
7model_hf = fasttext.load_model(hf_hub_download("kenhktsui/fineweb-edu-fasttext-classifier", "model.bin"))
8
9
10def replace_newlines(text: str) -> str:
11 return re.sub("\n+", " ", text)
12
13
14def predict(text_list: List[str]) -> List[dict]:
15 text_list = [replace_newlines(text) for text in text_list]
16 pred = model_hf.predict(text_list)
17 return [{"label": int(l[0].lstrip("__label__")), "score": s[0]}
18 for l, s in zip(*pred)]
19
20
21predict(["Hi"])
22# Output: [{'label': 0, 'score': 1.00001}]
23 precision recall f1-score support
0 0.72 0.44 0.55 5704
1 0.73 0.87 0.80 26595
2 0.52 0.49 0.50 10350
3 0.48 0.33 0.39 3397
4 0.69 0.03 0.06 819
5 0.00 0.00 0.00 2
accuracy 0.68 46867
macro avg 0.52 0.36 0.38 46867
weighted avg 0.67 0.68 0.66 46867| Label | This Model | HuggingFaceFW/fineweb-edu-classifier |
|---|---|---|
| 0 | 0.55 | 0.59 |
| 1 | 0.80 | 0.81 |
| 2 | 0.50 | 0.59 |
| 3 | 0.39 | 0.53 |
| 4 | 0.06 | 0.44 |
| 5 | 0.00 | 0.02 |
[ 2537 3098 65 4 0 0]
[ 944 23037 2491 123 0 0]
y_true [ 26 4742 5048 533 1 0]
[ 4 434 1846 1105 8 0]
[ 0 38 213 544 24 0]
[ 0 0 0 0 2 0]
y_pred| Predicted - Actual Rating | Frequency | % |
|---|---|---|
| 0 | 31751 | 67.7% |
| -1 | 8078 | 17.2% |
| +1 | 6130 | 13.1% |
| -2 | 673 | 1.4% |
| +2 | 189 | 0.4% |
| -3 | 42 | 0.1% |
| +3 | 4 | 0.0% |
@misc{ktsui2024cpueduvalue,
title={Low Latency CPU Based Educational Value Classifier With Generic Educational Value},
author={Ken Tsui and Huu Nguyen},
year={2024},
}