aixsatoshi commited on
Commit
c8a5f4c
1 Parent(s): 1e73023

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +34 -0
README.md CHANGED
@@ -115,6 +115,40 @@ demo = gr.ChatInterface(
115
  demo.queue().launch()
116
  ```
117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  # Base Model
119
  [tokyotech-llm/Swallow-MS-7b-v0.1](https://huggingface.co/tokyotech-llm/Swallow-MS-7b-v0.1)
120
 
 
115
  demo.queue().launch()
116
  ```
117
 
118
+ ### Textstreamer
119
+ ```
120
+ import torch
121
+ from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
122
+
123
+ model_name = "aixsatoshi/Honyaku-7b-v2"
124
+ model = AutoModelForCausalLM.from_pretrained(
125
+ model_name,
126
+ torch_dtype=torch.bfloat16,
127
+ device_map="auto",
128
+ )
129
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
130
+
131
+ # Define the streamer
132
+ streamer = TextStreamer(tokenizer)
133
+
134
+ # Define the English prompt
135
+ english_prompt = """
136
+ Machine translation accuracy varies greatly across languages.
137
+ Key challenges include context understanding, idiomatic expressions, and syntactic differences.
138
+ Advanced models leverage AI to enhance translation quality, focusing on nuances and cultural relevance.
139
+ Continuous updates and training on diverse datasets are essential for improving accuracy and expanding language support, making global communication more accessible and effective.
140
+ """
141
+
142
+ # Prepare the prompt for English to Japanese translation
143
+ prompt = f"<english>: {english_prompt} </english>\n\n<japanese>:"
144
+
145
+ # Tokenize the input text and move to CUDA device
146
+ inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
147
+
148
+ # Generate the output using the model and streamer
149
+ output = model.generate(**inputs, max_new_tokens=4096, do_sample=True, top_k=20, top_p=0.95, streamer=streamer)
150
+ ```
151
+
152
  # Base Model
153
  [tokyotech-llm/Swallow-MS-7b-v0.1](https://huggingface.co/tokyotech-llm/Swallow-MS-7b-v0.1)
154