Update README.md
Browse files
README.md
CHANGED
@@ -6,7 +6,123 @@ base_model:
|
|
6 |
- google/gemma-2-2b-jpn-it
|
7 |
---
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
```
|
10 |
pip install -U transformers
|
11 |
pip install requests
|
12 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
- google/gemma-2-2b-jpn-it
|
7 |
---
|
8 |
|
9 |
+
## Model Card for gemma-2-2b-jpn-it-translate-gguf
|
10 |
+
|
11 |
+
gemma-2-2b-jpn-it-translate-ggufは、日英・英日翻訳タスクに特化したSLM(Small Language Model)です。パラメーター数は20億(2B)ですが、従来の70億(7B)モデルに迫るレベルの翻訳品質を提供します。ファイルサイズが約5GBと比較的小さいため、高速な実行が可能です。
|
12 |
+
gemma-2-2b-jpn-it-translate-gguf is an SLM (Small Language Model) specialized for Japanese-English and English-Japanese translation tasks. Despite having only 2 billion parameters (2B), it provides translation quality approaching that of conventional 7 billion (7B) parameter models. With a relatively small file size of about 5GB, it enables fast execution.
|
13 |
+
|
14 |
+
|
15 |
+
ドキュメントは今後、より詳しく書かれます
|
16 |
+
The documentation will be more detailed in the future.
|
17 |
+
|
18 |
+
### sample for windows
|
19 |
+
```
|
20 |
+
.\llama.cpp\build\bin\Release\llama-server -m .\gemma-2-2b-jpn-it-translate-IQ4_XS.gguf -c 2048
|
21 |
+
```
|
22 |
+
|
23 |
```
|
24 |
pip install -U transformers
|
25 |
pip install requests
|
26 |
```
|
27 |
+
|
28 |
+
```
|
29 |
+
import transformers
|
30 |
+
import requests
|
31 |
+
import json
|
32 |
+
from transformers import AutoTokenizer
|
33 |
+
|
34 |
+
system_prompt = "You are a highly skilled professional Japanese-English and English-Japanese translator. Translate the given text accurately, taking into account the context and specific instructions provided. Steps may include hints enclosed in square brackets [] with the key and value separated by a colon:. Only when the subject is specified in the Japanese sentence, the subject will be added when translating into English. If no additional instructions or context are provided, use your expertise to consider what the most appropriate context is and provide a natural translation that aligns with that context. When translating, strive to faithfully reflect the meaning and tone of the original text, pay attention to cultural nuances and differences in language usage, and ensure that the translation is grammatically correct and easy to read. After completing the translation, review it once more to check for errors or unnatural expressions. For technical terms and proper nouns, either leave them in the original language or use appropriate translations as necessary. Take a deep breath, calm down, and start translating.\n\n"
|
35 |
+
instruct = "Translate Japanese to English.\nWhen translating, please use the following hints:\n[writing_style: casual]"
|
36 |
+
|
37 |
+
initial_messages = [
|
38 |
+
{"role": "user", "content": system_prompt + instruct},
|
39 |
+
{"role": "assistant", "content": "OK"}
|
40 |
+
]
|
41 |
+
|
42 |
+
message_list = [
|
43 |
+
"and I was a little bit nervous, too, speaking to a Japanese audience really for the first time, certainly since I left the White House. ",
|
44 |
+
"And I had a very good interpreter, and if you have ever made a speech in Japan in English, it takes a lot longer to say it in Japanese. ",
|
45 |
+
"I decided I would break the ice by telling the shortest joke that I knew.",
|
46 |
+
"It was not the best joke I knew, but it was the shortest joke I knew, left over from my governor's campaign years before.",
|
47 |
+
"So I told my joke, the interpreter told the joke, and the audience just collapsed in laughter. ",
|
48 |
+
"I never got a better response from any audience in my life. ",
|
49 |
+
"So I could not wait to get through the speech and talk to the interpreter and ask him,"
|
50 |
+
"\"How did you tell my joke?\"",
|
51 |
+
"He was very evasive. He would not tell me how he told it.",
|
52 |
+
"I insisted, and he finally ducked his head and said,",
|
53 |
+
"\"I told the audience, 'President Carter told a funny story. Everybody, laugh.'\""
|
54 |
+
]
|
55 |
+
|
56 |
+
tokenizer = AutoTokenizer.from_pretrained("webbigdata/gemma-2-2b-jpn-it-translate")
|
57 |
+
|
58 |
+
if __name__ == "__main__":
|
59 |
+
messages = initial_messages.copy()
|
60 |
+
for i in range(len(message_list)):
|
61 |
+
messages.append({"role": "user", "content": message_list[i]})
|
62 |
+
print("user: " + message_list[i])
|
63 |
+
|
64 |
+
prompt = tokenizer.apply_chat_template(
|
65 |
+
messages,
|
66 |
+
add_generation_prompt=True,
|
67 |
+
tokenize=False
|
68 |
+
)
|
69 |
+
|
70 |
+
payload = {
|
71 |
+
"prompt": prompt,
|
72 |
+
"n_predict": 1200
|
73 |
+
}
|
74 |
+
|
75 |
+
# Define the URL and headers for the POST request
|
76 |
+
url = "http://localhost:8080/completion"
|
77 |
+
headers = {
|
78 |
+
"Content-Type": "application/json"
|
79 |
+
}
|
80 |
+
|
81 |
+
# Send the POST request and capture the response
|
82 |
+
response = requests.post(url, headers=headers, data=json.dumps(payload))
|
83 |
+
# print(response)
|
84 |
+
# print( response.json() )
|
85 |
+
|
86 |
+
|
87 |
+
# Check if the request was successful
|
88 |
+
if response.status_code != 200:
|
89 |
+
print(f"Error: {response.text}")
|
90 |
+
|
91 |
+
# Parse the response JSON
|
92 |
+
response_data = response.json()
|
93 |
+
|
94 |
+
# Extract the 'content' field from the response
|
95 |
+
response_content = response_data.get('content', '').strip()
|
96 |
+
|
97 |
+
print("assistant: " + response_content)
|
98 |
+
messages.append({"role": "assistant", "content": response_content})
|
99 |
+
|
100 |
+
# Max 6 message, you need more memory for more massages.
|
101 |
+
if len(messages) > 8: # 2 (initial) + 6 (new) = 8
|
102 |
+
messages = initial_messages + messages[-6:]
|
103 |
+
```
|
104 |
+
|
105 |
+
|
106 |
+
result
|
107 |
+
```
|
108 |
+
user: and I was a little bit nervous, too, speaking to a Japanese audience really for the first time, certainly since I left the White House.
|
109 |
+
assistant: そして、私が、ホワイトハウスを去ってから、初めての日本の方々に向けて話すことにも、少し緊張していました。
|
110 |
+
user: And I had a very good interpreter, and if you have ever made a speech in Japan in English, it takes a lot longer to say it in Japanese.
|
111 |
+
assistant: そして、私はとても良い通訳者でしたが、日本語で英語で話したことは、英語で話した時よりはるかに時間がかかります 。
|
112 |
+
user: I decided I would break the ice by telling the shortest joke that I knew.
|
113 |
+
assistant: 私が、一番短いジョークを話せば、会話の糸口を切り開くことができるだろうと決意しました。
|
114 |
+
user: It was not the best joke I knew, but it was the shortest joke I knew, left over from my governor's campaign years before.
|
115 |
+
assistant: 一番いいジョークではないかもしれませんでしたが、私の総選挙時の残り物である、最短ジョークでした。
|
116 |
+
user: So I told my joke, the interpreter told the joke, and the audience just collapsed in laughter.
|
117 |
+
assistant: 私はジョークを話した、通訳者もジョークを話すと、聴衆はただただ笑いとりました。
|
118 |
+
user: I never got a better response from any audience in my life.
|
119 |
+
assistant: 私の生涯で、これ以上いい反応は受けませんでした。
|
120 |
+
user: So I could not wait to get through the speech and talk to the interpreter and ask him,"How did you tell my joke?"
|
121 |
+
assistant: そうして、短い間にスピーチを終えて、通訳者と会話して、彼に尋ねてみたいと思いました、「私のジョークはどうやっ て話したのか?」
|
122 |
+
user: He was very evasive. He would not tell me how he told it.
|
123 |
+
assistant: 通訳者は非常に曖昧でした。どう言えたか聞きたいのに、話さないのです。
|
124 |
+
user: I insisted, and he finally ducked his head and said,
|
125 |
+
assistant: 私は強く言いました、そして彼はついに首をすくって言いました。
|
126 |
+
user: "I told the audience, 'President Carter told a funny story. Everybody, laugh.'"
|
127 |
+
assistant: 「私が台本に書いてある、カールが面白い話をした。みんな、笑わせる」
|
128 |
+
```
|