traintogpb commited on
Commit
e658f6d
1 Parent(s): 1ea767f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +56 -0
README.md CHANGED
@@ -7,5 +7,61 @@ language:
7
  - ko
8
  pipeline_tag: translation
9
  ---
 
 
10
 
 
 
 
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  - ko
8
  pipeline_tag: translation
9
  ---
10
+ ### Pretrained LM
11
+ - [beomi/Llama-3-Open-Ko-8B](https://huggingface.co/beomi/Llama-3-Open-Ko-8B) (MIT License)
12
 
13
+ ### Training Dataset
14
+ - [traintogpb/aihub-flores-koen-integrated-sparta-mini-300k](https://huggingface.co/datasets/traintogpb/aihub-flores-koen-integrated-sparta-mini-300k)
15
+ - Can translate in Enlgish-Korean (bi-directional)
16
 
17
+ ### Prompt
18
+ - Template:
19
+ ```python
20
+ prompt = f"Translate this from {src_lang} to {tgt_lang}\n### {src_lang}: {src_text}\n### {tgt_lang}: "
21
+
22
+ >>> # src_lang can be 'English', '한국어'
23
+ >>> # tgt_lang can be '한국어', 'English'
24
+ ```
25
+ Mind that there is a "space (`_`)" at the end of the prompt (unpredictable first token will be popped up).
26
+ But if you use vLLM, it's okay to remove the final space(`_`).
27
+
28
+ ### Training
29
+ - Trained with QLoRA
30
+ - PLM: NormalFloat 4-bit
31
+ - Adapter: BrainFloat 16-bit
32
+ - Adapted to all the linear layers (around 2.05%)
33
+ - Merge adapters and upscaled in BrainFloat 16-bit precision
34
+
35
+ ### Usage (IMPORTANT)
36
+ - Should remove the EOS token (`<|endoftext|>`, id=46332) at the end of the prompt.
37
+ ```python
38
+ # MODEL
39
+ model_name = 'traintogpb/llama-3-enko-translator-8b-qlora-bf16-upscaled'
40
+ model = AutoModelForCausalLM.from_pretrained(
41
+ model_name,
42
+ max_length=768,
43
+ attn_implementation='flash_attention_2',
44
+ torch_dtype=torch.bfloat16,
45
+ )
46
+
47
+ tokenizer = AutoTokenizer.from_pretrained(adapter_name)
48
+ tokenizer.pad_token_id = 128002 # eos_token_id and pad_token_id should be different
49
+
50
+ text = "Someday, QWER will be the greatest girl band in the world."
51
+ input_prompt = f"Translate this from English to 한국어.\n### English: {text}\n### 한국어:"
52
+ inputs = tokenizer(input_prompt, max_length=768, truncation=True, return_tensors='pt')
53
+
54
+ if inputs['input_ids'][0][-1] == tokenizer.eos_token_id:
55
+ inputs['input_ids'] = inputs['input_ids'][0][:-1].unsqueeze(dim=0)
56
+ inputs['attention_mask'] = inputs['attention_mask'][0][:-1].unsqueeze(dim=0)
57
+
58
+ outputs = model.generate(**inputs, max_length=768, eos_token_id=tokenizer.eos_token_id)
59
+
60
+ input_len = len(inputs['input_ids'].squeeze())
61
+ translation = tokenizer.decode(outputs[0][input_len:], skip_special_tokens=True)
62
+ print(translation)
63
+ ```
64
+
65
+ ### Framework versions
66
+
67
+ - PEFT 0.8.2