aixsatoshi commited on
Commit
0d9ba8e
1 Parent(s): 29e28cc

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +105 -3
README.md CHANGED
@@ -1,3 +1,105 @@
1
- ---
2
- license: llama2
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: llama2
3
+ ---
4
+
5
+ ### Description
6
+
7
+ This is a translation model utilizing the high Japanese proficiency of Swallow-hf-13b, primarily focused on English-Japanese or any language-to-Japanese translation.
8
+
9
+ The model, tokyotech-llm/Swallow-13b-hf, has been fine-tuned with an 8K context and is mainly aimed at translating relatively long texts ranging from 100 to several thousand tokens.
10
+
11
+ While its core strength lies in English-Japanese translation, it also partially supports translation in multiple other languages.
12
+ (Multilingual translation features and long context translation become unstable when quantized.)
13
+
14
+
15
+ ### Prompt
16
+
17
+ An XML-like instruction template has been adopted.
18
+
19
+ ---
20
+ ### 概要
21
+ Swallow-hf-13bの高い日本語力を利用した翻訳モデルです
22
+ [tokyotech-llm/Swallow-hf-13b](https://huggingface.co/tokyotech-llm/Swallow-13b-hf)
23
+
24
+ 英日翻訳メインに、ファインチューニングしています
25
+ 数千tokenまでの翻訳に対応しています
26
+
27
+ 多言語から日本語への翻訳も一部対応しています(多言語翻訳機能や長文翻訳は量子化するとさらに不安定です)
28
+
29
+ ### プロンプト
30
+ XML likeなタグによるinstructionフォーマットを採用しました
31
+ - 利点
32
+ - Instructionのtoken消費少ない
33
+ - モデルの指示理解がよい
34
+ - 欠点
35
+ - タグ付きテキスト処理に弱い
36
+
37
+ ## Usage
38
+ ### Prompt format:English to Japanese
39
+ ```
40
+
41
+ <english>: {} <NL>
42
+
43
+ <japanese>: {} <NL>
44
+
45
+
46
+ ```
47
+
48
+ ### Prompt format:Other language to Japanese
49
+ ```
50
+
51
+ <english>: {} <NL>
52
+
53
+ <japanese>: {} <NL>
54
+
55
+
56
+ ```
57
+
58
+ ### Prompt format:Japanese to English
59
+ ```
60
+
61
+ not supported
62
+
63
+
64
+ ```
65
+
66
+ 長文の場合、Textstreamerの使用をお勧めします
67
+ ```
68
+ import torch
69
+ from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
70
+
71
+ model_name = "aixsatoshi/Honyaku-13b"
72
+ model = AutoModelForCausalLM.from_pretrained(
73
+ model_name,
74
+ torch_dtype=torch.bfloat16,
75
+ device_map="auto",
76
+ )
77
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
78
+
79
+ # Define the streamer
80
+ streamer = TextStreamer(tokenizer)
81
+
82
+ # Define the English prompt
83
+ english_prompt = """
84
+ In an era marked by rapid globalization, the intricate interplay between international law, economic policies, and political dynamics has become increasingly complex.
85
+ Legal frameworks, once confined within national borders, now stretch across continents, necessitating a nuanced understanding of transnational legislation and treaties.
86
+ As multinational corporations navigate the labyrinthine maze of global markets, economic theories that underpin currency fluctuations, trade imbalances, and fiscal policies are more pertinent than ever.
87
+ Central to these economic considerations is the concept of market equilibrium, a delicate balance affected by myriad factors including consumer behavior, governmental regulations, and global crises.
88
+ Politically, the landscape is equally labyrinthine. Ideological shifts and the resurgence of nationalism have reshaped diplomatic relations, with international agreements and alliances being tested under the strain of geopolitical tensions.
89
+ The role of supranational entities like the United Nations and the European Union in mediating these conflicts is of paramount importance, as is the need for diplomatic finesse in an increasingly multipolar world.
90
+ Furthermore, the intersection of politics and economics is evident in the debate over economic sanctions and their efficacy in swaying political decisions.
91
+ In this context, understanding the subtleties of rhetoric used in political discourse, and how it interweaves with legal jargon and economic terminology, is crucial.
92
+ For instance, the rhetoric surrounding fiscal austerity measures often intertwines with legal discourse on budgetary legislation and economic debates on inflation control.
93
+ Similarly, discussions on constitutional amendments are frequently laden with political undertones, reflecting broader societal issues and ideological divides.
94
+ This convergence of legal, economic, and political vernacular presents a unique challenge for machine translation systems, demanding not only linguistic accuracy but also a deep comprehension of the nuanced interplay of these disciplines.
95
+ """
96
+
97
+ # Prepare the prompt for English to Japanese translation
98
+ prompt = f"<english>: {english_prompt} <NL>\n\n<japanese>:"
99
+
100
+ # Tokenize the input text and move to CUDA device
101
+ inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
102
+
103
+ # Generate the output using the model and streamer
104
+ output = model.generate(**inputs, max_new_tokens=4096, do_sample=True, top_k=20, top_p=0.95, streamer=streamer)
105
+ ```