CjangCjengh commited on
Commit
3989e9e
1 Parent(s): a6053dc

Upload files

Browse files
Files changed (1) hide show
  1. README.md +55 -0
README.md ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-nc-sa-4.0
3
+ language:
4
+ - th
5
+ - zh
6
+ ---
7
+ 基于[Sakura-14B-Qwen2beta-Base-v2](https://huggingface.co/SakuraLLM/Sakura-14B-Qwen2beta-Base-v2),在泰中翻译数据上微调(包含69MB日轻的泰翻中翻对照以及10MB中文网文的泰翻)
8
+
9
+ 模型仅支持泰文→简体中文的翻译
10
+
11
+ ```python
12
+ from transformers import AutoModelForCausalLM, AutoTokenizer
13
+ from transformers.generation import GenerationConfig
14
+
15
+ model_path = 'CjangCjengh/LN-Thai-14B-v0.1'
16
+ tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
17
+ model = AutoModelForCausalLM.from_pretrained(model_path, device_map='auto', trust_remote_code=True).eval()
18
+ model.generation_config = GenerationConfig.from_pretrained(model_path, trust_remote_code=True)
19
+
20
+ # 段落之间用\n分隔
21
+ text = '''“อาจารย์คะ ช่วยรับหนูเป็นลูกศิษย์ด้วยนะคะ”
22
+ มิยุจัง เด็กสาวได้รับรู้ความลับของ ชาลี เด็กหนุ่มว่า ตัวจริงของคือท่านอาจารย์ 007H นักเขียนนิยายลามกชื่อดังที่เธอคลั่งไคล้ เด็กสาวผู้อยากจะเขียนนิยายลามกแบบนี้บ้างจึงมาขอฝากตัวเป็นลูกศิษย์ของชาลี พร้อมกับเรื่องวุ่น ๆ ของเด็กหนุ่มที่อยากไล่เธอออกไปก่อนที่ชีวิตส่วนตัวของตัวเองจะพินาศไปในพริบตา ทว่า นานวันเข้าความสัมพันธ์ของอาจารย์หนุ่มกับลูกศิษย์ตัวน้อยก็เริ่มแน่นแฟ้นมากขึ้น
23
+ นิยายลามกเรื่องใหม่ครั้งนี้ชาลีจะเขียนเสร็จก่อนหรือเข้าไปนอนในดาวหมีก่อนกันนะ ?'''
24
+
25
+ # 去除零宽空格
26
+ text = text.replace('\u200b','')
27
+
28
+ # 文本长度控制在2048以内
29
+ assert len(text) < 2048
30
+
31
+ messages = [
32
+ {'role': 'system', 'content': '你是一个轻小说译者,善于将外文轻小说翻译成中文'},
33
+ {'role': 'user', 'content': f'翻译成中文:\n{text}'}
34
+ ]
35
+
36
+ text = tokenizer.apply_chat_template(
37
+ messages,
38
+ tokenize=False,
39
+ add_generation_prompt=True
40
+ )
41
+
42
+ model_inputs = tokenizer([text], return_tensors='pt').to('cuda')
43
+
44
+ generated_ids = model.generate(
45
+ model_inputs.input_ids,
46
+ max_new_tokens=1024
47
+ )
48
+
49
+ generated_ids = [
50
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
51
+ ]
52
+
53
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
54
+ print(response)
55
+ ```