Add model card
Browse files
README.md
CHANGED
|
@@ -1,37 +1,43 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
library_name: transformers
|
| 3 |
-
|
|
|
|
| 4 |
---
|
| 5 |
|
| 6 |
# Model Card for Model ID
|
| 7 |
|
| 8 |
-
|
| 9 |
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
## Model Details
|
| 13 |
|
| 14 |
### Model Description
|
| 15 |
|
| 16 |
-
<!-- Provide a longer summary of what this model is. -->
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
- **
|
| 22 |
-
- **
|
| 23 |
-
- **Model type:**
|
| 24 |
-
- **Language(s) (NLP):**
|
| 25 |
-
- **
|
| 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:**
|
| 33 |
-
- **Paper [optional]:** [More Information Needed]
|
| 34 |
-
- **Demo [optional]:** [More Information Needed]
|
| 35 |
|
| 36 |
## Uses
|
| 37 |
|
|
@@ -39,161 +45,132 @@ This is the model card of a 🤗 transformers model that has been pushed on the
|
|
| 39 |
|
| 40 |
### Direct Use
|
| 41 |
|
| 42 |
-
|
| 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 |
-
|
| 51 |
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
|
| 56 |
-
|
|
|
|
| 57 |
|
| 58 |
-
|
|
|
|
| 59 |
|
| 60 |
-
|
|
|
|
| 61 |
|
| 62 |
-
|
|
|
|
| 63 |
|
| 64 |
-
|
|
|
|
| 65 |
|
| 66 |
-
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
|
| 69 |
|
| 70 |
-
|
| 71 |
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
-
[More Information Needed]
|
| 75 |
|
| 76 |
## Training Details
|
| 77 |
|
| 78 |
-
### Training Data
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
[More Information Needed]
|
| 83 |
|
| 84 |
### Training Procedure
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
#### Preprocessing [optional]
|
| 89 |
-
|
| 90 |
-
[More Information Needed]
|
| 91 |
|
| 92 |
|
| 93 |
#### Training Hyperparameters
|
| 94 |
|
| 95 |
-
- **Training regime:**
|
| 96 |
|
| 97 |
-
#### Speeds, Sizes, Times [optional]
|
| 98 |
|
| 99 |
-
|
| 100 |
|
| 101 |
-
|
|
|
|
| 102 |
|
| 103 |
-
|
|
|
|
| 104 |
|
| 105 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
| 106 |
|
| 107 |
### Testing Data, Factors & Metrics
|
| 108 |
|
| 109 |
#### Testing Data
|
| 110 |
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
[More Information Needed]
|
| 114 |
|
| 115 |
-
|
|
|
|
| 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 |
-
|
| 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 |
-
|
| 160 |
|
| 161 |
-
[
|
| 162 |
|
| 163 |
#### Hardware
|
| 164 |
|
| 165 |
-
|
| 166 |
|
| 167 |
#### Software
|
| 168 |
|
| 169 |
-
|
| 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 |
-
|
| 196 |
|
| 197 |
-
## Model Card Contact
|
| 198 |
|
| 199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
base_model:
|
| 3 |
+
- distilBERT/distilbert-base-uncased
|
| 4 |
+
datasets:
|
| 5 |
+
- stanfordnlp/imdb
|
| 6 |
+
language:
|
| 7 |
+
- en
|
| 8 |
library_name: transformers
|
| 9 |
+
metrics:
|
| 10 |
+
- perplexity
|
| 11 |
---
|
| 12 |
|
| 13 |
# Model Card for Model ID
|
| 14 |
|
| 15 |
+
🍿🎥Welcome to the DistilBERT-DeNiro model card!🎞️📽️
|
| 16 |
|
| 17 |
+
We domain adapt (fine-tune) the DistilBERT base model [DistilBERT/distilbert-base-uncased](https://huggingface.co/distilbert/distilbert-base-uncased) on the IMDB movies dataset for a whole word masked language modeling task.
|
| 18 |
|
| 19 |
|
| 20 |
## Model Details
|
| 21 |
|
| 22 |
### Model Description
|
| 23 |
|
|
|
|
| 24 |
|
| 25 |
+
The DistilBERT base model is fined-tuned using a custom PyTorch training loop. We supervise a training of DistilBERT for the purpose of masked language modeling on [stanfordnlp/imdb](https://huggingface.co/datasets/stanfordnlp/imdb), an open source
|
| 26 |
+
dateset from Stanford NLP available through the 🤗 hub [stanfordnlp/imdb](https://huggingface.co/datasets/stanfordnlp/imdb). This dataset of movie reviews was concatenated into a single string before being chunked and padded to a size of 256 tokens.
|
| 27 |
+
We fed these chunks into the model during training with a batch size of 32. After training, the ultimate model is domain adapted to fill `[MASK]` tokens in an input string with terms and lingo common to movies.
|
| 28 |
|
| 29 |
+
|
| 30 |
+
- **Developed by:** John Graham Reynolds
|
| 31 |
+
- **Funded by:** Vanderbilt University
|
| 32 |
+
- **Model type:** Masked Language Model
|
| 33 |
+
- **Language(s) (NLP):** English
|
| 34 |
+
- **Finetuned from model:** "DistilBERT/distilbert-base-uncased"
|
|
|
|
| 35 |
|
| 36 |
### Model Sources [optional]
|
| 37 |
|
| 38 |
<!-- Provide the basic links for the model. -->
|
| 39 |
|
| 40 |
+
- **Repository:** https://github.com/johngrahamreynolds/DistilBERT-DeNiro
|
|
|
|
|
|
|
| 41 |
|
| 42 |
## Uses
|
| 43 |
|
|
|
|
| 45 |
|
| 46 |
### Direct Use
|
| 47 |
|
| 48 |
+
In order to query the model effectively, one must pass it a string containing a `[MASK]` token to be filled. An example is `text = "This is a great [MASK]!".
|
| 49 |
+
The domain-adapted model will attempt to fill the mask with a token relevant to movies, cinema, tv, etc.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
## How to Use and Query the Model
|
| 52 |
|
| 53 |
+
Use the code below to get started with the model. Users pass a `text` string detailing a sentence with a `[MASK]` token. The model will provide options
|
| 54 |
+
to fill the mask based on the sentence context and its background of knowledge. Note - the DistilBERT base model was trained on a very large general corpus of text.
|
| 55 |
+
In our training, we have fine-tuned the model on the large IMDB movie review dataset. That is, the model is now accustomed to filling `[MASK]` tokens with words related to
|
| 56 |
+
the domain of movies/tv/films. To see the model's afinity for cinematic lingo, it is best to be considerate in one's prompt engineering. That is, to most likely generate movie related text,
|
| 57 |
+
one should ideally pass a masked `text` string that could reasonably be found in someone's review of a movie. See the example below:
|
| 58 |
|
| 59 |
+
``` python
|
| 60 |
|
| 61 |
+
import torch
|
| 62 |
+
from transformers import AutoModelForMaskedLM, AutoTokenizer
|
| 63 |
|
| 64 |
+
model = AutoModelForMaskedLM.from_pretrained("MarioBarbeque/DistilBERT-DeNiro").to("cuda")
|
| 65 |
+
tokenizer = AutoTokenizer.from_pretrained("distilbert/distilbert-base-uncased")
|
| 66 |
|
| 67 |
+
# Pass a unique string with a [MASK] token for the model to fill
|
| 68 |
+
text = "This is a great [MASK]!"
|
| 69 |
|
| 70 |
+
tokenized_text = tokenizer(text, return_tensors="pt").to("cuda")
|
| 71 |
+
token_logits = model(**tokenized_text).logits
|
| 72 |
|
| 73 |
+
mask_token_index = torch.where(tokenized_text["input_ids"] == tokenizer.mask_token_id)[1]
|
| 74 |
+
mask_token_logits = token_logits[0, mask_token_index, :]
|
| 75 |
|
| 76 |
+
top_5_tokens = torch.topk(mask_token_logits, 5, dim=1).indices[0].tolist()
|
| 77 |
+
for token in top_5_tokens:
|
| 78 |
+
print(text.replace(tokenizer.mask_token, tokenizer.decode(token)))
|
| 79 |
|
| 80 |
+
```
|
| 81 |
|
| 82 |
+
This code outputs the following:
|
| 83 |
|
| 84 |
+
``` python
|
| 85 |
+
This is a great movie!
|
| 86 |
+
This is a great film!
|
| 87 |
+
This is a great idea!
|
| 88 |
+
This is a great show!
|
| 89 |
+
This is a great documentary!
|
| 90 |
+
```
|
| 91 |
|
|
|
|
| 92 |
|
| 93 |
## Training Details
|
| 94 |
|
| 95 |
+
### Training Data / Preprocessing
|
| 96 |
|
| 97 |
+
The data used comes from the Stanford NLP 🤗 hub. It has been preprocessed to only contain reviews at least 13 or more words in length. The model card
|
| 98 |
+
can be found [here](https://huggingface.co/datasets/stanfordnlp/imdb).
|
|
|
|
| 99 |
|
| 100 |
### Training Procedure
|
| 101 |
|
| 102 |
+
The model was trained locally on a single-node with one 16GB Nvidia T4 using 🤗 Transformers, 🤗 Tokenizers, and a custom PyTorch training loop that made use of 🤗 Accelerate.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
|
| 105 |
#### Training Hyperparameters
|
| 106 |
|
| 107 |
+
- **Training regime:** We use FP32 precision, as follows immediately from the precision inhereted for the original "DistilBERT/distilbert-base-uncased" model.
|
| 108 |
|
|
|
|
| 109 |
|
| 110 |
+
## Evaluation / Metrics
|
| 111 |
|
| 112 |
+
We evaluate our masked language model's performance using the `perplexity` metric, which has a few mathematical defitions. We define the perplexity as the exponential of the cross-entropy.
|
| 113 |
+
See the wikipedia links for perplexity and cross-entropy below for more a detailed discussion and various other definitions.
|
| 114 |
|
| 115 |
+
Cross-entropy: [https://en.wikipedia.org/wiki/Cross-entropy](https://en.wikipedia.org/wiki/Cross-entropy)
|
| 116 |
+
Perplexity: [https://en.wikipedia.org/wiki/Perplexity](https://en.wikipedia.org/wiki/Perplexity)
|
| 117 |
|
|
|
|
| 118 |
|
| 119 |
### Testing Data, Factors & Metrics
|
| 120 |
|
| 121 |
#### Testing Data
|
| 122 |
|
| 123 |
+
The IMDB dataset from Stanford NLP comes pre-split into training and testing data of 25k reviews each. Our preprocessing
|
|
|
|
|
|
|
| 124 |
|
| 125 |
+
We configured a train/test split using the standard 80/20 rule of thumb on the shuffled UC Irvine data set. The dataset [model card](https://huggingface.co/datasets/MarioBarbeque/UCI_drug_reviews)
|
| 126 |
+
contains in its base form a `DataDict` with splits for train, validation, and test. The dataset used for testing can be found there in the test split.
|
| 127 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
### Results
|
| 130 |
|
| 131 |
+
We find the following perplexity metrics over 3 training epochs:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
+
| epoch | perplexity |
|
| 134 |
+
|-------|------------|
|
| 135 |
+
|0 | 17.38 |
|
| 136 |
+
|1 | 16.28 |
|
| 137 |
+
|2 | 15.78 |
|
| 138 |
|
| 139 |
+
#### Summary
|
| 140 |
|
| 141 |
+
We train this model for the purpose of attempting a local training of a masked language model using both the 🤗 ecosystem and a custom PyTorch training and evaluation loop.
|
| 142 |
+
We look forward to further fine-tuning this model on more film/actor/cinema related data in order to further improve the model's knowledge and ability in this domain -
|
| 143 |
+
indeed cinema is one of the author's favorite things.
|
| 144 |
|
| 145 |
## Environmental Impact
|
| 146 |
|
| 147 |
+
- **Hardware Type:** Nvidia Tesla T4 16GB
|
| 148 |
+
- **Hours used:** 1.2
|
| 149 |
+
- **Cloud Provider:** Microsoft Azure
|
| 150 |
+
- **Compute Region:** EastUS
|
| 151 |
+
- **Carbon Emitted:** 0.03 kgCO2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
|
|
|
| 153 |
|
| 154 |
+
Experiments were conducted using Azure in region eastus, which has a carbon efficiency of 0.37 kgCO$_2$eq/kWh. A cumulative of 1.2 hours of computation was performed on hardware of type T4 (TDP of 70W).
|
| 155 |
|
| 156 |
+
Total emissions are estimated to be 0.03 kgCO$_2$eq of which 100 percents were directly offset by the cloud provider.
|
| 157 |
|
| 158 |
+
Estimations were conducted using the MachineLearning Impact calculator presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
| 159 |
|
| 160 |
#### Hardware
|
| 161 |
|
| 162 |
+
The model was trained locally in an Azure Databricks workspace using a single node with 1 16GB Nvidia T4 GPU for 1.2 GPU Hours.
|
| 163 |
|
| 164 |
#### Software
|
| 165 |
|
| 166 |
+
Training utilized PyTorch, 🤗 Transformers, 🤗 Tokenizers, 🤗 Datasets, 🤗 Accelerate, and more in an Azure Databricks execution environment.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
|
| 168 |
+
#### Citations
|
| 169 |
|
|
|
|
| 170 |
|
| 171 |
+
@article{lacoste2019quantifying,
|
| 172 |
+
title={Quantifying the Carbon Emissions of Machine Learning},
|
| 173 |
+
author={Lacoste, Alexandre and Luccioni, Alexandra and Schmidt, Victor and Dandres, Thomas},
|
| 174 |
+
journal={arXiv preprint arXiv:1910.09700},
|
| 175 |
+
year={2019}
|
| 176 |
+
}
|