File size: 917 Bytes
c81f977
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Prosody DistilBERT Text Classifier

Fine-tuned `distilbert-base-uncased` for binary page classification in the
[Princeton Prosody Archive](https://prosody.princeton.edu/) corpus, using page
**text** (OCR transcription) only.

- **Classes:** `TU` (0), `non-TU` (1)
- **Architecture:** `DistilBertForSequenceClassification` (HF-native)

```python
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import torch

model = AutoModelForSequenceClassification.from_pretrained("./distilbert-text")
tok   = AutoTokenizer.from_pretrained("./distilbert-text")

enc = tok("a line of verse ...", truncation=True, max_length=512, return_tensors="pt")
with torch.no_grad():
    probs = model(**enc).logits.softmax(-1)[0]
print({model.config.id2label[i]: float(p) for i, p in enumerate(probs)})
```

`label_encoder.pkl` is the original sklearn `LabelEncoder` (`class1`->0, `class2`->1)
kept for provenance.