DeclanBracken commited on
Commit
55c5a1b
·
1 Parent(s): 0daf370

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +28 -152
README.md CHANGED
@@ -17,9 +17,9 @@
17
 
18
 
19
  - **Developed by:** Declan Bracken, Armando Ordorica, Michael Santorelli, Paul Zhou
20
- - **Model type:** [Transformer]
21
- - **Language(s) (NLP):** [English]
22
- - **Finetuned from model [optional]:** [BERT_base_uncased]
23
 
24
  ### Model Sources [optional]
25
 
@@ -35,163 +35,39 @@
35
 
36
  ### Direct Use
37
 
38
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
 
39
 
40
- [More Information Needed]
 
 
 
41
 
42
- ### Downstream Use [optional]
 
43
 
44
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
 
 
45
 
46
- [More Information Needed]
 
 
47
 
48
- ### Out-of-Scope Use
 
 
49
 
50
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
 
 
51
 
52
- [More Information Needed]
 
53
 
54
- ## Bias, Risks, and Limitations
 
55
 
56
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
57
-
58
- [More Information Needed]
59
-
60
- ### Recommendations
61
-
62
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
63
-
64
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
65
-
66
- ## How to Get Started with the Model
67
-
68
- Use the code below to get started with the model.
69
-
70
- [More Information Needed]
71
-
72
- ## Training Details
73
-
74
- ### Training Data
75
-
76
- <!-- 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. -->
77
-
78
- [More Information Needed]
79
-
80
- ### Training Procedure
81
-
82
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
83
-
84
- #### Preprocessing [optional]
85
-
86
- [More Information Needed]
87
-
88
-
89
- #### Training Hyperparameters
90
-
91
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
92
-
93
- #### Speeds, Sizes, Times [optional]
94
-
95
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
96
-
97
- [More Information Needed]
98
-
99
- ## Evaluation
100
-
101
- <!-- This section describes the evaluation protocols and provides the results. -->
102
-
103
- ### Testing Data, Factors & Metrics
104
-
105
- #### Testing Data
106
-
107
- <!-- This should link to a Dataset Card if possible. -->
108
-
109
- [More Information Needed]
110
-
111
- #### Factors
112
-
113
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
114
-
115
- [More Information Needed]
116
-
117
- #### Metrics
118
-
119
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
120
-
121
- [More Information Needed]
122
-
123
- ### Results
124
-
125
- [More Information Needed]
126
-
127
- #### Summary
128
-
129
-
130
-
131
- ## Model Examination [optional]
132
-
133
- <!-- Relevant interpretability work for the model goes here -->
134
-
135
- [More Information Needed]
136
-
137
- ## Environmental Impact
138
-
139
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
140
-
141
- 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).
142
-
143
- - **Hardware Type:** [More Information Needed]
144
- - **Hours used:** [More Information Needed]
145
- - **Cloud Provider:** [More Information Needed]
146
- - **Compute Region:** [More Information Needed]
147
- - **Carbon Emitted:** [More Information Needed]
148
-
149
- ## Technical Specifications [optional]
150
-
151
- ### Model Architecture and Objective
152
-
153
- [More Information Needed]
154
-
155
- ### Compute Infrastructure
156
-
157
- [More Information Needed]
158
-
159
- #### Hardware
160
-
161
- [More Information Needed]
162
-
163
- #### Software
164
-
165
- [More Information Needed]
166
-
167
- ## Citation [optional]
168
-
169
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
170
-
171
- **BibTeX:**
172
-
173
- [More Information Needed]
174
-
175
- **APA:**
176
-
177
- [More Information Needed]
178
-
179
- ## Glossary [optional]
180
-
181
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
182
-
183
- [More Information Needed]
184
-
185
- ## More Information [optional]
186
-
187
- [More Information Needed]
188
-
189
- ## Model Card Authors [optional]
190
-
191
- [More Information Needed]
192
-
193
- ## Model Card Contact
194
-
195
- [More Information Needed]
196
 
197
 
 
17
 
18
 
19
  - **Developed by:** Declan Bracken, Armando Ordorica, Michael Santorelli, Paul Zhou
20
+ - **Model type:** Transformer
21
+ - **Language(s) (NLP):** English
22
+ - **Finetuned from model:** BERT_base_uncased
23
 
24
  ### Model Sources [optional]
25
 
 
35
 
36
  ### Direct Use
37
 
38
+ Create a custom class to load in the model, the label encoder, and the BERT tokenizer used for training (bert-base-uncased) as below.
39
+ use the tokenizer to tokenize any input string you'd like, then pass it through the model to get outputs.
40
 
41
+ class BERTClassifier:
42
+ def __init__(self, model_identifier):
43
+ # Load the tokenizer from bert base uncased
44
+ self.tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
45
 
46
+ # Load the config
47
+ config = AutoConfig.from_pretrained(model_identifier)
48
 
49
+ # Load the model
50
+ self.model = BertForSequenceClassification.from_pretrained(model_identifier, config=config)
51
+ self.model.eval() # Set the model to evaluation mode
52
 
53
+ # Load the label encoder
54
+ encoder_url = f'https://huggingface.co/{model_identifier}/resolve/main/model_encoder.pkl'
55
+ self.labels = pickle.loads(requests.get(encoder_url).content)
56
 
57
+ def predict_category(self, text):
58
+ # Tokenize the text
59
+ inputs = self.tokenizer(text, return_tensors='pt', truncation=True, padding=True)
60
 
61
+ # Predict
62
+ with torch.no_grad():
63
+ outputs = self.model(**inputs)
64
 
65
+ # Get the prediction index
66
+ prediction_idx = torch.argmax(outputs.logits, dim=1).item()
67
 
68
+ # Decode the prediction index to get the label
69
+ prediction_label = self.labels[prediction_idx] # Use indexing for a NumPy array
70
 
71
+ return prediction_label
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73