Text Generation
Transformers
PyTorch
Chinese
gpt2
VAE
CVAE
NER
Data Augmentation
text-generation-inference
Instructions to use IDEA-CCNL/Randeng-DELLA-CVAE-226M-NER-Chinese with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use IDEA-CCNL/Randeng-DELLA-CVAE-226M-NER-Chinese with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="IDEA-CCNL/Randeng-DELLA-CVAE-226M-NER-Chinese")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("IDEA-CCNL/Randeng-DELLA-CVAE-226M-NER-Chinese") model = AutoModelForCausalLM.from_pretrained("IDEA-CCNL/Randeng-DELLA-CVAE-226M-NER-Chinese", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use IDEA-CCNL/Randeng-DELLA-CVAE-226M-NER-Chinese with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "IDEA-CCNL/Randeng-DELLA-CVAE-226M-NER-Chinese" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "IDEA-CCNL/Randeng-DELLA-CVAE-226M-NER-Chinese", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/IDEA-CCNL/Randeng-DELLA-CVAE-226M-NER-Chinese
- SGLang
How to use IDEA-CCNL/Randeng-DELLA-CVAE-226M-NER-Chinese with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "IDEA-CCNL/Randeng-DELLA-CVAE-226M-NER-Chinese" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "IDEA-CCNL/Randeng-DELLA-CVAE-226M-NER-Chinese", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "IDEA-CCNL/Randeng-DELLA-CVAE-226M-NER-Chinese" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "IDEA-CCNL/Randeng-DELLA-CVAE-226M-NER-Chinese", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use IDEA-CCNL/Randeng-DELLA-CVAE-226M-NER-Chinese with Docker Model Runner:
docker model run hf.co/IDEA-CCNL/Randeng-DELLA-CVAE-226M-NER-Chinese
Commit ·
15c28f5
1
Parent(s): 7a44969
Update README.md
Browse files
README.md
CHANGED
|
@@ -45,9 +45,45 @@ from torch.nn.utils.rnn import pad_sequence
|
|
| 45 |
from fengshen.models.deepVAE.deep_vae import Della
|
| 46 |
from transformers.models.bert.tokenization_bert import BertTokenizer
|
| 47 |
|
| 48 |
-
tokenizer = BertTokenizer.from_pretrained("IDEA-CCNL/Randeng-DELLA-
|
| 49 |
-
vae_model = Della.from_pretrained("IDEA-CCNL/Randeng-DELLA-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
```
|
| 53 |
|
|
|
|
| 45 |
from fengshen.models.deepVAE.deep_vae import Della
|
| 46 |
from transformers.models.bert.tokenization_bert import BertTokenizer
|
| 47 |
|
| 48 |
+
tokenizer = BertTokenizer.from_pretrained("IDEA-CCNL/Randeng-DELLA-CVAE-226M-NER-Chinese")
|
| 49 |
+
vae_model = Della.from_pretrained("IDEA-CCNL/Randeng-DELLA-CVAE-226M-NER-Chinese")
|
| 50 |
+
|
| 51 |
+
special_tokens_dict = {'bos_token': '<BOS>', 'eos_token': '<EOS>', 'additional_special_tokens': ['<ENT>', '<ENS>']}
|
| 52 |
+
tokenizer.add_special_tokens(special_tokens_dict)
|
| 53 |
+
|
| 54 |
+
model = vae_model.model
|
| 55 |
+
ent_token_type_id = tokenizer.additional_special_tokens_ids[0]
|
| 56 |
+
ent_token_sep_id = tokenizer.additional_special_tokens_ids[1]
|
| 57 |
+
bos_token_id, eos_token_id = tokenizer.bos_token_id, tokenizer.eos_token_id
|
| 58 |
+
decoder_target, decoder_entities = [], []
|
| 59 |
+
entity_list = [('体验中心', '地点/地理位置'), ('昨天', '时间')]
|
| 60 |
+
|
| 61 |
+
for ent in entity_list:
|
| 62 |
+
entity_name = tokenizer.convert_tokens_to_ids(tokenizer.tokenize(ent[0]))
|
| 63 |
+
entity_type = tokenizer.convert_tokens_to_ids(tokenizer.tokenize(ent[1]))
|
| 64 |
+
decoder_entities.extend(entity_name + [ent_token_type_id] + entity_type + [ent_token_sep_id])
|
| 65 |
+
decoder_entities.extend([bos_token_id]) # for generation
|
| 66 |
+
decoder_target.append(torch.tensor(decoder_entities, dtype=torch.long))
|
| 67 |
+
inputs = pad_sequence(decoder_target, batch_first=True, padding_value=0)
|
| 68 |
+
|
| 69 |
+
encoder_outputs = model.encoder(input_ids=inputs.to(device))
|
| 70 |
+
prior_z_list, prior_output_list = model.get_cond_prior_vecs(encoder_outputs.hidden_states[1:],
|
| 71 |
+
inputs, sample=True, beta_logvar=0.)
|
| 72 |
+
outputs = model.decoder.generate(input_ids=inputs.to(device), layer_latent_vecs=prior_z_list, labels=None,
|
| 73 |
+
label_ignore=model.pad_token_id, num_return_sequences=32, max_new_tokens=256,
|
| 74 |
+
eos_token_id=tokenizer.eos_token_id, pad_token_id=tokenizer.pad_token_id,
|
| 75 |
+
no_repeat_ngram_size=-1, do_sample=True, top_p=0.5)
|
| 76 |
+
|
| 77 |
+
print(tokenizer.decode(inputs[0]))
|
| 78 |
+
gen_sents = []
|
| 79 |
+
for idx in range(len(outputs)):
|
| 80 |
+
sent_len= 512 if eos_token_id not in outputs[idx].tolist() else outputs[idx].tolist().index(eos_token_id) + 1
|
| 81 |
+
start_loc = outputs[idx].tolist().index(bos_token_id)
|
| 82 |
+
gen_sent = tokenizer.decode(outputs[idx][start_loc:sent_len]).replace(' ', '')
|
| 83 |
+
if all([ent[0] in gen_sent for ent in entity_list]):
|
| 84 |
+
gen_sents.append(gen_sent)
|
| 85 |
+
for s in gen_sents:
|
| 86 |
+
print(s)
|
| 87 |
|
| 88 |
```
|
| 89 |
|