binxu.wang commited on
Commit
ec0497c
1 Parent(s): bfd7dfd

debug loading

Browse files
Files changed (1) hide show
  1. app.py +11 -12
app.py CHANGED
@@ -3,23 +3,22 @@ import transformers
3
  # import tokenizers
4
  import torch
5
  from transformers import pipeline, set_seed
6
- from transformers import GPT2Model, GPT2Config, GPT2LMHeadModel
7
- from transformers import BertTokenizerFast
8
  # https://huggingface.co/docs/hub/spaces-sdks-gradio
9
 
10
- tokenizer_bert = BertTokenizerFast.from_pretrained('bert-base-chinese',
11
- additional_special_tokens=["<s>","<pad>","</s>","<unk>","<mask>"],
12
- pad_token='<pad>' ,max_len=512)
13
 
14
- configuration = GPT2Config(vocab_size=25000, n_layer=8)
15
- model = GPT2LMHeadModel(config=configuration)
16
- #%%
17
- # path2pytorch_model = "pytorch_model.bin"
18
  # path2pytorch_model = "/home/binxuwang/Datasets/ancChn_L8_LB_cont_output/checkpoint-100000/pytorch_model.bin"
19
  # model.load_state_dict(torch.load(path2pytorch_model))
20
- model.from_pretrained(("binxu/Ziyue-GPT2"))
21
-
22
- generator = pipeline('text-generation', model=model, tokenizer=tokenizer_bert)
 
23
 
24
  def generate(prompt):
25
  outputs = generator(prompt, max_length=50, num_return_sequences=5, num_beams=10, repetition_penalty=1.5)
 
3
  # import tokenizers
4
  import torch
5
  from transformers import pipeline, set_seed
6
+ from transformers import GPT2Model, GPT2Config, GPT2LMHeadModel, AutoModel
7
+ from transformers import BertTokenizerFast, BertTokenizer
8
  # https://huggingface.co/docs/hub/spaces-sdks-gradio
9
 
10
+ # tokenizer_bert = BertTokenizer.from_pretrained('bert-base-chinese',
11
+ # additional_special_tokens=["<s>","<pad>","</s>","<unk>","<mask>"],
12
+ # pad_token='<pad>', max_len=512)
13
 
14
+ # configuration = GPT2Config(vocab_size=25000, n_layer=8)
15
+ # model = GPT2LMHeadModel(config=configuration)
 
 
16
  # path2pytorch_model = "/home/binxuwang/Datasets/ancChn_L8_LB_cont_output/checkpoint-100000/pytorch_model.bin"
17
  # model.load_state_dict(torch.load(path2pytorch_model))
18
+ # model.from_pretrained("binxu/Ziyue-GPT2")
19
+ #%%
20
+ model = GPT2LMHeadModel.from_pretrained("binxu/Ziyue-GPT2")
21
+ generator = pipeline('text-generation', model=model, tokenizer='bert-base-chinese')
22
 
23
  def generate(prompt):
24
  outputs = generator(prompt, max_length=50, num_return_sequences=5, num_beams=10, repetition_penalty=1.5)