初始化项目,由ModelHub XC社区提供模型
Model: cambridgeltl/simctg_rocstories Source: Original Platform
This commit is contained in:
28
.gitattributes
vendored
Normal file
28
.gitattributes
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||
*.arrow filter=lfs diff=lfs merge=lfs -text
|
||||
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||
*.ftz filter=lfs diff=lfs merge=lfs -text
|
||||
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||
*.h5 filter=lfs diff=lfs merge=lfs -text
|
||||
*.joblib filter=lfs diff=lfs merge=lfs -text
|
||||
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.model filter=lfs diff=lfs merge=lfs -text
|
||||
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
||||
*.onnx filter=lfs diff=lfs merge=lfs -text
|
||||
*.ot filter=lfs diff=lfs merge=lfs -text
|
||||
*.parquet filter=lfs diff=lfs merge=lfs -text
|
||||
*.pb filter=lfs diff=lfs merge=lfs -text
|
||||
*.pt filter=lfs diff=lfs merge=lfs -text
|
||||
*.pth filter=lfs diff=lfs merge=lfs -text
|
||||
*.rar filter=lfs diff=lfs merge=lfs -text
|
||||
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
||||
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.tflite filter=lfs diff=lfs merge=lfs -text
|
||||
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||
*.wasm filter=lfs diff=lfs merge=lfs -text
|
||||
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
||||
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
||||
60
README.md
Normal file
60
README.md
Normal file
@@ -0,0 +1,60 @@
|
||||
This model provides a GPT-2 language model trained with SimCTG on the ROCStories benchmark [(Mostafazadeh et al., 2016)](https://aclanthology.org/N16-1098.pdf) based on our paper [_A Contrastive Framework for Neural Text Generation_](https://arxiv.org/abs/2202.06417).
|
||||
|
||||
We provide a detailed tutorial on how to apply SimCTG and Contrastive Search in our [project repo](https://github.com/yxuansu/SimCTG#4-huggingface-style-tutorials-back-to-top). In the following, we illustrate a brief tutorial on how to use our approach to perform text generation.
|
||||
|
||||
## 1. Installation of SimCTG:
|
||||
```yaml
|
||||
pip install simctg --upgrade
|
||||
```
|
||||
|
||||
## 2. Initialize SimCTG Model:
|
||||
```python
|
||||
import torch
|
||||
# load SimCTG language model
|
||||
from simctg.simctggpt import SimCTGGPT
|
||||
model_name = r'cambridgeltl/simctg_rocstories'
|
||||
model = SimCTGGPT(model_name)
|
||||
model.eval()
|
||||
tokenizer = model.tokenizer
|
||||
```
|
||||
|
||||
## 3. Prepare the Text Prefix:
|
||||
```python
|
||||
prompt = r"Accident in the Lab <|endoftext|>"
|
||||
print ('Prefix is: {}'.format(prompt))
|
||||
tokens = model.tokenizer.tokenize(prompt)
|
||||
input_ids = model.tokenizer.convert_tokens_to_ids(tokens)
|
||||
input_ids = torch.LongTensor(input_ids).view(1,-1)
|
||||
```
|
||||
|
||||
## 4. Generate Text with Contrastive Search:
|
||||
```python
|
||||
beam_width, alpha, decoding_len = 5, 0.65, 45
|
||||
output = model.fast_contrastive_search(input_ids=input_ids, beam_width=beam_width,
|
||||
alpha=alpha, decoding_len=decoding_len)
|
||||
print("Output:\n" + 100 * '-')
|
||||
print(tokenizer.decode(output).split(model.tokenizer.eos_token)[1].strip())
|
||||
'''
|
||||
Prefix is: Accident in the Lab <|endoftext|>
|
||||
Output:
|
||||
----------------------------------------------------------------------------------------------------
|
||||
Tom went to work one day. He noticed a lab accident in the lab. Tom was worried about his safety at work.
|
||||
Unfortunately the accident didn't go well. Tom wound up leaving early to get back on the job.
|
||||
'''
|
||||
```
|
||||
|
||||
For more details of our work, please refer to our main [project repo](https://github.com/yxuansu/SimCTG).
|
||||
|
||||
## 5. Citation:
|
||||
If you find our paper and resources useful, please kindly leave a star and cite our paper. Thanks!
|
||||
|
||||
```bibtex
|
||||
@article{su2022contrastive,
|
||||
title={A Contrastive Framework for Neural Text Generation},
|
||||
author={Su, Yixuan and Lan, Tian and Wang, Yan and Yogatama, Dani and Kong, Lingpeng and Collier, Nigel},
|
||||
journal={arXiv preprint arXiv:2202.06417},
|
||||
year={2022}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
1
added_tokens.json
Normal file
1
added_tokens.json
Normal file
@@ -0,0 +1 @@
|
||||
{"<_PAD_>": 50257}
|
||||
37
config.json
Normal file
37
config.json
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"_name_or_path": "gpt2",
|
||||
"activation_function": "gelu_new",
|
||||
"architectures": [
|
||||
"GPT2LMHeadModel"
|
||||
],
|
||||
"attn_pdrop": 0.1,
|
||||
"bos_token_id": 50256,
|
||||
"embd_pdrop": 0.1,
|
||||
"eos_token_id": 50256,
|
||||
"gradient_checkpointing": false,
|
||||
"initializer_range": 0.02,
|
||||
"layer_norm_epsilon": 1e-05,
|
||||
"model_type": "gpt2",
|
||||
"n_ctx": 1024,
|
||||
"n_embd": 768,
|
||||
"n_head": 12,
|
||||
"n_inner": null,
|
||||
"n_layer": 12,
|
||||
"n_positions": 1024,
|
||||
"resid_pdrop": 0.1,
|
||||
"scale_attn_weights": true,
|
||||
"summary_activation": null,
|
||||
"summary_first_dropout": 0.1,
|
||||
"summary_proj_to_labels": true,
|
||||
"summary_type": "cls_index",
|
||||
"summary_use_proj": true,
|
||||
"task_specific_params": {
|
||||
"text-generation": {
|
||||
"do_sample": true,
|
||||
"max_length": 50
|
||||
}
|
||||
},
|
||||
"transformers_version": "4.7.0",
|
||||
"use_cache": true,
|
||||
"vocab_size": 50258
|
||||
}
|
||||
50001
merges.txt
Normal file
50001
merges.txt
Normal file
File diff suppressed because it is too large
Load Diff
3
pytorch_model.bin
Normal file
3
pytorch_model.bin
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:a92042035e69bbe5326228bccb44b2a3622117feef87974488c1c733a67cef5b
|
||||
size 510409625
|
||||
1
special_tokens_map.json
Normal file
1
special_tokens_map.json
Normal file
@@ -0,0 +1 @@
|
||||
{"bos_token": "<|endoftext|>", "eos_token": "<|endoftext|>", "unk_token": "<|endoftext|>"}
|
||||
1
tokenizer.json
Normal file
1
tokenizer.json
Normal file
File diff suppressed because one or more lines are too long
1
tokenizer_config.json
Normal file
1
tokenizer_config.json
Normal file
@@ -0,0 +1 @@
|
||||
{"unk_token": "<|endoftext|>", "bos_token": "<|endoftext|>", "eos_token": "<|endoftext|>", "add_prefix_space": false, "model_max_length": 1024, "special_tokens_map_file": null, "name_or_path": "gpt2"}
|
||||
1
vocab.json
Normal file
1
vocab.json
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user