mzbac commited on
Commit
26a91f3
·
verified ·
1 Parent(s): 043decf

Create README.md

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