CoolFace
Apppublic

sami606713/spelling-correction

sourceHugging Facemitupdated 2y agoView on Hugging Face
0likes
utils.py33 linesDownload Raw Back to root
1# Load the model and tokenizer2import torch3from transformers import T5Tokenizer, T5ForConditionalGeneration4import logging5logging.basicConfig(level=logging.INFO)6 7print(torch.__version__)8def load_tokenizer():9    try:10        tokenizer = T5Tokenizer.from_pretrained('Spelling_correction/tokenizer')11        return tokenizer12    except Exception as e:13        f"some error occur {e}"14        return None15 16def load_model():17    try:18        model = T5ForConditionalGeneration.from_pretrained('Spelling_correction/model')19 20        return model21    except Exception as e:22        f"Some error occur {e}"23        return None24def model_prediction(text):25    tokenizer=load_tokenizer()26    print(tokenizer)27    # input_ids = tokenizer.encode(text, return_tensors='pt') # Move input_ids to the GPU28    29    # model=load_model()30    # outputs = model.generate(input_ids, max_length=128)31    # corrected_text = tokenizer.decode(outputs[0], skip_special_tokens=True)32    return tokenizer33