aixsatoshi commited on
Commit
929c30d
1 Parent(s): f617303

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +31 -0
README.md CHANGED
@@ -53,6 +53,37 @@ XML likeなinstructionテンプレートを採用しました
53
 
54
  ```
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  ### Multi Language
57
 
58
  TAG work in English-to-Japanese
 
53
 
54
  ```
55
 
56
+ ```
57
+ from transformers import AutoModelForCausalLM, AutoTokenizer
58
+
59
+ # Initialize the model and tokenizer
60
+ device = "cuda" # the device to load the model onto
61
+ model_name = "aixsatoshi/Honyaku-Multi-Translator-Swallow-ms7b"
62
+ model = AutoModelForCausalLM.from_pretrained(model_name).to(device)
63
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
64
+
65
+ # Define the English prompt
66
+ english_prompt = "What is your favourite condiment?"
67
+
68
+ # Prepare the prompt for English to Japanese translation
69
+ english_to_japanese_prompt = f"""
70
+ <english>: {english_prompt} </english>
71
+
72
+ <japanese>:
73
+ """
74
+
75
+ # Encode the prompt
76
+ encoded_prompt = tokenizer(english_to_japanese_prompt, return_tensors="pt", padding=True).to(device)
77
+
78
+ # Generate a response
79
+ generated_ids = model.generate(**encoded_prompt, max_length=4096, do_sample=True)
80
+
81
+ # Decode and print the response
82
+ decoded_translation = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
83
+ print("English to Japanese Translation:")
84
+ print(decoded_translation)
85
+ ```
86
+
87
  ### Multi Language
88
 
89
  TAG work in English-to-Japanese