virustechhacks commited on
Commit
1bbe5f5
·
verified ·
1 Parent(s): 2388910

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +117 -112
README.md CHANGED
@@ -1,199 +1,204 @@
 
1
  ---
2
  library_name: transformers
3
- tags: []
4
  ---
5
 
6
- # Model Card for Model ID
7
-
8
- <!-- Provide a quick summary of what the model is/does. -->
9
-
10
 
 
11
 
12
  ## Model Details
13
 
14
  ### Model Description
15
 
16
- <!-- Provide a longer summary of what this model is. -->
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:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
 
28
- ### Model Sources [optional]
29
 
30
- <!-- Provide the basic links for the model. -->
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
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
-
44
- [More Information Needed]
45
 
46
- ### Downstream Use [optional]
47
 
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
-
50
- [More Information Needed]
51
 
52
  ### Out-of-Scope Use
53
 
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
 
 
57
 
58
  ## Bias, Risks, and Limitations
59
 
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
 
64
  ### Recommendations
65
 
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
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 get started with the model.
73
 
74
- [More Information Needed]
 
 
 
75
 
76
- ## Training Details
 
77
 
78
- ### Training Data
 
 
79
 
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
 
81
 
82
- [More Information Needed]
 
 
83
 
84
- ### Training Procedure
 
 
85
 
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
 
87
 
88
- #### Preprocessing [optional]
 
 
89
 
90
- [More Information Needed]
91
 
 
 
 
 
 
92
 
93
- #### Training Hyperparameters
 
 
 
 
94
 
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
 
97
- #### Speeds, Sizes, Times [optional]
98
 
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
 
101
- [More Information Needed]
102
 
103
- ## Evaluation
104
 
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
 
107
- ### Testing Data, Factors & Metrics
108
 
109
- #### Testing Data
 
 
 
 
 
 
 
 
 
 
 
110
 
111
- <!-- This should link to a Dataset Card if possible. -->
112
 
113
- [More Information Needed]
114
 
115
- #### Factors
 
 
116
 
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
 
119
- [More Information Needed]
120
 
121
  #### Metrics
122
 
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
-
125
- [More Information Needed]
 
 
126
 
127
  ### Results
128
 
129
- [More Information Needed]
130
-
131
  #### Summary
132
 
 
133
 
 
 
134
 
135
- ## Model Examination [optional]
 
136
 
137
- <!-- Relevant interpretability work for the model goes here -->
 
 
138
 
139
- [More Information Needed]
 
 
 
 
140
 
141
  ## Environmental Impact
142
 
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
 
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
 
 
 
146
 
147
- - **Hardware Type:** [More Information Needed]
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
- [More Information Needed]
158
 
159
  ### Compute Infrastructure
160
 
161
- [More Information Needed]
162
-
163
  #### Hardware
164
 
165
- [More Information Needed]
166
 
167
  #### Software
168
 
169
- [More Information Needed]
170
-
171
- ## Citation [optional]
172
-
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
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
- [More Information Needed]
 
 
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
+ ```