You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
864 B

1 week ago
import numpy as np
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.sequence import pad_sequences
import pickle
# Load the tokenizer and model
with open('tokenizer.pkl', 'rb') as handle:
tokenizer = pickle.load(handle)
model = load_model('word_classifier_model.keras')
def classify_word(word):
# Tokenize and pad the input word
sequence = tokenizer.texts_to_sequences([word])
padded_sequence = pad_sequences(sequence, maxlen=1)
# Predict using the model
prediction = model.predict(padded_sequence)
#return 1 if prediction >= 0.5 else 0
#return 1 if prediction >= 0.4 else 0
return f'{round(prediction[0][0]*100,3)}%'
while True:
word = input('>> ')
if word == 'exit':
break
result = classify_word(word)
print(f"The word '{word}' is a: {result}")