pkedzia commited on
Commit
12a313d
·
verified ·
1 Parent(s): a7121f3

Update README.md

Browse files

Added sample python usage

Files changed (1) hide show
  1. README.md +29 -0
README.md CHANGED
@@ -20,3 +20,32 @@ Eval loss:
20
 
21
  ![image/png](https://cdn-uploads.huggingface.co/production/uploads/644addfe9279988e0cbc296b/HIJI2a1nojM6lbDyYe0-A.png)
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  ![image/png](https://cdn-uploads.huggingface.co/production/uploads/644addfe9279988e0cbc296b/HIJI2a1nojM6lbDyYe0-A.png)
22
 
23
+
24
+ **Sample model usage**
25
+ ```[python]
26
+ from transformers import T5ForConditionalGeneration, T5Tokenizer
27
+
28
+ model = T5ForConditionalGeneration.from_pretrained(model_path)
29
+ tokenizer = T5Tokenizer.from_pretrained(model_path)
30
+
31
+ def do_inference(text, model, tokenizer):
32
+ input_text = f"denoise: {text}"
33
+ inputs = tokenizer.encode(
34
+ input_text,
35
+ return_tensors="pt",
36
+ max_length=256,
37
+ padding="max_length",
38
+ truncation=True,
39
+ )
40
+
41
+ corrected_ids = model.generate(
42
+ inputs,
43
+ max_length=256,
44
+ num_beams=5,
45
+ early_stopping=True,
46
+ )
47
+
48
+ corrected_sentence = tokenizer.decode(corrected_ids[0], skip_special_tokens=True)
49
+ return corrected_sentence
50
+ ```
51
+