shunxing1234 commited on
Commit
191ee55
1 Parent(s): 1fbf245

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +6 -12
README.md CHANGED
@@ -40,25 +40,19 @@ The additional details of the Aquila model will be presented in the official tec
40
  ```python
41
  from transformers import AutoTokenizer, AutoModelForCausalLM
42
  import torch
43
-
44
  model_info = "BAAI/Aquila2-7B"
45
  tokenizer = AutoTokenizer.from_pretrained(model_info, trust_remote_code=True)
46
  model = AutoModelForCausalLM.from_pretrained(model_info, trust_remote_code=True)
47
  model.eval()
48
- model.to("cuda:0")
49
-
50
- text = "汽车EDR是什么"
51
-
52
  tokens = tokenizer.encode_plus(text)['input_ids'][:-1]
53
-
54
- tokens = torch.tensor(tokens)[None,].to("cuda:0")
55
-
56
-
57
  with torch.no_grad():
58
- out = model.generate(tokens, do_sample=True, max_length=512, eos_token_id=100007)[0]
59
-
60
  out = tokenizer.decode(out.cpu().numpy().tolist())
61
-
62
  print(out)
63
  ```
64
 
 
40
  ```python
41
  from transformers import AutoTokenizer, AutoModelForCausalLM
42
  import torch
43
+ device = torch.device("cuda")
44
  model_info = "BAAI/Aquila2-7B"
45
  tokenizer = AutoTokenizer.from_pretrained(model_info, trust_remote_code=True)
46
  model = AutoModelForCausalLM.from_pretrained(model_info, trust_remote_code=True)
47
  model.eval()
48
+ model.to(device)
49
+ text = "请给出10个要到北京旅游的理由。"
 
 
50
  tokens = tokenizer.encode_plus(text)['input_ids'][:-1]
51
+ tokens = torch.tensor(tokens)[None,].to(device)
52
+ stop_tokens = ["###", "[UNK]", "</s>"]
 
 
53
  with torch.no_grad():
54
+ out = model.generate(tokens, do_sample=True, max_length=512, eos_token_id=100007, bad_words_ids=[[tokenizer.encode(token)[0] for token in stop_tokens]])[0]
 
55
  out = tokenizer.decode(out.cpu().numpy().tolist())
 
56
  print(out)
57
  ```
58