File size: 1,592 Bytes
8e80803
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
419bd0f
8e80803
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c0fc551
8e80803
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
---
license: llama3
---

# Model

fine-tuned LLaMA 3 8B on synthetic dataset generated by GPT-4 and LLaMA 3 70B via MLX-LM

## Usage

```python
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

model_id = "mzbac/llama-3-8B-grammar-hf"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16,
    device_map="auto",
    
)

messages = [
    {
        "role": "system",
        "content": "Please correct, polish, or translate the text delimited by triple backticks to standard English.",
    },
]
messages.append({"role": "user", "content":"Text=```neither 经理或员工 has been informed about the meeting```"})

input_ids = tokenizer.apply_chat_template(
    messages,
    add_generation_prompt=True,
    return_tensors="pt"
).to(model.device)

terminators = [
    tokenizer.eos_token_id,
    tokenizer.convert_tokens_to_ids("<|eot_id|>")
]

outputs = model.generate(
    input_ids,
    max_new_tokens=256,
    eos_token_id=terminators,
    do_sample=True,
    temperature=0.1,
)
response = outputs[0]
print(tokenizer.decode(response))

# <|begin_of_text|><|start_header_id|>system<|end_header_id|>

# Please correct, polish, or translate the text delimited by triple backticks to standard English.<|eot_id|><|start_header_id|>user<|end_header_id|>

# Text=```neither 经理或员工 has been informed about the meeting```<|eot_id|><|start_header_id|>assistant<|end_header_id|>

# Output=Neither the manager nor the employees have been informed about the meeting.<|eot_id|>
```