mzbac commited on
Commit
9e91736
·
verified ·
1 Parent(s): 089f0ad

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +40 -0
README.md ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ```
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+ import torch
4
+
5
+ model_id = "mzbac/gemma-2-9b-grammar-correction"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
7
+ model = AutoModelForCausalLM.from_pretrained(
8
+ model_id,
9
+ torch_dtype=torch.bfloat16,
10
+ device_map="auto",
11
+ )
12
+
13
+ messages = [
14
+ {
15
+ "role": "user",
16
+ "content": "Please correct, polish, or translate the text delimited by triple backticks to standard English\nText=```neither 经理或员工 has been informed about the meeting```",
17
+ },
18
+ ]
19
+ input_ids = tokenizer.apply_chat_template(
20
+ messages, add_generation_prompt=True, return_tensors="pt"
21
+ ).to(model.device)
22
+
23
+ terminators = [tokenizer.eos_token_id, tokenizer.convert_tokens_to_ids("<|im_end|>")]
24
+
25
+ outputs = model.generate(
26
+ input_ids,
27
+ max_new_tokens=256,
28
+ eos_token_id=terminators,
29
+ do_sample=True,
30
+ temperature=0.1,
31
+ )
32
+ response = outputs[0]
33
+ print(tokenizer.decode(response))
34
+
35
+ # <bos><start_of_turn>user
36
+ # Please correct, polish, or translate the text delimited by triple backticks to standard English
37
+ # Text=```neither 经理或员工 has been informed about the meeting```<end_of_turn>
38
+ # <start_of_turn>model
39
+ # Output=Neither the manager nor the employees have been informed about the meeting.<end_of_turn>
40
+ # <eos>