Skip to content

Commit

Permalink
fix some typo
Browse files Browse the repository at this point in the history
  • Loading branch information
yunfan committed Nov 14, 2021
1 parent c9238aa commit 24eceed
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ Then, use the PTMs as the following example, where `MODEL_NAME` is the correspon

For CPT:
```python
from modeling_cpt import BertTokenizer, CPTForConditionalGeneration
from modeling_cpt import CPTForConditionalGeneration
from transformers import BertTokenizer
tokenizer = BertTokenizer.from_pretrained("MODEL_NAME")
model = CPTForConditionalGeneration.from_pretrained("MODEL_NAME")
print(model)
Expand All @@ -63,9 +64,9 @@ print(model)

After initializing the model, you can use the following lines to generate text.
```python
>>> inputs = tokenizer.encode("北京是[MASK]的首都", return_tensors='pt')
>>> input_ids = tokenizer.encode("北京是[MASK]的首都", return_tensors='pt')
>>> pred_ids = model.generate(input_ids, num_beams=4, max_length=20)
>>> print(tokenizer.convert_ids_to_tokens(pred_ids[i]))
>>> print(tokenizer.convert_ids_to_tokens(pred_ids[0]))
['[SEP]', '[CLS]', '', '', '', '', '', '', '', '', '[SEP]']
```

Expand Down
5 changes: 4 additions & 1 deletion finetune/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ This repo contains the fine-tuning code for CPT on multiple NLU and NLG tasks, s
## Requirements
- pytorch==1.8.1
- transformers==4.4.1
- fitlog
- fastNLP

## Run
The code and running examples are listed in the corresponding folders of the fine-tuning tasks.
Expand All @@ -18,7 +20,8 @@ The code and running examples are listed in the corresponding folders of the fin
You can also fine-tuning CPT on other tasks by adding `modeling_cpt.py` into your project and use the following code to use CPT.

```python
from modeling_cpt import BertTokenizer, CPTForConditionalGeneration
from modeling_cpt import CPTForConditionalGeneration
from transformers import BertTokenizer
tokenizer = BertTokenizer.from_pretrained("MODEL_NAME")
model = CPTForConditionalGeneration.from_pretrained("MODEL_NAME")
print(model)
Expand Down
4 changes: 2 additions & 2 deletions finetune/mrc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ To train and evaluate **CPT$_u$**, **CPT$_g$** and **CPT$_{ug}$**, run the pytho
```bash
export MODEL_TYPE=cpt-base
export MODEL_NAME=fnlp/cpt-base
export CLUE_DATA_DIR=/path/to/mrc_data_dir
export CLUE_DATA_DIR=~/workdir/datasets/CLUEdatasets/
export TASK_NAME=drcd
export CLS_MODE=1
python run_mrc.py \
Expand All @@ -22,7 +22,7 @@ python run_mrc.py \
--gradient_accumulation_steps 4 \
--lr=3e-5 \
--dropout=0.2 \
--CLS_MODE=$CLS_MODE \
--cls_mode=$CLS_MODE \
--warmup_rate=0.1 \
--weight_decay_rate=0.01 \
--max_seq_length=512 \
Expand Down
4 changes: 2 additions & 2 deletions finetune/mrc/run_mrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def test(model, args, eval_examples, eval_features, device, name):
torch.distributed.barrier()

# load the bert setting
if 'bert' == args.model_type:
if 'bert' in args.model_type or 'cpt' in args.model_type:
if 'large' in args.init_restore_dir or '24' in args.init_restore_dir:
config_path = 'hfl/chinese-roberta-wwm-ext-large'
else:
Expand All @@ -219,7 +219,7 @@ def test(model, args, eval_examples, eval_features, device, name):
tokenizer = BertTokenizer.from_pretrained(config_path)
bert_config.hidden_dropout_prob = args.dropout
bert_config.attention_probs_dropout_prob = args.dropout
if 'arch' in args.init_restore_dir:
if 'cpt' in args.init_restore_dir:
config = CPTConfig.from_pretrained(args.init_restore_dir)
config.cls_mode = args.cls_mode
config.attention_dropout = args.dropout
Expand Down

0 comments on commit 24eceed

Please sign in to comment.