File size: 2,107 Bytes
40d619e 589f886 8126bf7 40d619e 589f886 9de1eb8 589f886 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 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 |
---
license: apache-2.0
language:
- en
- zh
inference: false
---
# SeqGPT-560M
<!-- Provide a quick summary of what the model is/does. -->
This is SeqGPT-560M weight, a compact model targeting open-domain Natural Language Understanding (NLU). We refer you to our github [repo](https://github.com/Alibaba-NLP/SeqGPT) for more details.
## Model Details
### Model Description
<!-- Provide a longer summary of what this model is. -->
The model is fine-tuned based on [BLOOMZ-560M](https://huggingface.co/bigscience/bloomz-560m).
### Model Sources
<!-- Provide the basic links for the model. -->
- **Repository:** [SeqGPT](https://github.com/Alibaba-NLP/SeqGPT)
- **Paper:** [arxiv](https://arxiv.org/abs/2308.10529)
- **Demo:** [demo](https://www.modelscope.cn/studios/TTCoding/open_ner/summary)
## Uses
```py
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, AutoModel
model_name_or_path = 'DAMO-NLP/SeqGPT-560M'
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
model = AutoModelForCausalLM.from_pretrained(model_name_or_path)
tokenizer.padding_side = 'left'
tokenizer.truncation_side = 'left'
if torch.cuda.is_available():
model = model.half().cuda()
model.eval()
GEN_TOK = '[GEN]'
while True:
sent = input('输入/Input: ').strip()
task = input('分类/classify press 1, 抽取/extract press 2: ').strip()
labels = input('标签集/Label-Set (e.g, labelA,LabelB,LabelC): ').strip().replace(',', ',')
task = '分类' if task == '1' else '抽取'
# Changing the instruction can harm the performance
p = '输入: {}\n{}: {}\n输出: {}'.format(sent, task, labels, GEN_TOK)
input_ids = tokenizer(p, return_tensors="pt", padding=True, truncation=True, max_length=1024)
input_ids = input_ids.to(model.device)
outputs = model.generate(**input_ids, num_beams=4, do_sample=False, max_new_tokens=256)
input_ids = input_ids.get('input_ids', input_ids)
outputs = outputs[0][len(input_ids[0]):]
response = tokenizer.decode(outputs, skip_special_tokens=True)
print('BOT: ========== \n{}'.format(response))
``` |