Update README.md
Browse files
README.md
CHANGED
|
@@ -1,199 +1,107 @@
|
|
| 1 |
-
|
| 2 |
-
library_name: transformers
|
| 3 |
-
tags: []
|
| 4 |
-
---
|
| 5 |
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
| 9 |
|
|
|
|
| 10 |
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
|
| 18 |
-
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
- **License:** [More Information Needed]
|
| 26 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
| 27 |
|
| 28 |
-
###
|
| 29 |
|
| 30 |
-
|
| 31 |
|
| 32 |
-
-
|
| 33 |
-
- **Paper [optional]:** [More Information Needed]
|
| 34 |
-
- **Demo [optional]:** [More Information Needed]
|
| 35 |
|
| 36 |
-
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
|
| 43 |
|
| 44 |
-
|
| 45 |
|
| 46 |
-
|
|
|
|
|
|
|
| 47 |
|
| 48 |
-
|
| 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 |
-
|
|
|
|
| 75 |
|
| 76 |
-
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
|
|
|
|
| 79 |
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
-
|
| 83 |
|
| 84 |
-
|
| 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 |
+
# ERC Classifiers
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
This repository contains a model trained for multi-label classification of scientific papers in the ERC (European Research Council) context. The model predicts multiple categories for a paper, such as its research domain or topic, based on the abstract and title.
|
| 4 |
|
| 5 |
+
## Model Description
|
| 6 |
|
| 7 |
+
The model is based on **SPECTER** (a transformer-based model pre-trained on scientific literature), fine-tuned for **multi-label classification** on a dataset of scientific papers. The model classifies papers into several categories, which are defined by the **ERC categories**. The fine-tuned model is trained to predict these categories given the title and abstract of each paper.
|
| 8 |
|
| 9 |
+
### Preprocessing
|
| 10 |
|
| 11 |
+
The preprocessing pipeline involves:
|
| 12 |
|
| 13 |
+
1. **Data Loading**: Papers are loaded from a Parquet file containing the title, abstract, and their respective categories.
|
| 14 |
+
2. **Label Cleaning**: Labels (categories) are processed to remove any unnecessary information (like content within parentheses).
|
| 15 |
+
3. **Label Encoding**: Categories are transformed into a binary matrix using the **MultiLabelBinarizer** from scikit-learn. Each category corresponds to a column, and the value is `1` if the paper belongs to that category, `0` otherwise.
|
| 16 |
+
4. **Statistics and Visualization**: Basic statistics and visualizations, such as label distributions, are generated to help understand the dataset better.
|
| 17 |
|
| 18 |
+
### Training
|
| 19 |
|
| 20 |
+
The model is fine-tuned on the preprocessed dataset using the following setup:
|
| 21 |
|
| 22 |
+
* **Base Model**: The model uses the `allenai/specter` transformer as the base model for sequence classification.
|
| 23 |
+
* **Optimizer**: AdamW optimizer with a learning rate of `5e-5` is used.
|
| 24 |
+
* **Loss Function**: Binary Cross-Entropy with logits (`BCEWithLogitsLoss`) is employed, as the task is multi-label classification.
|
| 25 |
+
* **Epochs**: The model is trained for **5 epochs** with a batch size of 4.
|
| 26 |
+
* **Training Data**: The model is trained on a processed dataset stored in `train_ready.parquet`.
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
### Evaluation
|
| 29 |
|
| 30 |
+
The model is evaluated using both **single-label** and **multi-label** metrics:
|
| 31 |
|
| 32 |
+
#### Single-Label Evaluation
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
* **Accuracy**: The accuracy is measured by checking how often the true label appears in the predicted labels.
|
| 35 |
+
* **Precision, Recall, F1**: These metrics are calculated for each class and averaged for the entire dataset.
|
| 36 |
|
| 37 |
+
#### Multi-Label Evaluation
|
| 38 |
|
| 39 |
+
* **Micro and Macro Metrics**: Precision, recall, and F1 scores are computed using both micro-averaging (overall performance) and macro-averaging (performance per label).
|
| 40 |
+
* **Label Frequency Plot**: A plot showing the frequency distribution of labels in the test set.
|
| 41 |
+
* **Top and Bottom F1 Plot**: A plot visualizing the top and bottom labels based on their F1 scores.
|
| 42 |
|
| 43 |
+
## Dataset
|
| 44 |
|
| 45 |
+
The dataset consists of scientific papers, each with the following columns:
|
| 46 |
|
| 47 |
+
* **title**: The title of the paper.
|
| 48 |
+
* **abstract**: The abstract of the paper.
|
| 49 |
+
* **label**: A list of categories (labels) assigned to the paper.
|
| 50 |
|
| 51 |
+
The dataset is preprocessed and stored in a `train_ready.parquet` file.
|
| 52 |
|
| 53 |
+
## Files
|
| 54 |
|
| 55 |
+
* `config.json`: Model configuration file.
|
| 56 |
+
* `model.safetensors`: Saved fine-tuned model weights.
|
| 57 |
+
* `tokenizer.json`: Tokenizer configuration for the fine-tuned model.
|
| 58 |
+
* `tokenizer_config.json`: Tokenizer settings.
|
| 59 |
+
* `special_tokens_map.json`: Special tokens used by the tokenizer.
|
| 60 |
+
* `vocab.txt`: Vocabulary file for the fine-tuned tokenizer.
|
| 61 |
|
| 62 |
+
## Usage
|
| 63 |
|
| 64 |
+
To use the model, follow these steps:
|
| 65 |
|
| 66 |
+
1. **Install Dependencies**:
|
| 67 |
|
| 68 |
+
```bash
|
| 69 |
+
pip install transformers torch datasets
|
| 70 |
+
```
|
| 71 |
|
| 72 |
+
2. **Load the Model and Tokenizer**:
|
| 73 |
|
| 74 |
+
```python
|
| 75 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 76 |
|
| 77 |
+
model_name = "SIRIS-Lab/erc-classifiers"
|
| 78 |
|
| 79 |
+
# Load fine-tuned model and tokenizer
|
| 80 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 81 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 82 |
+
```
|
| 83 |
|
| 84 |
+
3. **Use the Model for Prediction**:
|
| 85 |
|
| 86 |
+
```python
|
| 87 |
+
# Example paper title and abstract
|
| 88 |
+
text = "Example title and abstract of a scientific paper."
|
| 89 |
|
| 90 |
+
# Tokenize the input text
|
| 91 |
+
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
|
| 92 |
|
| 93 |
+
# Make predictions
|
| 94 |
+
with torch.no_grad():
|
| 95 |
+
logits = model(**inputs).logits
|
| 96 |
|
| 97 |
+
# Apply sigmoid activation to get probabilities
|
| 98 |
+
probabilities = torch.sigmoid(logits)
|
| 99 |
|
| 100 |
+
# Get predicted labels (threshold at 0.5)
|
| 101 |
+
predicted_labels = (probabilities >= 0.5).long().cpu().numpy()
|
| 102 |
+
print(predicted_labels)
|
| 103 |
+
```
|
| 104 |
|
| 105 |
+
## Conclusion
|
| 106 |
|
| 107 |
+
This model provides an efficient solution for classifying scientific papers into multiple categories based on their content. It uses state-of-the-art transformer-based techniques and is fine-tuned on a real-world dataset of ERC-related scientific papers.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|