mzbac commited on
Commit
8e80803
1 Parent(s): fa4cf3e

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +60 -0
README.md ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: llama3
3
+ ---
4
+
5
+ # Model
6
+
7
+ fine-tuned LLaMA 3 8B on synthetic dataset generated by GPT-4 and LLaMA 3 70B via MLX-LM
8
+
9
+ ## Usage
10
+
11
+ ```python
12
+ from transformers import AutoTokenizer, AutoModelForCausalLM
13
+ import torch
14
+
15
+ model_id = "mzbac/llama-3-8B-grammar-hf"
16
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
17
+ model = AutoModelForCausalLM.from_pretrained(
18
+ model_id,
19
+ torch_dtype=torch.bfloat16,
20
+ device_map="auto",
21
+
22
+ )
23
+
24
+ messages = [
25
+ {
26
+ "role": "system",
27
+ "content": "Please correct, polish, or translate the text to standard English.",
28
+ },
29
+ ]
30
+ messages.append({"role": "user", "content":"Text=```neither 经理或员工 has been informed about the meeting```"})
31
+
32
+ input_ids = tokenizer.apply_chat_template(
33
+ messages,
34
+ add_generation_prompt=True,
35
+ return_tensors="pt"
36
+ ).to(model.device)
37
+
38
+ terminators = [
39
+ tokenizer.eos_token_id,
40
+ tokenizer.convert_tokens_to_ids("<|eot_id|>")
41
+ ]
42
+
43
+ outputs = model.generate(
44
+ input_ids,
45
+ max_new_tokens=256,
46
+ eos_token_id=terminators,
47
+ do_sample=True,
48
+ temperature=0.1,
49
+ )
50
+ response = outputs[0]
51
+ print(tokenizer.decode(response))
52
+
53
+ # <|begin_of_text|><|start_header_id|>system<|end_header_id|>
54
+
55
+ # Please correct, polish, or translate the text to standard English.<|eot_id|><|start_header_id|>user<|end_header_id|>
56
+
57
+ # Text=```neither 经理或员工 has been informed about the meeting```<|eot_id|><|start_header_id|>assistant<|end_header_id|>
58
+
59
+ # Output=Neither the manager nor the employees have been informed about the meeting.<|eot_id|>
60
+ ```