Views
No views yet
| Label ID | Category |
|---|---|
| 0 | World |
| 1 | Sport |
| 2 | Business |
| 3 | Science & Technology |
bert-base-uncasedAutoTokenizer with truncation and dynamic padding enabled.save_pretrained() and uploaded to the Hugging Face Hub.1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4# Load model from the Hub
5model_name = "zacanadir/wsbt-sequence-classifier"
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
9MAX_LENGTH = 200
10
11def predict_text(text_list):
12 encodings = tokenizer(
13 text_list,
14 padding=True,
15 truncation=True,
16 max_length=MAX_LENGTH,
17 return_tensors="pt"
18 ).to(model.device)
19
20 model.eval()
21 with torch.no_grad():
22 outputs = model(**encodings)
23 preds = torch.argmax(outputs.logits, dim=-1)
24 return preds.tolist()
25
26# Example
27sample_texts = [
28 "Nvidia becomes the first chipmaker to top $5 trillion in market value.",
29 "The Raja of Casablanca advances to the semi final of the African Champions' League."
30]
31
32label_to_category = {
33 0: "World",
34 1: "Sport",
35 2: "Business",
36 3: "Science & Technology"
37}
38
39preds = predict_text(sample_texts)
40predicted_categories = [label_to_category[int(i)] for i in preds]
41print(predicted_categories)
42
43🧾 Output Example
44['Business', 'Sport']
45
46🚀 How to Reuse / Fine-tune Further
47
48If you’d like to fine-tune this model on your own dataset:
49
50from transformers import Trainer, TrainingArguments, AutoTokenizer, AutoModelForSequenceClassification
51from datasets import load_dataset
52
53tokenizer = AutoTokenizer.from_pretrained("zacanadir/wsbt-sequence-classifier")
54model = AutoModelForSequenceClassification.from_pretrained("zacanadir/wsbt-sequence-classifier", num_labels=4)
55
56# Load your dataset and fine-tune
57
58📦 Files Included
59File Description
60config.json Model architecture & label mapping
61pytorch_model.bin Trained weights
62tokenizer.json, vocab.txt, special_tokens_map.json Tokenizer files
63training_args.bin Trainer configuration (epochs, LR, etc.)
64
65✨ Acknowledgements
66Hugging Face Transformers
67Google Colab for free GPU training
68PyTorch
69
70Trained and deployed with ❤️ using Hugging Face and Google Colab.