Text Classification
Transformers
Safetensors
distilbert
sentiment-analysis
new-closed-neutral
colab
text-embeddings-inference
Instructions to use virustechhacks/distil-bert-classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use virustechhacks/distil-bert-classifier with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="virustechhacks/distil-bert-classifier")# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("virustechhacks/distil-bert-classifier") model = AutoModelForSequenceClassification.from_pretrained("virustechhacks/distil-bert-classifier") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,199 +1,204 @@
|
|
|
|
|
| 1 |
---
|
| 2 |
library_name: transformers
|
| 3 |
-
tags: []
|
| 4 |
---
|
| 5 |
|
| 6 |
-
# Model Card for
|
| 7 |
-
|
| 8 |
-
<!-- Provide a quick summary of what the model is/does. -->
|
| 9 |
-
|
| 10 |
|
|
|
|
| 11 |
|
| 12 |
## Model Details
|
| 13 |
|
| 14 |
### Model Description
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
|
| 19 |
|
| 20 |
-
- **Developed by:**
|
| 21 |
-
- **
|
| 22 |
-
- **
|
| 23 |
-
- **
|
| 24 |
-
- **
|
| 25 |
-
- **License:** [More Information Needed]
|
| 26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
| 27 |
|
| 28 |
-
### Model Sources
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
- **Repository:** [More Information Needed]
|
| 33 |
-
- **Paper [optional]:** [More Information Needed]
|
| 34 |
-
- **Demo [optional]:** [More Information Needed]
|
| 35 |
|
| 36 |
## Uses
|
| 37 |
|
| 38 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
| 39 |
-
|
| 40 |
### Direct Use
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
[More Information Needed]
|
| 45 |
|
| 46 |
-
### Downstream Use
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
[More Information Needed]
|
| 51 |
|
| 52 |
### Out-of-Scope Use
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
| 57 |
|
| 58 |
## Bias, Risks, and Limitations
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
|
| 64 |
### Recommendations
|
| 65 |
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
| 69 |
|
| 70 |
## How to Get Started with the Model
|
| 71 |
|
| 72 |
-
Use the code below to
|
| 73 |
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
-
#
|
|
|
|
| 77 |
|
| 78 |
-
#
|
|
|
|
|
|
|
| 79 |
|
| 80 |
-
|
|
|
|
| 81 |
|
| 82 |
-
|
|
|
|
|
|
|
| 83 |
|
| 84 |
-
|
|
|
|
|
|
|
| 85 |
|
| 86 |
-
|
|
|
|
| 87 |
|
| 88 |
-
|
|
|
|
|
|
|
| 89 |
|
| 90 |
-
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
-
|
| 96 |
|
| 97 |
-
###
|
| 98 |
|
| 99 |
-
|
| 100 |
|
| 101 |
-
|
| 102 |
|
| 103 |
-
##
|
| 104 |
|
| 105 |
-
|
| 106 |
|
| 107 |
-
###
|
| 108 |
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
-
|
| 112 |
|
| 113 |
-
|
| 114 |
|
| 115 |
-
##
|
|
|
|
|
|
|
| 116 |
|
| 117 |
-
|
| 118 |
|
| 119 |
-
|
| 120 |
|
| 121 |
#### Metrics
|
| 122 |
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
| 126 |
|
| 127 |
### Results
|
| 128 |
|
| 129 |
-
[More Information Needed]
|
| 130 |
-
|
| 131 |
#### Summary
|
| 132 |
|
|
|
|
| 133 |
|
|
|
|
|
|
|
| 134 |
|
| 135 |
-
|
|
|
|
| 136 |
|
| 137 |
-
|
|
|
|
|
|
|
| 138 |
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
## Environmental Impact
|
| 142 |
|
| 143 |
-
|
| 144 |
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
-
|
| 148 |
-
- **Hours used:** [More Information Needed]
|
| 149 |
-
- **Cloud Provider:** [More Information Needed]
|
| 150 |
-
- **Compute Region:** [More Information Needed]
|
| 151 |
-
- **Carbon Emitted:** [More Information Needed]
|
| 152 |
-
|
| 153 |
-
## Technical Specifications [optional]
|
| 154 |
|
| 155 |
### Model Architecture and Objective
|
| 156 |
|
| 157 |
-
|
| 158 |
|
| 159 |
### Compute Infrastructure
|
| 160 |
|
| 161 |
-
[More Information Needed]
|
| 162 |
-
|
| 163 |
#### Hardware
|
| 164 |
|
| 165 |
-
|
| 166 |
|
| 167 |
#### Software
|
| 168 |
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
**BibTeX:**
|
| 176 |
-
|
| 177 |
-
[More Information Needed]
|
| 178 |
-
|
| 179 |
-
**APA:**
|
| 180 |
-
|
| 181 |
-
[More Information Needed]
|
| 182 |
-
|
| 183 |
-
## Glossary [optional]
|
| 184 |
-
|
| 185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
| 186 |
-
|
| 187 |
-
[More Information Needed]
|
| 188 |
-
|
| 189 |
-
## More Information [optional]
|
| 190 |
-
|
| 191 |
-
[More Information Needed]
|
| 192 |
-
|
| 193 |
-
## Model Card Authors [optional]
|
| 194 |
-
|
| 195 |
-
[More Information Needed]
|
| 196 |
|
| 197 |
## Model Card Contact
|
| 198 |
|
| 199 |
-
[
|
|
|
|
|
|
| 1 |
+
```markdown
|
| 2 |
---
|
| 3 |
library_name: transformers
|
| 4 |
+
tags: ["text-classification", "distilbert", "sentiment-analysis", "new-closed-neutral", "colab"]
|
| 5 |
---
|
| 6 |
|
| 7 |
+
# Model Card for distil-bert-classifier
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
This model is a fine-tuned DistilBERT model for sequence classification, specifically designed to identify the status of places (e.g., restaurants, businesses) as 'NEW', 'CLOSED', or 'NEUTRAL' based on short text snippets.
|
| 10 |
|
| 11 |
## Model Details
|
| 12 |
|
| 13 |
### Model Description
|
| 14 |
|
| 15 |
+
This is a `distilbert-base-uncased` model that has been fine-tuned on a synthetic dataset to classify text into three categories: 'NEW', 'CLOSED', and 'NEUTRAL'. It is intended to help aggregate signals about the operational status of businesses or points of interest from textual data.
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
- **Developed by:** virustechhacks (HuggingFace user)
|
| 18 |
+
- **Model type:** DistilBERT for Sequence Classification
|
| 19 |
+
- **Language(s) (NLP):** English
|
| 20 |
+
- **License:** MIT (Commonly used for open-source models; please confirm if a different license is preferred)
|
| 21 |
+
- **Finetuned from model:** `distilbert-base-uncased`
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
### Model Sources
|
| 24 |
|
| 25 |
+
- **Repository:** `https://huggingface.co/virustechhacks/distil-bert-classifier`
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
## Uses
|
| 28 |
|
|
|
|
|
|
|
| 29 |
### Direct Use
|
| 30 |
|
| 31 |
+
This model can be used to classify individual text snippets to determine if they indicate a place is 'NEW', 'CLOSED', or 'NEUTRAL'. For example, classifying a social media post, a review, or a news headline.
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
### Downstream Use
|
| 34 |
|
| 35 |
+
Aggregated predictions from this model can serve as features in larger analytical pipelines or other machine learning models (e.g., XGBoost) to provide a comprehensive view of a place's status. For instance, `closed_signal_ratio`, `new_signal_ratio`, and `mention_count` can be derived from the model's outputs for each place.
|
|
|
|
|
|
|
| 36 |
|
| 37 |
### Out-of-Scope Use
|
| 38 |
|
| 39 |
+
This model is not intended for:
|
| 40 |
+
- Detailed sentiment analysis beyond the defined categories (NEW/CLOSED/NEUTRAL).
|
| 41 |
+
- Classification of texts in languages other than English.
|
| 42 |
+
- Critical applications where misclassification could lead to severe consequences without further rigorous testing and validation on real-world data.
|
| 43 |
+
- Analyzing very long texts, as it was trained with a `max_length` of 128 tokens.
|
| 44 |
|
| 45 |
## Bias, Risks, and Limitations
|
| 46 |
|
| 47 |
+
- **Synthetic Data Bias:** The model was trained on a synthetically generated dataset using keyword-based rules. While useful for demonstration, its performance on real-world, diverse, and nuanced text data may vary significantly. It may exhibit biases present in the keyword templates or overfit to specific phrasing.
|
| 48 |
+
- **Lack of Recency Feature:** The synthetic data did not include timestamps, thus the model cannot account for the recency of mentions, which is a crucial factor in real-world status detection.
|
| 49 |
+
- **Max Length Truncation:** Texts longer than 128 tokens will be truncated, potentially losing important context.
|
| 50 |
|
| 51 |
### Recommendations
|
| 52 |
|
| 53 |
+
Users should be aware of the model's limitations, especially its reliance on synthetic training data. For real-world deployment, fine-tuning on a diverse and representative real-world dataset is highly recommended. Performance should be thoroughly evaluated on actual production data.
|
|
|
|
|
|
|
| 54 |
|
| 55 |
## How to Get Started with the Model
|
| 56 |
|
| 57 |
+
Use the code below to load the model and tokenizer from the HuggingFace Hub and make predictions:
|
| 58 |
|
| 59 |
+
```python
|
| 60 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 61 |
+
import torch.nn.functional as F
|
| 62 |
+
import torch
|
| 63 |
|
| 64 |
+
# Define the repository name
|
| 65 |
+
repo_name = "virustechhacks/distil-bert-classifier"
|
| 66 |
|
| 67 |
+
# Load tokenizer and model from HuggingFace Hub
|
| 68 |
+
loaded_tokenizer = AutoTokenizer.from_pretrained(repo_name)
|
| 69 |
+
loaded_model = AutoModelForSequenceClassification.from_pretrained(repo_name)
|
| 70 |
|
| 71 |
+
# Define label mappings (assuming these were used during training)
|
| 72 |
+
id_to_label = {0: 'NEW', 1: 'CLOSED', 2: 'NEUTRAL'}
|
| 73 |
|
| 74 |
+
# Set device
|
| 75 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 76 |
+
loaded_model.to(device)
|
| 77 |
|
| 78 |
+
def predict_status(text):
|
| 79 |
+
inputs = loaded_tokenizer(text, truncation=True, padding='max_length', max_length=128, return_tensors="pt")
|
| 80 |
+
inputs = {k: v.to(device) for k, v in inputs.items()}
|
| 81 |
|
| 82 |
+
with torch.no_grad():
|
| 83 |
+
outputs = loaded_model(**inputs)
|
| 84 |
|
| 85 |
+
probabilities = F.softmax(outputs.logits, dim=-1)
|
| 86 |
+
confidence, predicted_id = torch.max(probabilities, dim=1)
|
| 87 |
+
predicted_label = id_to_label[predicted_id.item()]
|
| 88 |
|
| 89 |
+
return predicted_label, confidence.item()
|
| 90 |
|
| 91 |
+
# Example usage
|
| 92 |
+
text_example = "Grand opening this weekend!"
|
| 93 |
+
label, conf = predict_status(text_example)
|
| 94 |
+
print(f"Text: '{text_example}'")
|
| 95 |
+
print(f"Prediction: {label} (Confidence: {conf:.2f})")
|
| 96 |
|
| 97 |
+
text_example_2 = "The store ceased operations due to low foot traffic."
|
| 98 |
+
label, conf = predict_status(text_example_2)
|
| 99 |
+
print(f"Text: '{text_example_2}'")
|
| 100 |
+
print(f"Prediction: {label} (Confidence: {conf:.2f})")
|
| 101 |
+
```
|
| 102 |
|
| 103 |
+
## Training Details
|
| 104 |
|
| 105 |
+
### Training Data
|
| 106 |
|
| 107 |
+
A synthetic dataset was generated with 2100 samples, evenly distributed across three classes: 'NEW' (700 samples), 'CLOSED' (700 samples), and 'NEUTRAL' (700 samples). The data was created using predefined keyword lists and sentence templates to simulate realistic phrases for each category. This dataset was split into a training set (1680 samples) and a validation set (420 samples) with stratified sampling to maintain label distribution.
|
| 108 |
|
| 109 |
+
### Training Procedure
|
| 110 |
|
| 111 |
+
#### Preprocessing
|
| 112 |
|
| 113 |
+
Text data was tokenized using the `distilbert-base-uncased` tokenizer with `truncation=True`, `padding='max_length'`, and a `max_length` of 128 tokens. Labels were mapped to integers (NEW: 0, CLOSED: 1, NEUTRAL: 2). HuggingFace `Dataset` objects were created and processed for training.
|
| 114 |
|
| 115 |
+
#### Training Hyperparameters
|
| 116 |
|
| 117 |
+
- **Training regime:** Single GPU (or CPU if GPU not available), fp32 precision (default for `Trainer` without explicit mixed precision)
|
| 118 |
+
- **`num_train_epochs`**: 3
|
| 119 |
+
- **`per_device_train_batch_size`**: 16
|
| 120 |
+
- **`per_device_eval_batch_size`**: 16
|
| 121 |
+
- **`warmup_steps`**: 500
|
| 122 |
+
- **`weight_decay`**: 0.01
|
| 123 |
+
- **`logging_steps`**: 10
|
| 124 |
+
- **`eval_strategy`**: "epoch"
|
| 125 |
+
- **`learning_rate`**: 2e-5
|
| 126 |
+
- **`save_strategy`**: "epoch"
|
| 127 |
+
- **`load_best_model_at_end`**: True
|
| 128 |
+
- **`metric_for_best_model`**: "f1"
|
| 129 |
|
| 130 |
+
#### Speeds, Sizes, Times
|
| 131 |
|
| 132 |
+
The model training was performed in a Google Colab environment. Specific timings and compute resources (e.g., GPU type) were not explicitly logged but typically involve a T4 or V100 GPU if available.
|
| 133 |
|
| 134 |
+
## Evaluation
|
| 135 |
+
|
| 136 |
+
### Testing Data, Factors & Metrics
|
| 137 |
|
| 138 |
+
#### Testing Data
|
| 139 |
|
| 140 |
+
The model was evaluated on a synthetic validation set consisting of 420 samples (140 samples per class) generated using the same methodology as the training data.
|
| 141 |
|
| 142 |
#### Metrics
|
| 143 |
|
| 144 |
+
The evaluation metrics used were:
|
| 145 |
+
- **Accuracy**
|
| 146 |
+
- **Precision** (weighted average)
|
| 147 |
+
- **Recall** (weighted average)
|
| 148 |
+
- **F1-score** (weighted average and per-class)
|
| 149 |
|
| 150 |
### Results
|
| 151 |
|
|
|
|
|
|
|
| 152 |
#### Summary
|
| 153 |
|
| 154 |
+
On the synthetic validation set, the model achieved perfect scores across all metrics:
|
| 155 |
|
| 156 |
+
```
|
| 157 |
+
Evaluation results: {'eval_loss': 0.0277, 'eval_accuracy': 1.0, 'eval_f1': 1.0, 'eval_precision': 1.0, 'eval_recall': 1.0, ...}
|
| 158 |
|
| 159 |
+
Classification Report:
|
| 160 |
+
precision recall f1-score support
|
| 161 |
|
| 162 |
+
NEW 1.00 1.00 1.00 140
|
| 163 |
+
CLOSED 1.00 1.00 1.00 140
|
| 164 |
+
NEUTRAL 1.00 1.00 1.00 140
|
| 165 |
|
| 166 |
+
accuracy 1.00 420
|
| 167 |
+
macro avg 1.00 1.00 1.00 420
|
| 168 |
+
weighted avg 1.00 1.00 1.00 420
|
| 169 |
+
```
|
| 170 |
+
It is important to reiterate that these results are on a synthetic dataset and may not reflect real-world performance.
|
| 171 |
|
| 172 |
## Environmental Impact
|
| 173 |
|
| 174 |
+
Carbon emissions for this training run were not explicitly measured.
|
| 175 |
|
| 176 |
+
- **Hardware Type:** Google Colab GPU (e.g., Tesla T4 or V100) or CPU
|
| 177 |
+
- **Cloud Provider:** Google Cloud
|
| 178 |
+
- **Compute Region:** `[More Information Needed]` (Colab region)
|
| 179 |
+
- **Carbon Emitted:** `[More Information Needed]`
|
| 180 |
|
| 181 |
+
## Technical Specifications
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
### Model Architecture and Objective
|
| 184 |
|
| 185 |
+
The model uses the DistilBERT architecture, a smaller, faster, and lighter version of BERT. It is configured for sequence classification with a final dense layer for 3 output classes (NEW, CLOSED, NEUTRAL). Its objective is to minimize the cross-entropy loss between predicted and true labels.
|
| 186 |
|
| 187 |
### Compute Infrastructure
|
| 188 |
|
|
|
|
|
|
|
| 189 |
#### Hardware
|
| 190 |
|
| 191 |
+
Training was performed on Google Colaboratory, which typically provides access to NVIDIA GPUs (e.g., Tesla T4). The specific GPU allocated during the session was not logged.
|
| 192 |
|
| 193 |
#### Software
|
| 194 |
|
| 195 |
+
- Python 3.x
|
| 196 |
+
- `transformers` library (version used during execution)
|
| 197 |
+
- `torch` (PyTorch)
|
| 198 |
+
- `datasets` library
|
| 199 |
+
- `scikit-learn`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
|
| 201 |
## Model Card Contact
|
| 202 |
|
| 203 |
+
[virustechhacks on HuggingFace Hub](https://huggingface.co/virustechhacks)
|
| 204 |
+
```
|