File size: 2,042 Bytes
5e0f476 d1dc7ab |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
---
language:
- zh
tags:
- translation
- 文言文
- ancient
license: apache-2.0
datasets:
- cctc
widget:
- text: "如果不除掉他,之后会是个隐患"
---
# From modern Chinese to Ancient Chinese
> 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
> 从现代文到文言文的翻译器, 训练语料是就是九十多万句句对, [数据集链接](https://github.com/BangBOOM/Classical-Chinese)
## 推荐的inference 通道
```python
from transformers import (
EncoderDecoderModel,
AutoTokenizer
)
PRETRAINED = "raynardj/wenyanwen-chinese-translate-to-ancient"
tokenizer = AutoTokenizer.from_pretrained(PRETRAINED)
model = EncoderDecoderModel.from_pretrained(PRETRAINED)
def inference(text):
tk_kwargs = dict(
truncation=True,
max_length=128,
padding="max_length",
return_tensors='pt')
inputs = tokenizer([text,],**tk_kwargs)
with torch.no_grad():
return tokenizer.batch_decode(
model.generate(
inputs.input_ids,
attention_mask=inputs.attention_mask,
num_beams=3,
bos_token_id=101,
eos_token_id=tokenizer.sep_token_id,
pad_token_id=tokenizer.pad_token_id,
), skip_special_tokens=True)
```
## 目前版本的案例
```python
>>> inference('你连一百块都不肯给我')
['不 肯 与 我 百 钱 。']
```
```python
>>> inference("他不能做长远的谋划")
['不 能 为 远 谋 。']
```
```python
>>> inference("我们要干一番大事业")
['吾 属 当 举 大 事 。']
```
```python
>>> inference("这感觉,已经不对,我努力,在挽回")
['此 之 谓 也 , 已 不 可 矣 , 我 勉 之 , 以 回 之 。']
```
```python
>>> inference("轻轻地我走了, 正如我轻轻地来, 我挥一挥衣袖,不带走一片云彩")
['轻 我 行 , 如 我 轻 来 , 挥 袂 不 携 一 片 云 。']
```
|