Spaces:
Runtime error
Runtime error
Delete README.md
Browse files
README.md
DELETED
|
@@ -1,155 +0,0 @@
|
|
| 1 |
-
# Exploring the Roberta Model and its Application for Named Entity Recognition
|
| 2 |
-
|
| 3 |
-
## Introduction
|
| 4 |
-
This project aims to explore the Roberta model and its application in the task of Named Entity Recognition (NER). Roberta is a variant of BERT with improved performance on various natural language processing (NLP) tasks.
|
| 5 |
-
|
| 6 |
-
## Team Members
|
| 7 |
-
- **Nguyen Viet Bac** - 22022511
|
| 8 |
-
- **Dang Van Khai** - 22022550
|
| 9 |
-
- **Duong Minh Duc** - 22022606
|
| 10 |
-
|
| 11 |
-
## Project Objectives
|
| 12 |
-
1. Understand the Roberta model.
|
| 13 |
-
2. Apply the Roberta model to the task of Named Entity Recognition.
|
| 14 |
-
3. Evaluate the model's performance on standard datasets.
|
| 15 |
-
|
| 16 |
-
## Content
|
| 17 |
-
### 1. Introduction to the Roberta Model
|
| 18 |
-
- Overview of the Roberta model.
|
| 19 |
-
- Key features and improvements over the BERT model.
|
| 20 |
-
|
| 21 |
-
### 2. Data Preparation
|
| 22 |
-
- Collect and preprocess data for the NER task.
|
| 23 |
-
- Split the dataset into training, validation, and test sets.
|
| 24 |
-
|
| 25 |
-
### 3. Model Training
|
| 26 |
-
- Install necessary libraries.
|
| 27 |
-
- Train the Roberta model on the NER dataset.
|
| 28 |
-
- Save and load the trained model.
|
| 29 |
-
|
| 30 |
-
### 4. Evaluation and Testing
|
| 31 |
-
- Evaluate the model on the test set.
|
| 32 |
-
- Analyze results and provide insights.
|
| 33 |
-
|
| 34 |
-
### 5. Conclusion
|
| 35 |
-
- Summarize the achieved results.
|
| 36 |
-
- Suggest future directions for the project.
|
| 37 |
-
|
| 38 |
-
## System Requirements
|
| 39 |
-
- Python 3.x
|
| 40 |
-
- PyTorch
|
| 41 |
-
- Transformers (Hugging Face)
|
| 42 |
-
- Other libraries: pandas, numpy, scikit-learn, etc.
|
| 43 |
-
|
| 44 |
-
## Setting up
|
| 45 |
-
|
| 46 |
-
```bash
|
| 47 |
-
import os
|
| 48 |
-
os.environ['PARAM_SET'] = 'base' # change to 'large' to use the large architecture
|
| 49 |
-
|
| 50 |
-
# we use pip 23.1 to run
|
| 51 |
-
pip install pip==23.1
|
| 52 |
-
# clone the repo
|
| 53 |
-
git clone https://github.com/NLP-UET/Roberta-NER.git
|
| 54 |
-
pip install -r ./Roberta-NER/requirements.txt
|
| 55 |
-
gdown --id 1uC7UYA-BDg-dJYB_C6aphyJ5IWweVzXE # base model
|
| 56 |
-
gdown --id 15HA6Iq5Gld2XXV27lmOOa3KlK-DV_gTq # large model
|
| 57 |
-
tar -xzvf xlmr.base.tar.gz -C ./Roberta-NER/pretrained_models/
|
| 58 |
-
tar -xzvf xlmr.large.tar.gz -C ./Roberta-NER/pretrained_models/
|
| 59 |
-
rm -r xlmr.base.tar.gz
|
| 60 |
-
rm -r xlmr.large.tar.gz
|
| 61 |
-
```
|
| 62 |
-
|
| 63 |
-
## Training arguments:
|
| 64 |
-
```bash
|
| 65 |
-
-h, --help show this help message and exit
|
| 66 |
-
--data_dir DATA_DIR The input data dir. Should contain the .tsv files (or
|
| 67 |
-
other data files) for the task.
|
| 68 |
-
--pretrained_path PRETRAINED_PATH
|
| 69 |
-
pretrained XLM-Roberta model path
|
| 70 |
-
--task_name TASK_NAME
|
| 71 |
-
The name of the task to train.
|
| 72 |
-
--output_dir OUTPUT_DIR
|
| 73 |
-
The output directory where the model predictions and
|
| 74 |
-
checkpoints will be written.
|
| 75 |
-
--max_seq_length MAX_SEQ_LENGTH
|
| 76 |
-
The maximum total input sequence length after
|
| 77 |
-
WordPiece tokenization. Sequences longer than this
|
| 78 |
-
will be truncated, and sequences shorter than this
|
| 79 |
-
will be padded.
|
| 80 |
-
--do_train Whether to run training.
|
| 81 |
-
--do_eval Whether to run eval or not.
|
| 82 |
-
--eval_on EVAL_ON Whether to run eval on the dev set or test set.
|
| 83 |
-
--do_lower_case Set this flag if you are using an uncased model.
|
| 84 |
-
--train_batch_size TRAIN_BATCH_SIZE
|
| 85 |
-
Total batch size for training.
|
| 86 |
-
--eval_batch_size EVAL_BATCH_SIZE
|
| 87 |
-
Total batch size for eval.
|
| 88 |
-
--learning_rate LEARNING_RATE
|
| 89 |
-
The initial learning rate for Adam.
|
| 90 |
-
--num_train_epochs NUM_TRAIN_EPOCHS
|
| 91 |
-
Total number of training epochs to perform.
|
| 92 |
-
--warmup_proportion WARMUP_PROPORTION
|
| 93 |
-
Proportion of training to perform linear learning rate
|
| 94 |
-
warmup for. E.g., 0.1 = 10% of training.
|
| 95 |
-
--weight_decay WEIGHT_DECAY
|
| 96 |
-
Weight deay if we apply some.
|
| 97 |
-
--adam_epsilon ADAM_EPSILON
|
| 98 |
-
Epsilon for Adam optimizer.
|
| 99 |
-
--max_grad_norm MAX_GRAD_NORM
|
| 100 |
-
Max gradient norm.
|
| 101 |
-
--no_cuda Whether not to use CUDA when available
|
| 102 |
-
--seed SEED random seed for initialization
|
| 103 |
-
--gradient_accumulation_steps GRADIENT_ACCUMULATION_STEPS
|
| 104 |
-
Number of updates steps to accumulate before
|
| 105 |
-
performing a backward/update pass.
|
| 106 |
-
--fp16 Whether to use 16-bit float precision instead of
|
| 107 |
-
32-bit
|
| 108 |
-
--fp16_opt_level FP16_OPT_LEVEL
|
| 109 |
-
For fp16: Apex AMP optimization level selected in
|
| 110 |
-
['O0', 'O1', 'O2', and 'O3'].See details at
|
| 111 |
-
https://nvidia.github.io/apex/amp.html
|
| 112 |
-
--loss_scale LOSS_SCALE
|
| 113 |
-
Loss scaling to improve fp16 numeric stability. Only
|
| 114 |
-
used when fp16 set to True. 0 (default value): dynamic
|
| 115 |
-
loss scaling. Positive power of 2: static loss scaling
|
| 116 |
-
value.
|
| 117 |
-
--dropout DROPOUT training dropout probability
|
| 118 |
-
--freeze_model whether to freeze the XLM-R base model and train only
|
| 119 |
-
the classification heads
|
| 120 |
-
```
|
| 121 |
-
## How to run
|
| 122 |
-
|
| 123 |
-
For example:
|
| 124 |
-
```bash
|
| 125 |
-
python ./Roberta-NER/main.py \
|
| 126 |
-
--data_dir ./Roberta-NER/data/coNLL-2003/ \
|
| 127 |
-
--task_name ner \
|
| 128 |
-
--output_dir ./Roberta-NER/result/ \
|
| 129 |
-
--max_seq_length 16 \
|
| 130 |
-
--num_train_epochs 1 \
|
| 131 |
-
--do_eval \
|
| 132 |
-
--warmup_proportion 0.1 \
|
| 133 |
-
--pretrained_path ./Roberta-NER/pretrained_models/xlmr.$PARAM_SET \
|
| 134 |
-
--learning_rate 0.00007 \
|
| 135 |
-
--do_train \
|
| 136 |
-
--eval_on test \
|
| 137 |
-
--train_batch_size 4 \
|
| 138 |
-
--dropout 0.2
|
| 139 |
-
```
|
| 140 |
-
If you want to use the XLM-R model's outputs as features without finetuning, Use the `--freeze_model` argument.
|
| 141 |
-
|
| 142 |
-
By default, the best model on the validation set is saved to `args.output_dir`. This model is then loaded and tested on the test set, if `--do_eval` and `--eval_on test`.
|
| 143 |
-
|
| 144 |
-
### Predicting
|
| 145 |
-
To predict named entities in any text using the trained model, you can run the following command:
|
| 146 |
-
```bash
|
| 147 |
-
python ./Roberta-NER/predict.py --pretrained_path ./Roberta-NER/pretrained_models/xlmr.base --output_dir ./Roberta-NER/result/ --text "your input text"
|
| 148 |
-
```
|
| 149 |
-
Simply replace `"your input text"` with the text you want to analyze.
|
| 150 |
-
|
| 151 |
-
## Contribution
|
| 152 |
-
We welcome contributions from the community. Please create an issue or submit a pull request so we can review and integrate it into the project.
|
| 153 |
-
|
| 154 |
-
## License
|
| 155 |
-
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|