traintogpb commited on
Commit
171cd58
1 Parent(s): 70c1f9e

chore: fix model card

Browse files
Files changed (1) hide show
  1. README.md +45 -44
README.md CHANGED
@@ -24,10 +24,10 @@ pipeline_tag: translation
24
  - Template:
25
 
26
  ```python
27
- prompt = f"Translate this from {src_lang} to {tgt_lang}\n### {src_lang}: {src_text}\n### {tgt_lang}:"
28
 
29
- >>> # src_lang can be 'English', '한국어'
30
- >>> # tgt_lang can be '한국어', 'English'
31
  ```
32
 
33
  - Issue:
@@ -35,11 +35,11 @@ pipeline_tag: translation
35
  Make sure to use the prompt proposed above.
36
 
37
  ```python
38
- prompt = f"""Translate this from {src_lang} to {tgt_lang}
39
- ### {src_lang}: {src_text}
40
- ### {tgt_lang}:"""
41
 
42
- >>> # DO NOT USE this prompt.
43
  ```
44
 
45
  And mind that there is no "space (`_`)" at the end of the prompt.
@@ -52,45 +52,46 @@ pipeline_tag: translation
52
 
53
  ### Usage (IMPORTANT)
54
  - Should remove the EOS token (`<|endoftext|>`, id=46332) at the end of the prompt.
55
- ```python
56
- # MODEL
57
- plm_name = 'beomi/open-llama-2-ko-7b'
58
- adapter_name = 'traintogpb/llama-2-enko-translator-7b-qlora-adapter'
59
- model = LlamaForCausalLM.from_pretrained(
60
- plm_name,
61
- max_length=768,
62
- quantization_config=bnb_config, # Use the QLoRA config above
63
- attn_implementation='flash_attention_2',
64
- torch_dtype=torch.bfloat16
65
- )
66
- model = PeftModel.from_pretrained(
67
- model,
68
- adapter_name,
69
- torch_dtype=torch.bfloat16
70
- )
71
 
72
- # TOKENIZER
73
- tokenizer = LlamaTokenizer.from_pretrained(plm_name)
74
- tokenizer.pad_token = "</s>"
75
- tokenizer.pad_token_id = 2
76
- tokenizer.eos_token = "<|endoftext|>" # Must be differentiated from the PAD token
77
- tokenizer.eos_token_id = 46332
78
- tokenizer.add_eos_token = True
79
- tokenizer.model_max_length = 768
 
 
 
 
 
 
 
 
80
 
81
- # INFERENCE
82
- text = "NMIXX is the world-best female idol group, who came back with the new song 'DASH'."
83
- prompt = f"Translate this from {src_lang} to {tgt_lang}\n### {src_lang}: {src_text}\n### {tgt_lang}:"
 
 
 
 
 
84
 
85
- inputs = tokenizer(prompt, return_tensors="pt", max_length=max_length, truncation=True)
86
- # REMOVE EOS TOKEN IN THE PROMPT
87
- inputs['input_ids'] = inputs['input_ids'][0][:-1].unsqueeze(dim=0)
88
- inputs['attention_mask'] = inputs['attention_mask'][0][:-1].unsqueeze(dim=0)
89
 
90
- outputs = model.generate(**inputs, max_length=max_length, eos_token_id=46332)
 
 
 
91
 
92
- input_len = len(inputs['input_ids'].squeeze())
93
-
94
- translated_text = tokenizer.decode(outputs[0][input_len:], skip_special_tokens=True)
95
- print(translated_text)
96
- ```
 
 
 
24
  - Template:
25
 
26
  ```python
27
+ prompt = f"Translate this from {src_lang} to {tgt_lang}\n### {src_lang}: {src_text}\n### {tgt_lang}:"
28
 
29
+ >>> # src_lang can be 'English', '한국어'
30
+ >>> # tgt_lang can be '한국어', 'English'
31
  ```
32
 
33
  - Issue:
 
35
  Make sure to use the prompt proposed above.
36
 
37
  ```python
38
+ prompt = f"""Translate this from {src_lang} to {tgt_lang}
39
+ ### {src_lang}: {src_text}
40
+ ### {tgt_lang}:"""
41
 
42
+ >>> # DO NOT USE this prompt
43
  ```
44
 
45
  And mind that there is no "space (`_`)" at the end of the prompt.
 
52
 
53
  ### Usage (IMPORTANT)
54
  - Should remove the EOS token (`<|endoftext|>`, id=46332) at the end of the prompt.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
+ ```python
57
+ # MODEL
58
+ plm_name = 'beomi/open-llama-2-ko-7b'
59
+ adapter_name = 'traintogpb/llama-2-enko-translator-7b-qlora-adapter'
60
+ model = LlamaForCausalLM.from_pretrained(
61
+ plm_name,
62
+ max_length=768,
63
+ quantization_config=bnb_config, # Use the QLoRA config above
64
+ attn_implementation='flash_attention_2',
65
+ torch_dtype=torch.bfloat16
66
+ )
67
+ model = PeftModel.from_pretrained(
68
+ model,
69
+ adapter_name,
70
+ torch_dtype=torch.bfloat16
71
+ )
72
 
73
+ # TOKENIZER
74
+ tokenizer = LlamaTokenizer.from_pretrained(plm_name)
75
+ tokenizer.pad_token = "</s>"
76
+ tokenizer.pad_token_id = 2
77
+ tokenizer.eos_token = "<|endoftext|>" # Must be differentiated from the PAD token
78
+ tokenizer.eos_token_id = 46332
79
+ tokenizer.add_eos_token = True
80
+ tokenizer.model_max_length = 768
81
 
82
+ # INFERENCE
83
+ text = "NMIXX is the world-best female idol group, who came back with the new song 'DASH'."
84
+ prompt = f"Translate this from {src_lang} to {tgt_lang}\n### {src_lang}: {src_text}\n### {tgt_lang}:"
 
85
 
86
+ inputs = tokenizer(prompt, return_tensors="pt", max_length=max_length, truncation=True)
87
+ # REMOVE EOS TOKEN IN THE PROMPT
88
+ inputs['input_ids'] = inputs['input_ids'][0][:-1].unsqueeze(dim=0)
89
+ inputs['attention_mask'] = inputs['attention_mask'][0][:-1].unsqueeze(dim=0)
90
 
91
+ outputs = model.generate(**inputs, max_length=max_length, eos_token_id=46332)
92
+
93
+ input_len = len(inputs['input_ids'].squeeze())
94
+
95
+ translated_text = tokenizer.decode(outputs[0][input_len:], skip_special_tokens=True)
96
+ print(translated_text)
97
+ ```