Update README.md
Browse files
README.md
CHANGED
|
@@ -18,4 +18,48 @@ pipeline_tag: translation
|
|
| 18 |
|
| 19 |
This is the finetuned version of [google/mt5-large](https://huggingface.co/google/mt5-large) for translating Japanese into Simplified Chinese.
|
| 20 |
|
| 21 |
-
Trained for 1 epoch on 5680000 samples from [CCMatrix-v1-Ja_Zh-filtered](https://huggingface.co/datasets/larryvrh/CCMatrix-v1-Ja_Zh-filtered) and 690095 samples from [WikiMatrix-v1-Ja_Zh-filtered](https://huggingface.co/datasets/larryvrh/WikiMatrix-v1-Ja_Zh-filtered).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
This is the finetuned version of [google/mt5-large](https://huggingface.co/google/mt5-large) for translating Japanese into Simplified Chinese.
|
| 20 |
|
| 21 |
+
Trained for 1 epoch on 5680000 samples from [CCMatrix-v1-Ja_Zh-filtered](https://huggingface.co/datasets/larryvrh/CCMatrix-v1-Ja_Zh-filtered) and 690095 samples from [WikiMatrix-v1-Ja_Zh-filtered](https://huggingface.co/datasets/larryvrh/WikiMatrix-v1-Ja_Zh-filtered).
|
| 22 |
+
|
| 23 |
+
This model is trained on sentence pairs with max seq_len=128, therefore you need to break document into small sentences before inference in order to avoid performance degradation.
|
| 24 |
+
|
| 25 |
+
---
|
| 26 |
+
|
| 27 |
+
Demo Usage
|
| 28 |
+
|
| 29 |
+
```python
|
| 30 |
+
from transformers import pipeline
|
| 31 |
+
import re
|
| 32 |
+
|
| 33 |
+
pipe = pipeline(model="larryvrh/mt5-translation-ja_zh")
|
| 34 |
+
|
| 35 |
+
def translate_sentence(sentence):
|
| 36 |
+
return pipe(f'<-ja2zh-> {sentence}')[0]['translation_text']
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def translate_paragraph(paragraph):
|
| 40 |
+
sentences = []
|
| 41 |
+
cursor = 0
|
| 42 |
+
for i, c in enumerate(paragraph):
|
| 43 |
+
if c == '。':
|
| 44 |
+
sentences.append(paragraph[cursor:i + 1])
|
| 45 |
+
cursor = i + 1
|
| 46 |
+
if paragraph[-1] != '。':
|
| 47 |
+
sentences.append(paragraph[cursor:])
|
| 48 |
+
return ''.join(translate_sentence(s) for s in sentences)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def translate_article(article):
|
| 52 |
+
paragraphs = re.split(r'([\r\n]+)', article)
|
| 53 |
+
for i, p in enumerate(paragraphs):
|
| 54 |
+
if len(p.strip()) == 0:
|
| 55 |
+
continue
|
| 56 |
+
paragraphs[i] = translate_paragraph(p)
|
| 57 |
+
return ''.join(paragraphs)
|
| 58 |
+
|
| 59 |
+
article = '''文は、「主語・修飾語・述語」の語順で構成される。修飾語は被修飾語の前に位置する。また、名詞の格を示すためには、語順や語尾を変化させるのでなく、文法的な機能を示す機能語(助詞)を後ろに付け加える(膠着させる)。これらのことから、言語類型論上は、語順の点ではSOV型の言語に、形態の点では膠着語に分類される(「文法」の節参照)。
|
| 60 |
+
|
| 61 |
+
語彙は、古来の大和言葉(和語)のほか、漢語(字音語)、外来語、および、それらの混ざった混種語に分けられる。字音語(漢字の音読みに由来する語の意、一般に「漢語」と称する)は現代の語彙の一部分を占めている。また、「絵/画(ゑ)」など、もともと音であるが和語と認識されているものもある。さらに近代以降には西洋由来の語を中心とする外来語が増大している(「語種」の節参照)。'''
|
| 62 |
+
|
| 63 |
+
print(translate_article(article))
|
| 64 |
+
|
| 65 |
+
```
|