Views
No views yet
denoise: F.e. if you have text:As | -Tron^# om ia je@st je!d &*ną z na -J s | AA ta rsZy ch n a u k.denoise: As | -Tron^# om ia je@st je!d &*ną z na -J s | AA ta rsZy ch n a u k.1from transformers import T5ForConditionalGeneration, T5Tokenizer
2
3
4def do_inference(text, model, tokenizer):
5 input_text = f"denoise: {text}"
6 inputs = tokenizer.encode(
7 input_text,
8 return_tensors="pt",
9 max_length=256,
10 padding="max_length",
11 truncation=True,
12 )
13
14 corrected_ids = model.generate(
15 inputs,
16 max_length=256,
17 num_beams=5,
18 early_stopping=True,
19 )
20
21 corrected_sentence = tokenizer.decode(corrected_ids[0], skip_special_tokens=True)
22 return corrected_sentence
23
24
25model = T5ForConditionalGeneration.from_pretrained("radlab/polish-denoiser-t5-base")
26tokenizer = T5Tokenizer.from_pretrained("radlab/polish-denoiser-t5-base")
27
28text_str = "As | -Tron^# om ia je@st je!d &*ną z na -J s | AA ta rsZy ch n a u k."
29print(do_inference(text_str, model, tokenizer))
30denoise: As | -Tron^# om ia je@st je!d &*ną z na -J s | AA ta rsZy ch n a u k.Astronomia jest jedną z najstarszych nauk.