DHRUV SHEKHAWAT commited on
Commit
15985e2
·
1 Parent(s): e5c8275

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -44,12 +44,12 @@ class TransformerChatbot(Model):
44
  st.title("UniGLM TEXT completion Model")
45
  st.subheader("Next Word Prediction AI Model by Webraft-AI")
46
  #Picking what NLP task you want to do
47
- option = st.selectbox('Model',('1','2')) #option is stored in this variable
48
  #Textbox for text user is entering
49
  st.subheader("Enter a word from which a sentence / word would be predicted")
50
  text2 = st.text_input('Enter word: ') #text is stored in this variable
51
 
52
- if option == '1':
53
  with open("data2.txt","r") as f:
54
  text = f.read()
55
  text = text.lower()
@@ -74,13 +74,25 @@ if option == '1':
74
  chatbot.build(input_shape=(None, max_len)) # Build the model
75
  chatbot.compile(optimizer="adam", loss="sparse_categorical_crossentropy")
76
 
 
 
 
 
 
77
  given_X1 = other_num1
78
  input_sequence1 = pad_sequences([given_X1], maxlen=max_len, padding='post')
79
- output_sentence = ""
80
- for _ in range(1):
81
  predicted_token = np.argmax(chatbot.predict(input_sequence1), axis=-1)
82
  predicted_token = predicted_token.item()
83
  out = num_to_word[predicted_token]
 
 
 
 
 
 
 
84
  input_sequence1 = pad_sequences([given_X1], maxlen=max_len, padding='post')
85
 
86
  out2 = output_sentence
@@ -91,7 +103,7 @@ else:
91
  text = f.read()
92
  text = text.lower()
93
  words = text.split()
94
- loaded_dict = np.load("dict_predict3.bin.npz", allow_pickle=True)
95
  word_to_num = loaded_dict["word_to_num"].item()
96
  num_to_word = loaded_dict["num_to_word"].item()
97
  X = []
@@ -108,14 +120,14 @@ else:
108
  y_train = pad_sequences([Y])
109
  vocab_size = 100000
110
  max_len = 1
111
- d_model = 64 # 64 , 1024
112
  n_head = 4 # 8 , 16
113
  ff_dim = 256 # 256 , 2048
114
  dropout_rate = 0.1 # 0.5 , 0.2
115
 
116
 
117
  chatbot = TransformerChatbot(vocab_size, max_len, d_model, n_head, ff_dim, dropout_rate)
118
- chatbot.load_weights("predict3")
119
  chatbot.build(input_shape=(None, max_len)) # Build the model
120
  chatbot.compile(optimizer="adam", loss="sparse_categorical_crossentropy")
121
 
 
44
  st.title("UniGLM TEXT completion Model")
45
  st.subheader("Next Word Prediction AI Model by Webraft-AI")
46
  #Picking what NLP task you want to do
47
+ option = st.selectbox('Model',('13M','26M')) #option is stored in this variable
48
  #Textbox for text user is entering
49
  st.subheader("Enter a word from which a sentence / word would be predicted")
50
  text2 = st.text_input('Enter word: ') #text is stored in this variable
51
 
52
+ if option == '13M':
53
  with open("data2.txt","r") as f:
54
  text = f.read()
55
  text = text.lower()
 
74
  chatbot.build(input_shape=(None, max_len)) # Build the model
75
  chatbot.compile(optimizer="adam", loss="sparse_categorical_crossentropy")
76
 
77
+ for i in range(1):
78
+ other_text1 = text2
79
+ other_text1 = other_text1.lower()
80
+ other_words1 = other_text1.split()
81
+ other_num1 = [word_to_num[word] for word in other_words1]
82
  given_X1 = other_num1
83
  input_sequence1 = pad_sequences([given_X1], maxlen=max_len, padding='post')
84
+ output_sentence = other_text1+""
85
+ for _ in range(10):
86
  predicted_token = np.argmax(chatbot.predict(input_sequence1), axis=-1)
87
  predicted_token = predicted_token.item()
88
  out = num_to_word[predicted_token]
89
+
90
+
91
+ output_sentence += " " + out
92
+ if out == ".":
93
+ break
94
+ given_X1 = given_X1[1:]
95
+ given_X1.append(predicted_token)
96
  input_sequence1 = pad_sequences([given_X1], maxlen=max_len, padding='post')
97
 
98
  out2 = output_sentence
 
103
  text = f.read()
104
  text = text.lower()
105
  words = text.split()
106
+ loaded_dict = np.load("dict_predict1.bin.npz", allow_pickle=True)
107
  word_to_num = loaded_dict["word_to_num"].item()
108
  num_to_word = loaded_dict["num_to_word"].item()
109
  X = []
 
120
  y_train = pad_sequences([Y])
121
  vocab_size = 100000
122
  max_len = 1
123
+ d_model = 128 # 64 , 1024
124
  n_head = 4 # 8 , 16
125
  ff_dim = 256 # 256 , 2048
126
  dropout_rate = 0.1 # 0.5 , 0.2
127
 
128
 
129
  chatbot = TransformerChatbot(vocab_size, max_len, d_model, n_head, ff_dim, dropout_rate)
130
+ chatbot.load_weights("predict1")
131
  chatbot.build(input_shape=(None, max_len)) # Build the model
132
  chatbot.compile(optimizer="adam", loss="sparse_categorical_crossentropy")
133