Views
No views yet

1import torch
2from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
4model_path = "protonx-models/nano-protonx-legal-tc"
5
6tokenizer = AutoTokenizer.from_pretrained(model_path)
7model = AutoModelForSeq2SeqLM.from_pretrained(model_path)
8
9device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
10model.to(device)
11model.eval()
12
13examples = [
14 "can cu bo luat lao dong 2019 va cac van ban huong dan thuc hien.",
15]
16
17for text in examples:
18 inputs = tokenizer(
19 text,
20 return_tensors="pt",
21 truncation=True,
22 max_length=160
23 ).to(device)
24
25 with torch.no_grad():
26 outputs = model.generate(
27 **inputs,
28 num_beams=10,
29 max_new_tokens=160,
30 length_penalty=1.0,
31 early_stopping=True,
32 pad_token_id=tokenizer.pad_token_id,
33 eos_token_id=tokenizer.eos_token_id,
34 )
35
36 result = tokenizer.decode(outputs[0], skip_special_tokens=True)
37
38 print(f"Input: {text}")
39 print(f"Output: {result}")
40 print("-" * 30)| Metric | Score |
|---|---|
| ROUGE-L | 96.53 |
2.Trong Lut này các tù ng dui day dugc hiéu nhur sau2. Trong Luật này các từ ngữ dưới đây được hiểu như sau