-
Notifications
You must be signed in to change notification settings - Fork 13
/
Ling.py
38 lines (25 loc) · 729 Bytes
/
Ling.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import numpy as np
from keras.preprocessing.sequence import pad_sequences
import pickle
tokenizer=pickle.load(open('tokenizer.pkl','rb+'))
from keras.models import load_model
model=load_model(open('model.h5','rb+'))
def inp(name):
q=tokenizer.texts_to_sequences(name)
q=[i[0] for i in q]
q1=[]
q1.append(q)
s=pad_sequences(q1,maxlen=15,padding='post')
return s
def decoder(ans):
decode=np.argmax(ans,axis=1)[0]
return decode
def gender(name):
sequences=inp(name)
predict=model.predict(sequences)
result=decoder(predict)
if result==1:
print(name," is a male")
if result==0:
print(name," is a female")
return result