billfass commited on
Commit ·
715c3cc
1
Parent(s): 44db328
Initial commit of BertModel and tokenizer
Browse files
README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
|
| 3 |
+
# Custom BERT Model for Text Classification
|
| 4 |
+
|
| 5 |
+
## Model Description
|
| 6 |
+
|
| 7 |
+
This is a custom BERT model fine-tuned for text classification. The model was trained using a subset of a publicly available dataset and is capable of classifying text into 3 classes.
|
| 8 |
+
|
| 9 |
+
## Training Details
|
| 10 |
+
|
| 11 |
+
- **Architecture**: BERT Base Multilingual Cased
|
| 12 |
+
- **Training data**: Custom dataset
|
| 13 |
+
- **Preprocessing**: Tokenized using BERT's tokenizer, with a max sequence length of 80.
|
| 14 |
+
- **Fine-tuning**: The model was trained for 1 epoch with a learning rate of 2e-5, using AdamW optimizer and Cross-Entropy Loss.
|
| 15 |
+
- **Evaluation Metrics**: Accuracy on a held-out validation set.
|
| 16 |
+
|
| 17 |
+
## How to Use
|
| 18 |
+
|
| 19 |
+
### Dependencies
|
| 20 |
+
- Transformers 4.x
|
| 21 |
+
- Torch 1.x
|
| 22 |
+
|
| 23 |
+
### Code Snippet
|
| 24 |
+
|
| 25 |
+
For classification:
|
| 26 |
+
|
| 27 |
+
```python
|
| 28 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 29 |
+
import torch
|
| 30 |
+
|
| 31 |
+
tokenizer = AutoTokenizer.from_pretrained("billfass/my_bert_model")
|
| 32 |
+
model = AutoModelForSequenceClassification.from_pretrained("billfass/my_bert_model")
|
| 33 |
+
|
| 34 |
+
text = "Your example text here."
|
| 35 |
+
|
| 36 |
+
inputs = tokenizer(text, padding=True, truncation=True, max_length=80, return_tensors="pt")
|
| 37 |
+
labels = torch.tensor([1]).unsqueeze(0) # Batch size 1
|
| 38 |
+
|
| 39 |
+
outputs = model(**inputs, labels=labels)
|
| 40 |
+
loss = outputs.loss
|
| 41 |
+
logits = outputs.logits
|
| 42 |
+
|
| 43 |
+
# To get probabilities:
|
| 44 |
+
probs = torch.softmax(logits, dim=-1)
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
## Limitations and Bias
|
| 48 |
+
|
| 49 |
+
- Trained on a specific dataset, so may not generalize well to other kinds of text.
|
| 50 |
+
- Uses multilingual cased BERT, so it's not optimized for any specific language.
|
| 51 |
+
|
| 52 |
+
## Authors
|
| 53 |
+
|
| 54 |
+
- **Fassinou Bile**
|
| 55 |
+
- **billfass2010@gmail.com**
|
| 56 |
+
|
| 57 |
+
## Acknowledgments
|
| 58 |
+
|
| 59 |
+
Special thanks to Hugging Face for providing the Transformers library that made this project possible.
|
| 60 |
+
|
| 61 |
+
---
|