raynardj commited on
Commit
d1dc7ab
1 Parent(s): e1fc164

with example

Browse files
Files changed (1) hide show
  1. README.md +60 -1
README.md CHANGED
@@ -14,4 +14,63 @@ widget:
14
  ---
15
 
16
  # From modern Chinese to Ancient Chinese
17
- > 从现代文到文言文
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  ---
15
 
16
  # From modern Chinese to Ancient Chinese
17
+ > This model translate modern Chinese to Classical Chinese, so I guess who's interested in the problemset can speak at least modern Chinese, so... let me continue the documentation in Chinese
18
+
19
+ > 从现代文到文言文的翻译器, 训练语料是就是九十多万句句对, [数据集链接](https://github.com/BangBOOM/Classical-Chinese)
20
+
21
+ ## 推荐的inference 通道
22
+ ```python
23
+ from transformers import (
24
+ EncoderDecoderModel,
25
+ AutoTokenizer
26
+ )
27
+ PRETRAINED = "raynardj/wenyanwen-chinese-translate-to-ancient"
28
+ tokenizer = AutoTokenizer.from_pretrained(PRETRAINED)
29
+ model = EncoderDecoderModel.from_pretrained(PRETRAINED)
30
+
31
+ def inference(text):
32
+ tk_kwargs = dict(
33
+ truncation=True,
34
+ max_length=128,
35
+ padding="max_length",
36
+ return_tensors='pt')
37
+
38
+ inputs = tokenizer([text,],**tk_kwargs)
39
+ with torch.no_grad():
40
+ return tokenizer.batch_decode(
41
+ model.generate(
42
+ inputs.input_ids,
43
+ attention_mask=inputs.attention_mask,
44
+ num_beams=3,
45
+ bos_token_id=101,
46
+ eos_token_id=tokenizer.sep_token_id,
47
+ pad_token_id=tokenizer.pad_token_id,
48
+ ), skip_special_tokens=True)
49
+ ```
50
+
51
+ ## 目前版本的案例
52
+ ```python
53
+ >>> inference('你连一百块都不肯给我')
54
+ ['不 肯 与 我 百 钱 。']
55
+ ```
56
+
57
+ ```python
58
+ >>> inference("他不能做长远的谋划")
59
+ ['不 能 为 远 谋 。']
60
+ ```
61
+
62
+ ```python
63
+ >>> inference("我们要干一番大事业")
64
+ ['吾 属 当 举 大 事 。']
65
+ ```
66
+
67
+ ```python
68
+ >>> inference("这感觉,已经不对,我努力,在挽回")
69
+ ['此 之 谓 也 , 已 不 可 矣 , 我 勉 之 , 以 回 之 。']
70
+ ```
71
+
72
+ ```python
73
+ >>> inference("轻轻地我走了, 正如我轻轻地来, 我挥一挥衣袖,不带走一片云彩")
74
+ ['轻 我 行 , 如 我 轻 来 , 挥 袂 不 携 一 片 云 。']
75
+ ```
76
+