noshot 0.1.7__py3-none-any.whl → 0.1.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. noshot/data/ML TS XAI/ML/1. PCA - EDA/PCA-EDA.ipynb +207 -0
  2. noshot/data/ML TS XAI/ML/1. PCA - EDA/balance-scale.csv +626 -0
  3. noshot/data/ML TS XAI/ML/1. PCA - EDA/input.txt +625 -0
  4. noshot/data/ML TS XAI/ML/2. KNN Classifier/KNN.ipynb +287 -0
  5. noshot/data/ML TS XAI/ML/2. KNN Classifier/balance-scale.csv +626 -0
  6. noshot/data/ML TS XAI/ML/2. KNN Classifier/input.txt +625 -0
  7. noshot/data/ML TS XAI/ML/3. Linear Discriminant Analysis/LDA.ipynb +83 -0
  8. noshot/data/ML TS XAI/ML/3. Linear Discriminant Analysis/balance-scale.csv +626 -0
  9. noshot/data/ML TS XAI/ML/3. Linear Discriminant Analysis/input.txt +625 -0
  10. noshot/data/ML TS XAI/ML/4. Linear Regression/Linear-Regression.ipynb +117 -0
  11. noshot/data/ML TS XAI/ML/4. Linear Regression/machine-data.csv +210 -0
  12. noshot/data/ML TS XAI/ML/5. Logistic Regression/Logistic-Regression.ipynb +137 -0
  13. noshot/data/ML TS XAI/ML/5. Logistic Regression/wine-dataset.csv +179 -0
  14. noshot/data/ML TS XAI/ML/6. Bayesian Classifier/Bayesian.ipynb +129 -0
  15. noshot/data/ML TS XAI/ML/6. Bayesian Classifier/wine-dataset.csv +179 -0
  16. noshot/data/ML TS XAI/TS/1. EDA - Handling Time Series Data/Handling TS Data.ipynb +784 -0
  17. noshot/data/ML TS XAI/TS/1. EDA - Handling Time Series Data/raw_sales.csv +29581 -0
  18. noshot/data/ML TS XAI/TS/2. Feature Engineering/Feature Engineering-.ipynb +1445 -0
  19. noshot/data/ML TS XAI/TS/3. Temporal Relationships/Exploring Temporal Relationships.ipynb +603 -0
  20. noshot/data/ML TS XAI/TS/4. Up-Down-Sampling and Interploation/Up-Down-Sampling.ipynb +721 -0
  21. noshot/data/ML TS XAI/TS/4. Up-Down-Sampling and Interploation/shampoo_sales.csv +37 -0
  22. noshot/data/ML TS XAI/TS/5. Stationarity - Trend - Seasonality/Stationarity-Trend-Seasonality.ipynb +392 -0
  23. noshot/data/ML TS XAI/TS/5. Stationarity - Trend - Seasonality/daily-min-temperatures.csv +3651 -0
  24. noshot/data/ML TS XAI/TS/5. Stationarity - Trend - Seasonality/daily-total-female-births.csv +366 -0
  25. noshot/data/ML TS XAI/TS/6. Autocorrelation - Partial Autocorrelation/ACF-PACF.ipynb +175 -0
  26. noshot/data/ML TS XAI/TS/6. Autocorrelation - Partial Autocorrelation/daily-min-temperatures.csv +3651 -0
  27. {noshot-0.1.7.dist-info → noshot-0.1.9.dist-info}/METADATA +2 -2
  28. noshot-0.1.9.dist-info/RECORD +35 -0
  29. noshot/data/ML TS XAI/AIDS/1. Implement Basic Search Strategies/(A) Breadth First Search.ipynb +0 -112
  30. noshot/data/ML TS XAI/AIDS/1. Implement Basic Search Strategies/(B) Depth First Search.ipynb +0 -111
  31. noshot/data/ML TS XAI/AIDS/1. Implement Basic Search Strategies/(C) Uniform Cost Search.ipynb +0 -134
  32. noshot/data/ML TS XAI/AIDS/1. Implement Basic Search Strategies/(D) Depth Limites Search.ipynb +0 -115
  33. noshot/data/ML TS XAI/AIDS/1. Implement Basic Search Strategies/(E) Iterative Deepening DFS.ipynb +0 -123
  34. noshot/data/ML TS XAI/AIDS/10. ANOVA/2_ANOVA.csv +0 -769
  35. noshot/data/ML TS XAI/AIDS/10. ANOVA/One Way ANOVA (Repeated Measure).ipynb +0 -126
  36. noshot/data/ML TS XAI/AIDS/10. ANOVA/One Way ANOVA.ipynb +0 -134
  37. noshot/data/ML TS XAI/AIDS/10. ANOVA/Sample 1 Way ANOVA Test.ipynb +0 -119
  38. noshot/data/ML TS XAI/AIDS/10. ANOVA/Two Way ANOVA.ipynb +0 -138
  39. noshot/data/ML TS XAI/AIDS/10. ANOVA/reaction_time.csv +0 -5
  40. noshot/data/ML TS XAI/AIDS/10. ANOVA/sample_data.csv +0 -16
  41. noshot/data/ML TS XAI/AIDS/10. ANOVA/sleep_deprivation.csv +0 -4
  42. noshot/data/ML TS XAI/AIDS/11. Linear Regression/3_Linear.csv +0 -4802
  43. noshot/data/ML TS XAI/AIDS/11. Linear Regression/Linear Regression LAB.ipynb +0 -113
  44. noshot/data/ML TS XAI/AIDS/11. Linear Regression/Linear Regression New- sklearn.ipynb +0 -118
  45. noshot/data/ML TS XAI/AIDS/11. Linear Regression/Linear Regression.ipynb +0 -148
  46. noshot/data/ML TS XAI/AIDS/11. Linear Regression/house_rate.csv +0 -22
  47. noshot/data/ML TS XAI/AIDS/12. Logistic Regression/Logistic Regression New- sklearn.ipynb +0 -128
  48. noshot/data/ML TS XAI/AIDS/12. Logistic Regression/Logistic Regression.ipynb +0 -145
  49. noshot/data/ML TS XAI/AIDS/12. Logistic Regression/default.csv +0 -1001
  50. noshot/data/ML TS XAI/AIDS/12. Logistic Regression/hours_scores_records.csv +0 -101
  51. noshot/data/ML TS XAI/AIDS/2. Implement A Star And MA Star/(A) Astar.ipynb +0 -256
  52. noshot/data/ML TS XAI/AIDS/2. Implement A Star And MA Star/(B) IDAstar.ipynb +0 -157
  53. noshot/data/ML TS XAI/AIDS/2. Implement A Star And MA Star/(C) SMAstar.ipynb +0 -178
  54. noshot/data/ML TS XAI/AIDS/3. Genetic Algorithm/Genetic.ipynb +0 -95
  55. noshot/data/ML TS XAI/AIDS/4. Simulated Annealing/Simulated Annealing.ipynb +0 -74
  56. noshot/data/ML TS XAI/AIDS/4. Simulated Annealing/Sudoku Simulated Annealing.ipynb +0 -103
  57. noshot/data/ML TS XAI/AIDS/5. Alpha Beta Pruning/AlphaBetaPruning.ipynb +0 -182
  58. noshot/data/ML TS XAI/AIDS/6. Consraint Satisfaction Problems (CSP)/(A) CSP House Allocation.ipynb +0 -120
  59. noshot/data/ML TS XAI/AIDS/6. Consraint Satisfaction Problems (CSP)/(B) CSP Map Coloring.ipynb +0 -125
  60. noshot/data/ML TS XAI/AIDS/7. Random Sampling/Random Sampling.ipynb +0 -73
  61. noshot/data/ML TS XAI/AIDS/7. Random Sampling/height_weight_bmi.csv +0 -8389
  62. noshot/data/ML TS XAI/AIDS/8. Z Test/Z Test Hash Function.ipynb +0 -141
  63. noshot/data/ML TS XAI/AIDS/8. Z Test/Z Test.ipynb +0 -151
  64. noshot/data/ML TS XAI/AIDS/8. Z Test/height_weight_bmi.csv +0 -8389
  65. noshot/data/ML TS XAI/AIDS/9. T Test/1_heart.csv +0 -304
  66. noshot/data/ML TS XAI/AIDS/9. T Test/Independent T Test.ipynb +0 -119
  67. noshot/data/ML TS XAI/AIDS/9. T Test/Paired T Test.ipynb +0 -118
  68. noshot/data/ML TS XAI/AIDS/9. T Test/T Test Hash Function.ipynb +0 -142
  69. noshot/data/ML TS XAI/AIDS/9. T Test/T Test.ipynb +0 -158
  70. noshot/data/ML TS XAI/AIDS/9. T Test/height_weight_bmi.csv +0 -8389
  71. noshot/data/ML TS XAI/AIDS/9. T Test/iq_test.csv +0 -0
  72. noshot/data/ML TS XAI/AIDS/Others (AllinOne)/All In One.ipynb +0 -4581
  73. noshot/data/ML TS XAI/CN/1. Chat Application/chat.java +0 -81
  74. noshot/data/ML TS XAI/CN/1. Chat Application/output.png +0 -0
  75. noshot/data/ML TS XAI/CN/1. Chat Application/procedure.png +0 -0
  76. noshot/data/ML TS XAI/CN/10. Ethernet LAN IEEE 802.3/LAN.tcl +0 -65
  77. noshot/data/ML TS XAI/CN/10. Ethernet LAN IEEE 802.3/analysis.awk +0 -44
  78. noshot/data/ML TS XAI/CN/10. Ethernet LAN IEEE 802.3/output.png +0 -0
  79. noshot/data/ML TS XAI/CN/10. Ethernet LAN IEEE 802.3/procedure.png +0 -0
  80. noshot/data/ML TS XAI/CN/11. Wireless LAN IEEE 802.11/complexdcf.tcl +0 -229
  81. noshot/data/ML TS XAI/CN/11. Wireless LAN IEEE 802.11/output.png +0 -0
  82. noshot/data/ML TS XAI/CN/11. Wireless LAN IEEE 802.11/procedure.png +0 -0
  83. noshot/data/ML TS XAI/CN/2. File Transfer/file_to_send.txt +0 -2
  84. noshot/data/ML TS XAI/CN/2. File Transfer/filetransfer.java +0 -119
  85. noshot/data/ML TS XAI/CN/2. File Transfer/output.png +0 -0
  86. noshot/data/ML TS XAI/CN/2. File Transfer/procedure.png +0 -0
  87. noshot/data/ML TS XAI/CN/3. RMI (Remote Method Invocation)/Client.class +0 -0
  88. noshot/data/ML TS XAI/CN/3. RMI (Remote Method Invocation)/MyServerImpl.class +0 -0
  89. noshot/data/ML TS XAI/CN/3. RMI (Remote Method Invocation)/MyServerIntf.class +0 -0
  90. noshot/data/ML TS XAI/CN/3. RMI (Remote Method Invocation)/Server.class +0 -0
  91. noshot/data/ML TS XAI/CN/3. RMI (Remote Method Invocation)/output.png +0 -0
  92. noshot/data/ML TS XAI/CN/3. RMI (Remote Method Invocation)/procedure.png +0 -0
  93. noshot/data/ML TS XAI/CN/3. RMI (Remote Method Invocation)/rmi.java +0 -56
  94. noshot/data/ML TS XAI/CN/4. Wired Network/output.png +0 -0
  95. noshot/data/ML TS XAI/CN/4. Wired Network/procedure.png +0 -0
  96. noshot/data/ML TS XAI/CN/4. Wired Network/wired.awk +0 -25
  97. noshot/data/ML TS XAI/CN/4. Wired Network/wired.tcl +0 -81
  98. noshot/data/ML TS XAI/CN/5. Wireless Network/output.png +0 -0
  99. noshot/data/ML TS XAI/CN/5. Wireless Network/procedure.png +0 -0
  100. noshot/data/ML TS XAI/CN/5. Wireless Network/wireless.awk +0 -27
  101. noshot/data/ML TS XAI/CN/5. Wireless Network/wireless.tcl +0 -153
  102. noshot/data/ML TS XAI/CN/6. TCP Flow And Congestion Control/TCP Congestion Control/Sack And Vegas/analysis.awk +0 -27
  103. noshot/data/ML TS XAI/CN/6. TCP Flow And Congestion Control/TCP Congestion Control/Sack And Vegas/output.png +0 -0
  104. noshot/data/ML TS XAI/CN/6. TCP Flow And Congestion Control/TCP Congestion Control/Sack And Vegas/sack.tcl +0 -86
  105. noshot/data/ML TS XAI/CN/6. TCP Flow And Congestion Control/TCP Congestion Control/Sack And Vegas/vegas.tcl +0 -86
  106. noshot/data/ML TS XAI/CN/6. TCP Flow And Congestion Control/TCP Congestion Control/Tahoe And Reno/analysis.awk +0 -28
  107. noshot/data/ML TS XAI/CN/6. TCP Flow And Congestion Control/TCP Congestion Control/Tahoe And Reno/output.png +0 -0
  108. noshot/data/ML TS XAI/CN/6. TCP Flow And Congestion Control/TCP Congestion Control/Tahoe And Reno/reno.tcl +0 -78
  109. noshot/data/ML TS XAI/CN/6. TCP Flow And Congestion Control/TCP Congestion Control/Tahoe And Reno/tahoe.tcl +0 -79
  110. noshot/data/ML TS XAI/CN/6. TCP Flow And Congestion Control/TCP Flow Control/analysis.awk +0 -27
  111. noshot/data/ML TS XAI/CN/6. TCP Flow And Congestion Control/TCP Flow Control/flow.tcl +0 -163
  112. noshot/data/ML TS XAI/CN/6. TCP Flow And Congestion Control/TCP Flow Control/output.png +0 -0
  113. noshot/data/ML TS XAI/CN/6. TCP Flow And Congestion Control/procedure.png +0 -0
  114. noshot/data/ML TS XAI/CN/7. Link State And Distance Vector Routing/DV.tcl +0 -111
  115. noshot/data/ML TS XAI/CN/7. Link State And Distance Vector Routing/LS.tcl +0 -106
  116. noshot/data/ML TS XAI/CN/7. Link State And Distance Vector Routing/analysis.awk +0 -36
  117. noshot/data/ML TS XAI/CN/7. Link State And Distance Vector Routing/output.png +0 -0
  118. noshot/data/ML TS XAI/CN/7. Link State And Distance Vector Routing/procedure.png +0 -0
  119. noshot/data/ML TS XAI/CN/8. Multicast And Broadcast Routing/analysis.awk +0 -20
  120. noshot/data/ML TS XAI/CN/8. Multicast And Broadcast Routing/broadcast.tcl +0 -76
  121. noshot/data/ML TS XAI/CN/8. Multicast And Broadcast Routing/multicast.tcl +0 -103
  122. noshot/data/ML TS XAI/CN/8. Multicast And Broadcast Routing/output.png +0 -0
  123. noshot/data/ML TS XAI/CN/8. Multicast And Broadcast Routing/procedure.png +0 -0
  124. noshot/data/ML TS XAI/CN/9. DHCP/DHCP.java +0 -125
  125. noshot/data/ML TS XAI/CN/9. DHCP/output.png +0 -0
  126. noshot/data/ML TS XAI/CN/9. DHCP/procedure.png +0 -0
  127. noshot/data/ML TS XAI/NLP/NLP 1/1-Prereqs.py +0 -18
  128. noshot/data/ML TS XAI/NLP/NLP 1/2-Chi2test.py +0 -83
  129. noshot/data/ML TS XAI/NLP/NLP 1/2-T-test.py +0 -79
  130. noshot/data/ML TS XAI/NLP/NLP 1/3-WSD-nb.py +0 -53
  131. noshot/data/ML TS XAI/NLP/NLP 1/4-Hindle-Rooth.py +0 -53
  132. noshot/data/ML TS XAI/NLP/NLP 1/5-HMM-Trellis.py +0 -82
  133. noshot/data/ML TS XAI/NLP/NLP 1/6-HMM-Viterbi.py +0 -16
  134. noshot/data/ML TS XAI/NLP/NLP 1/7-PCFG-parsetree.py +0 -15
  135. noshot/data/ML TS XAI/NLP/NLP 1/Chi2test.ipynb +0 -285
  136. noshot/data/ML TS XAI/NLP/NLP 1/Hindle-Rooth.ipynb +0 -179
  137. noshot/data/ML TS XAI/NLP/NLP 1/Lab 10 - Text generator using LSTM.ipynb +0 -1461
  138. noshot/data/ML TS XAI/NLP/NLP 1/Lab 11 NMT.ipynb +0 -2307
  139. noshot/data/ML TS XAI/NLP/NLP 1/PCFG.ipynb +0 -134
  140. noshot/data/ML TS XAI/NLP/NLP 1/Prereqs.ipynb +0 -131
  141. noshot/data/ML TS XAI/NLP/NLP 1/T test.ipynb +0 -252
  142. noshot/data/ML TS XAI/NLP/NLP 1/TFIDF BOW.ipynb +0 -171
  143. noshot/data/ML TS XAI/NLP/NLP 1/Trellis.ipynb +0 -244
  144. noshot/data/ML TS XAI/NLP/NLP 1/WSD.ipynb +0 -645
  145. noshot/data/ML TS XAI/NLP/NLP 1/Word2Vec.ipynb +0 -93
  146. noshot/data/ML TS XAI/NLP/NLP 2/Lab01(tokenizer)/tokenizer.ipynb +0 -370
  147. noshot/data/ML TS XAI/NLP/NLP 2/Lab01(tokenizer)/training_tokenizer.txt +0 -6
  148. noshot/data/ML TS XAI/NLP/NLP 2/Lab02(stemming)/exp0.ipynb +0 -274
  149. noshot/data/ML TS XAI/NLP/NLP 2/Lab02(stemming)/lab2.ipynb +0 -905
  150. noshot/data/ML TS XAI/NLP/NLP 2/Lab02(stemming)/test.txt +0 -1
  151. noshot/data/ML TS XAI/NLP/NLP 2/Lab02(stemming)/tokenizing.ipynb +0 -272
  152. noshot/data/ML TS XAI/NLP/NLP 2/Lab03(parse-tree)/collocation.ipynb +0 -332
  153. noshot/data/ML TS XAI/NLP/NLP 2/Lab03(parse-tree)/lab3.ipynb +0 -549
  154. noshot/data/ML TS XAI/NLP/NLP 2/Lab03(parse-tree)/nlp.txt +0 -1
  155. noshot/data/ML TS XAI/NLP/NLP 2/Lab04(collocation)/Lab4-NLP-Exp-2.ipynb +0 -817
  156. noshot/data/ML TS XAI/NLP/NLP 2/Lab04(collocation)/collocation.ipynb +0 -332
  157. noshot/data/ML TS XAI/NLP/NLP 2/Lab05(WSD)/NLP-Lab-5-Exp3.ipynb +0 -231
  158. noshot/data/ML TS XAI/NLP/NLP 2/Lab05(WSD)/word-sense-disambiguation.ipynb +0 -507
  159. noshot/data/ML TS XAI/NLP/NLP 2/Lab06(additional-exercise)/lab6.ipynb +0 -134
  160. noshot/data/ML TS XAI/NLP/NLP 2/Lab07(HMM,Viterbi)/NLP Exp 4.ipynb +0 -255
  161. noshot/data/ML TS XAI/NLP/NLP 2/Lab07(HMM,Viterbi)/NLP_Exp_5.ipynb +0 -159
  162. noshot/data/ML TS XAI/NLP/NLP 2/Lab08(PCFG)/PCFG.ipynb +0 -282
  163. noshot/data/ML TS XAI/NLP/NLP 2/Lab09-Hindle-rooth&MLP/Lab 9 - MLP classifier.ipynb +0 -670
  164. noshot/data/ML TS XAI/NLP/NLP 2/Lab09-Hindle-rooth&MLP/MLP-alternative-code.ipynb +0 -613
  165. noshot/data/ML TS XAI/NLP/NLP 2/Lab09-Hindle-rooth&MLP/hindle-rooth-algorithm.ipynb +0 -74
  166. noshot/data/ML TS XAI/NLP/NLP 2/Lab10(LSTM)/Lab_10_Text_generator_using_LSTM.ipynb +0 -480
  167. noshot/data/ML TS XAI/NLP/NLP 2/Lab11(Viterbi-PCFG,Machine-translation)/Machine-translation.ipynb +0 -445
  168. noshot/data/ML TS XAI/NLP/NLP 2/Lab11(Viterbi-PCFG,Machine-translation)/Viterbi-PCFG.ipynb +0 -105
  169. noshot/data/ML TS XAI/NLP/NLP 2/Lab11(Viterbi-PCFG,Machine-translation)/corpora_tools.py +0 -87
  170. noshot/data/ML TS XAI/NLP/NLP 2/Lab11(Viterbi-PCFG,Machine-translation)/data_utils.py +0 -11
  171. noshot/data/ML TS XAI/NLP/NLP 2/Lab11(Viterbi-PCFG,Machine-translation)/train_translator.py +0 -83
  172. noshot/data/ML TS XAI/NLP/NLP 2/Lab12(Information-Extraction)/Information_Extraction.ipynb +0 -201
  173. noshot/data/ML TS XAI/NLP/NLP 3/Backtrack-without-Verbitri.ipynb +0 -185
  174. noshot/data/ML TS XAI/NLP/NLP 3/Backward-Procedure.ipynb +0 -597
  175. noshot/data/ML TS XAI/NLP/NLP 3/Bag_of.ipynb +0 -1422
  176. noshot/data/ML TS XAI/NLP/NLP 3/CYK-algorithm.ipynb +0 -1067
  177. noshot/data/ML TS XAI/NLP/NLP 3/Forward-Procedure.ipynb +0 -477
  178. noshot/data/ML TS XAI/NLP/NLP 3/LSTM.ipynb +0 -1290
  179. noshot/data/ML TS XAI/NLP/NLP 3/Lab 10 - Text generator using LSTM.ipynb +0 -1461
  180. noshot/data/ML TS XAI/NLP/NLP 3/Lab 11 NMT.ipynb +0 -2307
  181. noshot/data/ML TS XAI/NLP/NLP 3/NLP-LAB-4.ipynb +0 -216
  182. noshot/data/ML TS XAI/NLP/NLP 3/NLP-LAB-5.ipynb +0 -216
  183. noshot/data/ML TS XAI/NLP/NLP 3/abc.txt +0 -6
  184. noshot/data/ML TS XAI/NLP/NLP 3/ex-1-nltk.ipynb +0 -711
  185. noshot/data/ML TS XAI/NLP/NLP 3/ex-2-nlp.ipynb +0 -267
  186. noshot/data/ML TS XAI/NLP/NLP 3/exp8&9.ipynb +0 -305
  187. noshot/data/ML TS XAI/NLP/NLP 3/hind.ipynb +0 -287
  188. noshot/data/ML TS XAI/NLP/NLP 3/lab66.ipynb +0 -752
  189. noshot/data/ML TS XAI/NLP/NLP 3/leb_3.ipynb +0 -612
  190. noshot/data/ML TS XAI/NLP/NLP 3/naive_bayes_classifier.pkl +0 -0
  191. noshot/data/ML TS XAI/NLP/NLP 3/nlp_leb_1.ipynb +0 -3008
  192. noshot/data/ML TS XAI/NLP/NLP 3/nlp_leb_2.ipynb +0 -3095
  193. noshot/data/ML TS XAI/NLP/NLP 3/nlplab-9.ipynb +0 -295
  194. noshot/data/ML TS XAI/NLP/NLP 3/nltk-ex-4.ipynb +0 -506
  195. noshot/data/ML TS XAI/NLP/NLP 3/text1.txt +0 -48
  196. noshot/data/ML TS XAI/NLP/NLP 3/text2.txt +0 -8
  197. noshot/data/ML TS XAI/NLP/NLP 3/text3.txt +0 -48
  198. noshot/data/ML TS XAI/NLP/NLP 3/translation-rnn.ipynb +0 -812
  199. noshot/data/ML TS XAI/NLP/NLP 3/word2vector.ipynb +0 -173
  200. noshot/data/ML TS XAI/NLP/NLP 4/Backward Procedure Algorithm.ipynb +0 -179
  201. noshot/data/ML TS XAI/NLP/NLP 4/Chi Square Collocation.ipynb +0 -208
  202. noshot/data/ML TS XAI/NLP/NLP 4/Collocation (T test).ipynb +0 -188
  203. noshot/data/ML TS XAI/NLP/NLP 4/Experiment 1.ipynb +0 -437
  204. noshot/data/ML TS XAI/NLP/NLP 4/Forward Procedure Algorithm.ipynb +0 -132
  205. noshot/data/ML TS XAI/NLP/NLP 4/Hindle Rooth.ipynb +0 -414
  206. noshot/data/ML TS XAI/NLP/NLP 4/MachineTranslation.ipynb +0 -368
  207. noshot/data/ML TS XAI/NLP/NLP 4/Multi Layer Perceptron using MLPClassifier.ipynb +0 -86
  208. noshot/data/ML TS XAI/NLP/NLP 4/Multi Layer Perceptron using Tensorflow.ipynb +0 -112
  209. noshot/data/ML TS XAI/NLP/NLP 4/PCFG Inside Probability.ipynb +0 -451
  210. noshot/data/ML TS XAI/NLP/NLP 4/Text Generation using LSTM.ipynb +0 -297
  211. noshot/data/ML TS XAI/NLP/NLP 4/Viterbi.ipynb +0 -310
  212. noshot/data/ML TS XAI/NLP/NLP 4/Word Sense Disambiguation.ipynb +0 -335
  213. noshot/data/ML TS XAI/NLP/NLP 5/10.Text Generation using LSTM.ipynb +0 -316
  214. noshot/data/ML TS XAI/NLP/NLP 5/11.Machine Translation.ipynb +0 -868
  215. noshot/data/ML TS XAI/NLP/NLP 5/2.T and Chi2 Test.ipynb +0 -204
  216. noshot/data/ML TS XAI/NLP/NLP 5/3.Word Sense Diambiguation.ipynb +0 -234
  217. noshot/data/ML TS XAI/NLP/NLP 5/4.Hinddle and Rooth.ipynb +0 -128
  218. noshot/data/ML TS XAI/NLP/NLP 5/5.Forward and Backward.ipynb +0 -149
  219. noshot/data/ML TS XAI/NLP/NLP 5/6.Viterbi.ipynb +0 -111
  220. noshot/data/ML TS XAI/NLP/NLP 5/7.PCFG Parse Tree.ipynb +0 -134
  221. noshot/data/ML TS XAI/NLP/NLP 5/7.PCFG using cyk.ipynb +0 -101
  222. noshot/data/ML TS XAI/NLP/NLP 5/8.Bag of words and TF-IDF.ipynb +0 -310
  223. noshot/data/ML TS XAI/NLP/NLP 5/9.Word2Vector.ipynb +0 -78
  224. noshot/data/ML TS XAI/NLP/NLP 5/NLP ALL In One.ipynb +0 -2619
  225. noshot/data/ML TS XAI/NLP/NLP 5/sample1.txt +0 -15
  226. noshot/data/ML TS XAI/NLP/NLP 5/sample2.txt +0 -4
  227. noshot/data/ML TS XAI/NLP/NLP 5/word2vec_model.bin +0 -0
  228. noshot/data/ML TS XAI/NLP/NLP 6/1. Tokenize, Tagging, NER, Parse Tree.ipynb +0 -312
  229. noshot/data/ML TS XAI/NLP/NLP 6/2. T Test and Chi2 Test.ipynb +0 -185
  230. noshot/data/ML TS XAI/NLP/NLP 6/3. Naive Bayes WSD.ipynb +0 -199
  231. noshot/data/ML TS XAI/NLP/NLP 6/4. Hinddle and Rooth.ipynb +0 -151
  232. noshot/data/ML TS XAI/NLP/NLP 6/5 and 6 FWD, BWD, Viterbi.ipynb +0 -164
  233. noshot/data/ML TS XAI/NLP/NLP 6/7. PCFG using CYK.ipynb +0 -383
  234. noshot/data/ML TS XAI/NLP/NLP 6/8. BOW and TF-IDF.ipynb +0 -252
  235. noshot/data/ML TS XAI/Ubuntu CN Lab.iso +0 -0
  236. noshot-0.1.7.dist-info/RECORD +0 -216
  237. {noshot-0.1.7.dist-info → noshot-0.1.9.dist-info}/LICENSE.txt +0 -0
  238. {noshot-0.1.7.dist-info → noshot-0.1.9.dist-info}/WHEEL +0 -0
  239. {noshot-0.1.7.dist-info → noshot-0.1.9.dist-info}/top_level.txt +0 -0
@@ -1,1290 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": 1,
6
- "id": "d5f37367-910d-4abc-9448-3f80ebc0c956",
7
- "metadata": {},
8
- "outputs": [
9
- {
10
- "name": "stdout",
11
- "output_type": "stream",
12
- "text": [
13
- "Requirement already satisfied: tensorflow in c:\\users\\admin\\anaconda3\\lib\\site-packages (2.16.1)\n",
14
- "Requirement already satisfied: keras in c:\\users\\admin\\anaconda3\\lib\\site-packages (3.3.2)\n",
15
- "Requirement already satisfied: numpy in c:\\users\\admin\\anaconda3\\lib\\site-packages (1.26.4)\n",
16
- "Requirement already satisfied: tensorflow-intel==2.16.1 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from tensorflow) (2.16.1)\n",
17
- "Requirement already satisfied: absl-py>=1.0.0 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from tensorflow-intel==2.16.1->tensorflow) (2.1.0)\n",
18
- "Requirement already satisfied: astunparse>=1.6.0 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from tensorflow-intel==2.16.1->tensorflow) (1.6.3)\n",
19
- "Requirement already satisfied: flatbuffers>=23.5.26 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from tensorflow-intel==2.16.1->tensorflow) (24.3.25)\n",
20
- "Requirement already satisfied: gast!=0.5.0,!=0.5.1,!=0.5.2,>=0.2.1 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from tensorflow-intel==2.16.1->tensorflow) (0.5.4)\n",
21
- "Requirement already satisfied: google-pasta>=0.1.1 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from tensorflow-intel==2.16.1->tensorflow) (0.2.0)\n",
22
- "Requirement already satisfied: h5py>=3.10.0 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from tensorflow-intel==2.16.1->tensorflow) (3.11.0)\n",
23
- "Requirement already satisfied: libclang>=13.0.0 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from tensorflow-intel==2.16.1->tensorflow) (18.1.1)\n",
24
- "Requirement already satisfied: ml-dtypes~=0.3.1 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from tensorflow-intel==2.16.1->tensorflow) (0.3.2)\n",
25
- "Requirement already satisfied: opt-einsum>=2.3.2 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from tensorflow-intel==2.16.1->tensorflow) (3.3.0)\n",
26
- "Requirement already satisfied: packaging in c:\\users\\admin\\anaconda3\\lib\\site-packages (from tensorflow-intel==2.16.1->tensorflow) (23.1)\n",
27
- "Requirement already satisfied: protobuf!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.20.3 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from tensorflow-intel==2.16.1->tensorflow) (4.25.4)\n",
28
- "Requirement already satisfied: requests<3,>=2.21.0 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from tensorflow-intel==2.16.1->tensorflow) (2.31.0)\n",
29
- "Requirement already satisfied: setuptools in c:\\users\\admin\\anaconda3\\lib\\site-packages (from tensorflow-intel==2.16.1->tensorflow) (68.2.2)\n",
30
- "Requirement already satisfied: six>=1.12.0 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from tensorflow-intel==2.16.1->tensorflow) (1.16.0)\n",
31
- "Requirement already satisfied: termcolor>=1.1.0 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from tensorflow-intel==2.16.1->tensorflow) (2.4.0)\n",
32
- "Requirement already satisfied: typing-extensions>=3.6.6 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from tensorflow-intel==2.16.1->tensorflow) (4.9.0)\n",
33
- "Requirement already satisfied: wrapt>=1.11.0 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from tensorflow-intel==2.16.1->tensorflow) (1.14.1)\n",
34
- "Requirement already satisfied: grpcio<2.0,>=1.24.3 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from tensorflow-intel==2.16.1->tensorflow) (1.62.2)\n",
35
- "Requirement already satisfied: tensorboard<2.17,>=2.16 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from tensorflow-intel==2.16.1->tensorflow) (2.16.2)\n",
36
- "Requirement already satisfied: tensorflow-io-gcs-filesystem>=0.23.1 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from tensorflow-intel==2.16.1->tensorflow) (0.31.0)\n",
37
- "Requirement already satisfied: rich in c:\\users\\admin\\anaconda3\\lib\\site-packages (from keras) (13.3.5)\n",
38
- "Requirement already satisfied: namex in c:\\users\\admin\\anaconda3\\lib\\site-packages (from keras) (0.0.8)\n",
39
- "Requirement already satisfied: optree in c:\\users\\admin\\anaconda3\\lib\\site-packages (from keras) (0.11.0)\n",
40
- "Requirement already satisfied: markdown-it-py<3.0.0,>=2.2.0 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from rich->keras) (2.2.0)\n",
41
- "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from rich->keras) (2.15.1)\n",
42
- "Requirement already satisfied: wheel<1.0,>=0.23.0 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from astunparse>=1.6.0->tensorflow-intel==2.16.1->tensorflow) (0.41.2)\n",
43
- "Requirement already satisfied: mdurl~=0.1 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from markdown-it-py<3.0.0,>=2.2.0->rich->keras) (0.1.0)\n",
44
- "Requirement already satisfied: charset-normalizer<4,>=2 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from requests<3,>=2.21.0->tensorflow-intel==2.16.1->tensorflow) (2.0.4)\n",
45
- "Requirement already satisfied: idna<4,>=2.5 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from requests<3,>=2.21.0->tensorflow-intel==2.16.1->tensorflow) (3.4)\n",
46
- "Requirement already satisfied: urllib3<3,>=1.21.1 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from requests<3,>=2.21.0->tensorflow-intel==2.16.1->tensorflow) (2.0.7)\n",
47
- "Requirement already satisfied: certifi>=2017.4.17 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from requests<3,>=2.21.0->tensorflow-intel==2.16.1->tensorflow) (2024.2.2)\n",
48
- "Requirement already satisfied: markdown>=2.6.8 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from tensorboard<2.17,>=2.16->tensorflow-intel==2.16.1->tensorflow) (3.4.1)\n",
49
- "Requirement already satisfied: tensorboard-data-server<0.8.0,>=0.7.0 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from tensorboard<2.17,>=2.16->tensorflow-intel==2.16.1->tensorflow) (0.7.2)\n",
50
- "Requirement already satisfied: werkzeug>=1.0.1 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from tensorboard<2.17,>=2.16->tensorflow-intel==2.16.1->tensorflow) (2.2.3)\n",
51
- "Requirement already satisfied: MarkupSafe>=2.1.1 in c:\\users\\admin\\anaconda3\\lib\\site-packages (from werkzeug>=1.0.1->tensorboard<2.17,>=2.16->tensorflow-intel==2.16.1->tensorflow) (2.1.3)\n",
52
- "Note: you may need to restart the kernel to use updated packages.\n"
53
- ]
54
- }
55
- ],
56
- "source": [
57
- "pip install tensorflow keras numpy\n"
58
- ]
59
- },
60
- {
61
- "cell_type": "code",
62
- "execution_count": 3,
63
- "id": "8f4bb095-8a80-4c94-9d96-b2c32a953bb3",
64
- "metadata": {},
65
- "outputs": [
66
- {
67
- "name": "stdout",
68
- "output_type": "stream",
69
- "text": [
70
- "Epoch 1/20\n"
71
- ]
72
- },
73
- {
74
- "name": "stderr",
75
- "output_type": "stream",
76
- "text": [
77
- "C:\\Users\\admin\\anaconda3\\Lib\\site-packages\\keras\\src\\layers\\rnn\\rnn.py:204: UserWarning: Do not pass an `input_shape`/`input_dim` argument to a layer. When using Sequential models, prefer using an `Input(shape)` object as the first layer in the model instead.\n",
78
- " super().__init__(**kwargs)\n"
79
- ]
80
- },
81
- {
82
- "name": "stdout",
83
- "output_type": "stream",
84
- "text": [
85
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 76ms/step - loss: 2.9326\n",
86
- "Epoch 2/20\n",
87
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 75ms/step - loss: 2.2379\n",
88
- "Epoch 3/20\n",
89
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 76ms/step - loss: 1.9985\n",
90
- "Epoch 4/20\n",
91
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 76ms/step - loss: 1.8285\n",
92
- "Epoch 5/20\n",
93
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 76ms/step - loss: 1.6803\n",
94
- "Epoch 6/20\n",
95
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 76ms/step - loss: 1.5555\n",
96
- "Epoch 7/20\n",
97
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 76ms/step - loss: 1.4393\n",
98
- "Epoch 8/20\n",
99
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 76ms/step - loss: 1.3217\n",
100
- "Epoch 9/20\n",
101
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 77ms/step - loss: 1.2309\n",
102
- "Epoch 10/20\n",
103
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 76ms/step - loss: 1.1432\n",
104
- "Epoch 11/20\n",
105
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 76ms/step - loss: 1.0568\n",
106
- "Epoch 12/20\n",
107
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 77ms/step - loss: 0.9911\n",
108
- "Epoch 13/20\n",
109
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 77ms/step - loss: 0.9336\n",
110
- "Epoch 14/20\n",
111
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 77ms/step - loss: 0.8703\n",
112
- "Epoch 15/20\n",
113
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 77ms/step - loss: 0.8482\n",
114
- "Epoch 16/20\n",
115
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 79ms/step - loss: 0.7805\n",
116
- "Epoch 17/20\n",
117
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 79ms/step - loss: 0.7586\n",
118
- "Epoch 18/20\n",
119
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 78ms/step - loss: 0.7504\n",
120
- "Epoch 19/20\n",
121
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 78ms/step - loss: 0.7082\n",
122
- "Epoch 20/20\n",
123
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 79ms/step - loss: 0.6857\n",
124
- "all veziers-le-rethel had followed the funeral procession of m. badon- leremince to the grave, and the the frost might of her stold that did not care for her parents me one's the fireplace.\n",
125
- "\n",
126
- "and they have not from my chair to be was a strander them an example, never had been placed in my heart to time. they have not never had said my heart was suddenly a crime, ready to come out. if some time, and the selod and the stars that i suffered in the child cry-chair before they have on from my chair to be was a strander them an example, never had been placed in my heart to time. they have not never h\n"
127
- ]
128
- }
129
- ],
130
- "source": [
131
- "import numpy as np\n",
132
- "import tensorflow as tf\n",
133
- "from tensorflow.keras.models import Sequential\n",
134
- "from tensorflow.keras.layers import LSTM, Dense\n",
135
- "from tensorflow.keras.optimizers import Adam\n",
136
- "\n",
137
- "# Load and preprocess the data\n",
138
- "file_path = 'story.txt' # Replace with your .txt file path\n",
139
- "\n",
140
- "with open(file_path, 'r', encoding='utf-8') as file:\n",
141
- " text = file.read().lower() # Convert to lowercase for consistency\n",
142
- "\n",
143
- "# Create character-to-index and index-to-character mappings\n",
144
- "chars = sorted(list(set(text)))\n",
145
- "char_to_index = {c: i for i, c in enumerate(chars)}\n",
146
- "index_to_char = {i: c for i, c in enumerate(chars)}\n",
147
- "\n",
148
- "# Prepare the dataset\n",
149
- "sequence_length = 100\n",
150
- "sequences = []\n",
151
- "next_chars = []\n",
152
- "\n",
153
- "for i in range(0, len(text) - sequence_length, 1):\n",
154
- " sequences.append(text[i:i + sequence_length])\n",
155
- " next_chars.append(text[i + sequence_length])\n",
156
- "\n",
157
- "# Convert sequences to integer format\n",
158
- "X = np.zeros((len(sequences), sequence_length, len(chars)), dtype=bool)\n",
159
- "y = np.zeros((len(sequences), len(chars)), dtype=bool)\n",
160
- "\n",
161
- "for i, sequence in enumerate(sequences):\n",
162
- " for t, char in enumerate(sequence):\n",
163
- " X[i, t, char_to_index[char]] = 1\n",
164
- " y[i, char_to_index[next_chars[i]]] = 1\n",
165
- "\n",
166
- "# Build the LSTM model\n",
167
- "model = Sequential()\n",
168
- "model.add(LSTM(128, input_shape=(sequence_length, len(chars))))\n",
169
- "model.add(Dense(len(chars), activation='softmax'))\n",
170
- "\n",
171
- "# Compile the model\n",
172
- "model.compile(loss='categorical_crossentropy', optimizer=Adam(learning_rate=0.01))\n",
173
- "\n",
174
- "# Train the model\n",
175
- "model.fit(X, y, batch_size=128, epochs=20)\n",
176
- "\n",
177
- "# Function to generate text\n",
178
- "def generate_text(seed, length):\n",
179
- " generated = seed\n",
180
- " for _ in range(length):\n",
181
- " x_pred = np.zeros((1, sequence_length, len(chars)))\n",
182
- " for t, char in enumerate(seed):\n",
183
- " x_pred[0, t, char_to_index[char]] = 1\n",
184
- " preds = model.predict(x_pred, verbose=0)[0]\n",
185
- " next_index = np.argmax(preds)\n",
186
- " next_char = index_to_char[next_index]\n",
187
- "\n",
188
- " generated += next_char\n",
189
- " seed = seed[1:] + next_char\n",
190
- " return generated\n",
191
- "\n",
192
- "# Generate new text\n",
193
- "seed_text = text[:sequence_length] # Starting with the first sequence\n",
194
- "generated_text = generate_text(seed_text, 500) # Generate 500 characters\n",
195
- "print(generated_text)\n"
196
- ]
197
- },
198
- {
199
- "cell_type": "code",
200
- "execution_count": 4,
201
- "id": "08665e0a-2db2-49ea-8311-3094aaaea017",
202
- "metadata": {},
203
- "outputs": [
204
- {
205
- "name": "stdout",
206
- "output_type": "stream",
207
- "text": [
208
- "Epoch 1/20\n",
209
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 74ms/step - loss: 3.0619\n",
210
- "Epoch 2/20\n",
211
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 69ms/step - loss: 2.6110\n",
212
- "Epoch 3/20\n",
213
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 62ms/step - loss: 2.2423\n",
214
- "Epoch 4/20\n",
215
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 60ms/step - loss: 2.0018\n",
216
- "Epoch 5/20\n",
217
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 63ms/step - loss: 1.7758\n",
218
- "Epoch 6/20\n",
219
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 65ms/step - loss: 1.5593\n",
220
- "Epoch 7/20\n",
221
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 60ms/step - loss: 1.3996\n",
222
- "Epoch 8/20\n",
223
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 62ms/step - loss: 1.2476\n",
224
- "Epoch 9/20\n",
225
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 61ms/step - loss: 1.1190\n",
226
- "Epoch 10/20\n",
227
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 61ms/step - loss: 0.9928\n",
228
- "Epoch 11/20\n",
229
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 66ms/step - loss: 0.9214\n",
230
- "Epoch 12/20\n",
231
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 63ms/step - loss: 0.8305\n",
232
- "Epoch 13/20\n",
233
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 62ms/step - loss: 0.7180\n",
234
- "Epoch 14/20\n",
235
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 62ms/step - loss: 0.7005\n",
236
- "Epoch 15/20\n",
237
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 62ms/step - loss: 0.6285\n",
238
- "Epoch 16/20\n",
239
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 61ms/step - loss: 0.5890\n",
240
- "Epoch 17/20\n",
241
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 62ms/step - loss: 0.5114\n",
242
- "Epoch 18/20\n",
243
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 61ms/step - loss: 0.4845\n",
244
- "Epoch 19/20\n",
245
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 62ms/step - loss: 0.4621\n",
246
- "Epoch 20/20\n",
247
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 62ms/step - loss: 0.4143\n",
248
- "the impact of artificial intelligence on data science\n",
249
- "introduction\n",
250
- "in recent years, the convergence of and outlial for example, ai-powered nle sensure analysis, entity to ensure manual essential for making transformed data processing capabilities, accowore morket transformed data processing capabilities, accowore morket transformed data processing capabilities, accowore morket transformed data processing capabilities, accowore morket transformed data processing capabilities, accowore morket transformed data processing capabilities, accowore morket transformed data processing capabilities, acco\n"
251
- ]
252
- }
253
- ],
254
- "source": [
255
- "import numpy as np\n",
256
- "import tensorflow as tf\n",
257
- "from tensorflow.keras.models import Sequential\n",
258
- "from tensorflow.keras.layers import LSTM, Dense\n",
259
- "from tensorflow.keras.optimizers import Adam\n",
260
- "\n",
261
- "# Load and preprocess the data\n",
262
- "file_path = 'text3.txt' # Replace with your .txt file path\n",
263
- "\n",
264
- "with open(file_path, 'r', encoding='utf-8') as file:\n",
265
- " text = file.read().lower() # Convert to lowercase for consistency\n",
266
- "\n",
267
- "# Create character-to-index and index-to-character mappings\n",
268
- "chars = sorted(list(set(text)))\n",
269
- "char_to_index = {c: i for i, c in enumerate(chars)}\n",
270
- "index_to_char = {i: c for i, c in enumerate(chars)}\n",
271
- "\n",
272
- "# Prepare the dataset\n",
273
- "sequence_length = 100\n",
274
- "sequences = []\n",
275
- "next_chars = []\n",
276
- "\n",
277
- "for i in range(0, len(text) - sequence_length, 1):\n",
278
- " sequences.append(text[i:i + sequence_length])\n",
279
- " next_chars.append(text[i + sequence_length])\n",
280
- "\n",
281
- "# Convert sequences to integer format\n",
282
- "X = np.zeros((len(sequences), sequence_length, len(chars)), dtype=bool)\n",
283
- "y = np.zeros((len(sequences), len(chars)), dtype=bool)\n",
284
- "\n",
285
- "for i, sequence in enumerate(sequences):\n",
286
- " for t, char in enumerate(sequence):\n",
287
- " X[i, t, char_to_index[char]] = 1\n",
288
- " y[i, char_to_index[next_chars[i]]] = 1\n",
289
- "\n",
290
- "# Build the LSTM model\n",
291
- "model = Sequential()\n",
292
- "model.add(LSTM(128, input_shape=(sequence_length, len(chars))))\n",
293
- "model.add(Dense(len(chars), activation='softmax'))\n",
294
- "\n",
295
- "# Compile the model\n",
296
- "model.compile(loss='categorical_crossentropy', optimizer=Adam(learning_rate=0.01))\n",
297
- "\n",
298
- "# Train the model\n",
299
- "model.fit(X, y, batch_size=128, epochs=20)\n",
300
- "\n",
301
- "# Function to generate text\n",
302
- "def generate_text(seed, length):\n",
303
- " generated = seed\n",
304
- " for _ in range(length):\n",
305
- " x_pred = np.zeros((1, sequence_length, len(chars)))\n",
306
- " for t, char in enumerate(seed):\n",
307
- " x_pred[0, t, char_to_index[char]] = 1\n",
308
- " preds = model.predict(x_pred, verbose=0)[0]\n",
309
- " next_index = np.argmax(preds)\n",
310
- " next_char = index_to_char[next_index]\n",
311
- "\n",
312
- " generated += next_char\n",
313
- " seed = seed[1:] + next_char\n",
314
- " return generated\n",
315
- "\n",
316
- "# Generate new text\n",
317
- "seed_text = text[:sequence_length] # Starting with the first sequence\n",
318
- "generated_text = generate_text(seed_text, 500) # Generate 500 characters\n",
319
- "print(generated_text)\n"
320
- ]
321
- },
322
- {
323
- "cell_type": "code",
324
- "execution_count": 5,
325
- "id": "3417c46f-a775-4906-9df7-b4e42174499b",
326
- "metadata": {},
327
- "outputs": [
328
- {
329
- "name": "stdout",
330
- "output_type": "stream",
331
- "text": [
332
- "Epoch 1/20\n",
333
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 64ms/step - loss: 2.9458\n",
334
- "Epoch 2/20\n",
335
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 62ms/step - loss: 2.2906\n",
336
- "Epoch 3/20\n",
337
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 2.0541\n",
338
- "Epoch 4/20\n",
339
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 1.8668\n",
340
- "Epoch 5/20\n",
341
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 1.7507\n",
342
- "Epoch 6/20\n",
343
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 1.6214\n",
344
- "Epoch 7/20\n",
345
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 1.5074\n",
346
- "Epoch 8/20\n",
347
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 1.3756\n",
348
- "Epoch 9/20\n",
349
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 1.2885\n",
350
- "Epoch 10/20\n",
351
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 1.1763\n",
352
- "Epoch 11/20\n",
353
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 62ms/step - loss: 1.1092\n",
354
- "Epoch 12/20\n",
355
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 1.0609\n",
356
- "Epoch 13/20\n",
357
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 0.9783\n",
358
- "Epoch 14/20\n",
359
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 62ms/step - loss: 0.9056\n",
360
- "Epoch 15/20\n",
361
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m7s\u001b[0m 63ms/step - loss: 0.8710\n",
362
- "Epoch 16/20\n",
363
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 0.8234\n",
364
- "Epoch 17/20\n",
365
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 0.8114\n",
366
- "Epoch 18/20\n",
367
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 0.7557\n",
368
- "Epoch 19/20\n",
369
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 0.7315\n",
370
- "Epoch 20/20\n",
371
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 0.6878\n"
372
- ]
373
- },
374
- {
375
- "name": "stdin",
376
- "output_type": "stream",
377
- "text": [
378
- "Enter a seed text: My children, my dear children, I could not sleep the eternal sleep in peace if I\n"
379
- ]
380
- },
381
- {
382
- "name": "stdout",
383
- "output_type": "stream",
384
- "text": [
385
- "Generated Text:\n",
386
- " my children, my dear children, i could not sleep the eternal sleep in peace if i was an hour, and saided the window the strokes mothered them they were presently deslighted her parents' consent the child coughed again, and the child coughed again, and the child coughed again, and the child coughed again, and the child coughed again, and the child coughed again, and the child coughed again, and the child coughed again, and the child coughed again, and the child coughed again, and the child coughed again, and the child coughed again, and the child coughed again, and the child\n"
387
- ]
388
- }
389
- ],
390
- "source": [
391
- "import numpy as np\n",
392
- "import tensorflow as tf\n",
393
- "from tensorflow.keras.models import Sequential\n",
394
- "from tensorflow.keras.layers import LSTM, Dense\n",
395
- "from tensorflow.keras.optimizers import Adam\n",
396
- "\n",
397
- "# Load and preprocess the data\n",
398
- "file_path = 'story.txt' # Replace with your .txt file path\n",
399
- "\n",
400
- "with open(file_path, 'r', encoding='utf-8') as file:\n",
401
- " text = file.read().lower() # Convert to lowercase for consistency\n",
402
- "\n",
403
- "# Create character-to-index and index-to-character mappings\n",
404
- "chars = sorted(list(set(text)))\n",
405
- "char_to_index = {c: i for i, c in enumerate(chars)}\n",
406
- "index_to_char = {i: c for i, c in enumerate(chars)}\n",
407
- "\n",
408
- "# Prepare the dataset\n",
409
- "sequence_length = 100\n",
410
- "sequences = []\n",
411
- "next_chars = []\n",
412
- "\n",
413
- "for i in range(0, len(text) - sequence_length, 1):\n",
414
- " sequences.append(text[i:i + sequence_length])\n",
415
- " next_chars.append(text[i + sequence_length])\n",
416
- "\n",
417
- "# Convert sequences to integer format\n",
418
- "X = np.zeros((len(sequences), sequence_length, len(chars)), dtype=bool)\n",
419
- "y = np.zeros((len(sequences), len(chars)), dtype=bool)\n",
420
- "\n",
421
- "for i, sequence in enumerate(sequences):\n",
422
- " for t, char in enumerate(sequence):\n",
423
- " X[i, t, char_to_index[char]] = 1\n",
424
- " y[i, char_to_index[next_chars[i]]] = 1\n",
425
- "\n",
426
- "# Build the LSTM model\n",
427
- "model = Sequential()\n",
428
- "model.add(LSTM(128, input_shape=(sequence_length, len(chars))))\n",
429
- "model.add(Dense(len(chars), activation='softmax'))\n",
430
- "\n",
431
- "# Compile the model\n",
432
- "model.compile(loss='categorical_crossentropy', optimizer=Adam(learning_rate=0.01))\n",
433
- "\n",
434
- "# Train the model\n",
435
- "model.fit(X, y, batch_size=128, epochs=20)\n",
436
- "\n",
437
- "# Function to generate text based on user input\n",
438
- "def generate_text_based_on_input(seed, length=500):\n",
439
- " generated = seed\n",
440
- " for _ in range(length):\n",
441
- " x_pred = np.zeros((1, sequence_length, len(chars)))\n",
442
- " for t, char in enumerate(seed[-sequence_length:]):\n",
443
- " if char in char_to_index:\n",
444
- " x_pred[0, t, char_to_index[char]] = 1\n",
445
- " preds = model.predict(x_pred, verbose=0)[0]\n",
446
- " next_index = np.argmax(preds)\n",
447
- " next_char = index_to_char[next_index]\n",
448
- "\n",
449
- " generated += next_char\n",
450
- " seed = seed[1:] + next_char\n",
451
- " return generated\n",
452
- "\n",
453
- "# Get user input and generate text\n",
454
- "user_input = input(\"Enter a seed text: \").lower() # Convert input to lowercase for consistency\n",
455
- "if len(user_input) < sequence_length:\n",
456
- " # If the input is too short, pad it with spaces\n",
457
- " user_input = ' ' * (sequence_length - len(user_input)) + user_input\n",
458
- "\n",
459
- "generated_text = generate_text_based_on_input(user_input, 500) # Generate 500 characters\n",
460
- "print(\"Generated Text:\\n\", generated_text)\n"
461
- ]
462
- },
463
- {
464
- "cell_type": "code",
465
- "execution_count": 6,
466
- "id": "251b2fc3-5b54-48b0-a22c-caf834ebc71e",
467
- "metadata": {},
468
- "outputs": [
469
- {
470
- "name": "stdout",
471
- "output_type": "stream",
472
- "text": [
473
- "Epoch 1/20\n",
474
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 62ms/step - loss: 2.9647\n",
475
- "Epoch 2/20\n",
476
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m7s\u001b[0m 63ms/step - loss: 2.2791\n",
477
- "Epoch 3/20\n",
478
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 62ms/step - loss: 2.0423\n",
479
- "Epoch 4/20\n",
480
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 1.8638\n",
481
- "Epoch 5/20\n",
482
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 60ms/step - loss: 1.7517\n",
483
- "Epoch 6/20\n",
484
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 60ms/step - loss: 1.5960\n",
485
- "Epoch 7/20\n",
486
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 60ms/step - loss: 1.4962\n",
487
- "Epoch 8/20\n",
488
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 60ms/step - loss: 1.3756\n",
489
- "Epoch 9/20\n",
490
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 60ms/step - loss: 1.2786\n",
491
- "Epoch 10/20\n",
492
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 1.1815\n",
493
- "Epoch 11/20\n",
494
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 60ms/step - loss: 1.0831\n",
495
- "Epoch 12/20\n",
496
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 1.0043\n",
497
- "Epoch 13/20\n",
498
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 0.9850\n",
499
- "Epoch 14/20\n",
500
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 60ms/step - loss: 0.8991\n",
501
- "Epoch 15/20\n",
502
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 60ms/step - loss: 0.8368\n",
503
- "Epoch 16/20\n",
504
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 60ms/step - loss: 0.8337\n",
505
- "Epoch 17/20\n",
506
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m7s\u001b[0m 62ms/step - loss: 0.7777\n",
507
- "Epoch 18/20\n",
508
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 0.7415\n",
509
- "Epoch 19/20\n",
510
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 62ms/step - loss: 0.7063\n",
511
- "Epoch 20/20\n",
512
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 0.6638\n"
513
- ]
514
- },
515
- {
516
- "name": "stdin",
517
- "output_type": "stream",
518
- "text": [
519
- "Enter a seed text: All Veziers-le-Rethel had followed the funeral procession of M. Badon-Leremince to the grave, and the\n"
520
- ]
521
- },
522
- {
523
- "name": "stdout",
524
- "output_type": "stream",
525
- "text": [
526
- "Generated Text:\n",
527
- " all veziers-le-rethel had followed the funeral procession of m. badon-leremince to the grave, and the window the destrosen an the end of a woman being the window the frightfully his spectacles with that i seemed to the end of a woman being the window the frightfully his spectacles with that i seemed to the end of a woman being the window the frightfully his spectacles with that i seemed to the end of a woman being the window the frightfully his spectacles with that i seemed to the end of a woman being the window the frightfully his spectacles with that i seemed to the end of a woman being the w\n"
528
- ]
529
- }
530
- ],
531
- "source": [
532
- "import numpy as np\n",
533
- "import tensorflow as tf\n",
534
- "from tensorflow.keras.models import Sequential\n",
535
- "from tensorflow.keras.layers import LSTM, Dense\n",
536
- "from tensorflow.keras.optimizers import Adam\n",
537
- "\n",
538
- "# Load and preprocess the data\n",
539
- "file_path = 'story.txt' # Replace with your .txt file path\n",
540
- "\n",
541
- "with open(file_path, 'r', encoding='utf-8') as file:\n",
542
- " text = file.read().lower() # Convert to lowercase for consistency\n",
543
- "\n",
544
- "# Create character-to-index and index-to-character mappings\n",
545
- "chars = sorted(list(set(text)))\n",
546
- "char_to_index = {c: i for i, c in enumerate(chars)}\n",
547
- "index_to_char = {i: c for i, c in enumerate(chars)}\n",
548
- "\n",
549
- "# Prepare the dataset\n",
550
- "sequence_length = 100\n",
551
- "sequences = []\n",
552
- "next_chars = []\n",
553
- "\n",
554
- "for i in range(0, len(text) - sequence_length, 1):\n",
555
- " sequences.append(text[i:i + sequence_length])\n",
556
- " next_chars.append(text[i + sequence_length])\n",
557
- "\n",
558
- "# Convert sequences to integer format\n",
559
- "X = np.zeros((len(sequences), sequence_length, len(chars)), dtype=bool)\n",
560
- "y = np.zeros((len(sequences), len(chars)), dtype=bool)\n",
561
- "\n",
562
- "for i, sequence in enumerate(sequences):\n",
563
- " for t, char in enumerate(sequence):\n",
564
- " X[i, t, char_to_index[char]] = 1\n",
565
- " y[i, char_to_index[next_chars[i]]] = 1\n",
566
- "\n",
567
- "# Build the LSTM model\n",
568
- "model = Sequential()\n",
569
- "model.add(LSTM(128, input_shape=(sequence_length, len(chars))))\n",
570
- "model.add(Dense(len(chars), activation='softmax'))\n",
571
- "\n",
572
- "# Compile the model\n",
573
- "model.compile(loss='categorical_crossentropy', optimizer=Adam(learning_rate=0.01))\n",
574
- "\n",
575
- "# Train the model\n",
576
- "model.fit(X, y, batch_size=128, epochs=20)\n",
577
- "\n",
578
- "# Function to generate text based on user input\n",
579
- "def generate_text_based_on_input(seed, length=500):\n",
580
- " generated = seed\n",
581
- " for _ in range(length):\n",
582
- " x_pred = np.zeros((1, sequence_length, len(chars)))\n",
583
- " for t, char in enumerate(seed[-sequence_length:]):\n",
584
- " if char in char_to_index:\n",
585
- " x_pred[0, t, char_to_index[char]] = 1\n",
586
- " preds = model.predict(x_pred, verbose=0)[0]\n",
587
- " next_index = np.argmax(preds)\n",
588
- " next_char = index_to_char[next_index]\n",
589
- "\n",
590
- " generated += next_char\n",
591
- " seed = seed[1:] + next_char\n",
592
- " return generated\n",
593
- "\n",
594
- "# Get user input and generate text\n",
595
- "user_input = input(\"Enter a seed text: \").lower() # Convert input to lowercase for consistency\n",
596
- "if len(user_input) < sequence_length:\n",
597
- " # If the input is too short, pad it with spaces\n",
598
- " user_input = ' ' * (sequence_length - len(user_input)) + user_input\n",
599
- "\n",
600
- "generated_text = generate_text_based_on_input(user_input, 500) # Generate 500 characters\n",
601
- "print(\"Generated Text:\\n\", generated_text)\n"
602
- ]
603
- },
604
- {
605
- "cell_type": "code",
606
- "execution_count": 1,
607
- "id": "e606230a-8322-4f7d-a1b0-953d576afd09",
608
- "metadata": {},
609
- "outputs": [
610
- {
611
- "name": "stdout",
612
- "output_type": "stream",
613
- "text": [
614
- "Epoch 1/20\n"
615
- ]
616
- },
617
- {
618
- "name": "stderr",
619
- "output_type": "stream",
620
- "text": [
621
- "C:\\Users\\admin\\anaconda3\\Lib\\site-packages\\keras\\src\\layers\\rnn\\rnn.py:204: UserWarning: Do not pass an `input_shape`/`input_dim` argument to a layer. When using Sequential models, prefer using an `Input(shape)` object as the first layer in the model instead.\n",
622
- " super().__init__(**kwargs)\n"
623
- ]
624
- },
625
- {
626
- "name": "stdout",
627
- "output_type": "stream",
628
- "text": [
629
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m9s\u001b[0m 76ms/step - loss: 2.9391\n",
630
- "Epoch 2/20\n",
631
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 76ms/step - loss: 2.2775\n",
632
- "Epoch 3/20\n",
633
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 75ms/step - loss: 2.0429\n",
634
- "Epoch 4/20\n",
635
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 76ms/step - loss: 1.8611\n",
636
- "Epoch 5/20\n",
637
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 77ms/step - loss: 1.7257\n",
638
- "Epoch 6/20\n",
639
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 76ms/step - loss: 1.6239\n",
640
- "Epoch 7/20\n",
641
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 76ms/step - loss: 1.4916\n",
642
- "Epoch 8/20\n",
643
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 76ms/step - loss: 1.3634\n",
644
- "Epoch 9/20\n",
645
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 76ms/step - loss: 1.2802\n",
646
- "Epoch 10/20\n",
647
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 77ms/step - loss: 1.1956\n",
648
- "Epoch 11/20\n",
649
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m7s\u001b[0m 70ms/step - loss: 1.0818\n",
650
- "Epoch 12/20\n",
651
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m7s\u001b[0m 63ms/step - loss: 1.0210\n",
652
- "Epoch 13/20\n",
653
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 62ms/step - loss: 0.9462\n",
654
- "Epoch 14/20\n",
655
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 0.9086\n",
656
- "Epoch 15/20\n",
657
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 0.8537\n",
658
- "Epoch 16/20\n",
659
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 60ms/step - loss: 0.7936\n",
660
- "Epoch 17/20\n",
661
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 0.7640\n",
662
- "Epoch 18/20\n",
663
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 60ms/step - loss: 0.7019\n",
664
- "Epoch 19/20\n",
665
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 0.6817\n",
666
- "Epoch 20/20\n",
667
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 0.6417\n"
668
- ]
669
- },
670
- {
671
- "name": "stdin",
672
- "output_type": "stream",
673
- "text": [
674
- "Enter a seed text to start generating text: All Veziers-le-Rethel had followed the funeral procession of M. Badon-Leremince to the grave, and the\n"
675
- ]
676
- },
677
- {
678
- "name": "stdout",
679
- "output_type": "stream",
680
- "text": [
681
- "\n",
682
- "Generated Text:\n",
683
- " all veziers-le-rethel had followed the funeral procession of m. badon-leremince to the grave, and the took the resartice to the windowan tound, in me or? he evering. the with her a brist for the suffering only are dang--silentus?\"\n",
684
- "\n",
685
- "wher it awleep if a men the tall--the likenaniso it mp, and je? he last become becoming flech.\n",
686
- "\n",
687
- "but more fremed at the fetter when a reast recolacked by to mad in beside my befunte from my wind; and i madt when i was enseasles with the evening. i tervouset of mournct, and shutis alone in the windration who was take.\n",
688
- "\n",
689
- "he wind the fetter of a gander untow at horblack.\n",
690
- "\n"
691
- ]
692
- }
693
- ],
694
- "source": [
695
- "import numpy as np\n",
696
- "import tensorflow as tf\n",
697
- "from tensorflow.keras.models import Sequential\n",
698
- "from tensorflow.keras.layers import LSTM, Dense\n",
699
- "from tensorflow.keras.optimizers import Adam\n",
700
- "\n",
701
- "# Load and preprocess the data\n",
702
- "file_path = 'story.txt' # Path to your story.txt\n",
703
- "\n",
704
- "with open(file_path, 'r', encoding='utf-8') as file:\n",
705
- " text = file.read().lower() # Convert to lowercase for consistency\n",
706
- "\n",
707
- "# Create character-to-index and index-to-character mappings\n",
708
- "chars = sorted(list(set(text)))\n",
709
- "char_to_index = {c: i for i, c in enumerate(chars)}\n",
710
- "index_to_char = {i: c for i, c in enumerate(chars)}\n",
711
- "\n",
712
- "# Prepare the dataset\n",
713
- "sequence_length = 100\n",
714
- "sequences = []\n",
715
- "next_chars = []\n",
716
- "\n",
717
- "for i in range(0, len(text) - sequence_length, 1):\n",
718
- " sequences.append(text[i:i + sequence_length])\n",
719
- " next_chars.append(text[i + sequence_length])\n",
720
- "\n",
721
- "# Convert sequences to integer format\n",
722
- "X = np.zeros((len(sequences), sequence_length, len(chars)), dtype=bool)\n",
723
- "y = np.zeros((len(sequences), len(chars)), dtype=bool)\n",
724
- "\n",
725
- "for i, sequence in enumerate(sequences):\n",
726
- " for t, char in enumerate(sequence):\n",
727
- " X[i, t, char_to_index[char]] = 1\n",
728
- " y[i, char_to_index[next_chars[i]]] = 1\n",
729
- "\n",
730
- "# Build the LSTM model\n",
731
- "model = Sequential()\n",
732
- "model.add(LSTM(128, input_shape=(sequence_length, len(chars))))\n",
733
- "model.add(Dense(len(chars), activation='softmax'))\n",
734
- "\n",
735
- "# Compile the model\n",
736
- "model.compile(loss='categorical_crossentropy', optimizer=Adam(learning_rate=0.01))\n",
737
- "\n",
738
- "# Train the model\n",
739
- "model.fit(X, y, batch_size=128, epochs=20)\n",
740
- "\n",
741
- "# Function to apply temperature sampling\n",
742
- "def sample_with_temperature(preds, temperature=1.0):\n",
743
- " preds = np.asarray(preds).astype('float64')\n",
744
- " preds = np.log(preds + 1e-10) / temperature\n",
745
- " exp_preds = np.exp(preds)\n",
746
- " preds = exp_preds / np.sum(exp_preds)\n",
747
- " probas = np.random.multinomial(1, preds, 1)\n",
748
- " return np.argmax(probas)\n",
749
- "\n",
750
- "# Function to generate text based on user input with temperature\n",
751
- "def generate_text_based_on_input(seed, length=500, temperature=1.0):\n",
752
- " generated = seed\n",
753
- " for _ in range(length):\n",
754
- " x_pred = np.zeros((1, sequence_length, len(chars)))\n",
755
- " for t, char in enumerate(seed[-sequence_length:]):\n",
756
- " if char in char_to_index:\n",
757
- " x_pred[0, t, char_to_index[char]] = 1\n",
758
- " preds = model.predict(x_pred, verbose=0)[0]\n",
759
- " next_index = sample_with_temperature(preds, temperature)\n",
760
- " next_char = index_to_char[next_index]\n",
761
- "\n",
762
- " generated += next_char\n",
763
- " seed = seed[1:] + next_char\n",
764
- " return generated\n",
765
- "\n",
766
- "# Get user input\n",
767
- "user_input = input(\"Enter a seed text to start generating text: \").lower() # Convert to lowercase for consistency\n",
768
- "\n",
769
- "# Ensure the input is at least 100 characters long by padding if needed\n",
770
- "if len(user_input) < sequence_length:\n",
771
- " user_input = ' ' * (sequence_length - len(user_input)) + user_input\n",
772
- "\n",
773
- "# Generate new text based on the user's input\n",
774
- "temperature = 0.8 # Adjust this value between 0.5 (more predictable) to 1.5 (more random)\n",
775
- "generated_text = generate_text_based_on_input(user_input, 500, temperature=temperature) # Generate 500 characters\n",
776
- "\n",
777
- "print(\"\\nGenerated Text:\\n\", generated_text)\n"
778
- ]
779
- },
780
- {
781
- "cell_type": "code",
782
- "execution_count": 2,
783
- "id": "36f0b201-9ff1-4c4d-b510-73b1952a4b55",
784
- "metadata": {},
785
- "outputs": [
786
- {
787
- "name": "stdout",
788
- "output_type": "stream",
789
- "text": [
790
- "Epoch 1/20\n",
791
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m8s\u001b[0m 63ms/step - loss: 2.9254\n",
792
- "Epoch 2/20\n",
793
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 2.2345\n",
794
- "Epoch 3/20\n",
795
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 60ms/step - loss: 2.0033\n",
796
- "Epoch 4/20\n",
797
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 60ms/step - loss: 1.8478\n",
798
- "Epoch 5/20\n",
799
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 62ms/step - loss: 1.7384\n",
800
- "Epoch 6/20\n",
801
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m7s\u001b[0m 63ms/step - loss: 1.6068\n",
802
- "Epoch 7/20\n",
803
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m7s\u001b[0m 63ms/step - loss: 1.4370\n",
804
- "Epoch 8/20\n",
805
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m7s\u001b[0m 63ms/step - loss: 1.3639\n",
806
- "Epoch 9/20\n",
807
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 1.2820\n",
808
- "Epoch 10/20\n",
809
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 1.1884\n",
810
- "Epoch 11/20\n",
811
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 1.0942\n",
812
- "Epoch 12/20\n",
813
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 1.0235\n",
814
- "Epoch 13/20\n",
815
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 0.9511\n",
816
- "Epoch 14/20\n",
817
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 0.9130\n",
818
- "Epoch 15/20\n",
819
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 60ms/step - loss: 0.8794\n",
820
- "Epoch 16/20\n",
821
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 0.7815\n",
822
- "Epoch 17/20\n",
823
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 0.7733\n",
824
- "Epoch 18/20\n",
825
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 60ms/step - loss: 0.7389\n",
826
- "Epoch 19/20\n",
827
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 61ms/step - loss: 0.6914\n",
828
- "Epoch 20/20\n",
829
- "\u001b[1m104/104\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m6s\u001b[0m 62ms/step - loss: 0.6546\n"
830
- ]
831
- },
832
- {
833
- "name": "stdin",
834
- "output_type": "stream",
835
- "text": [
836
- "Enter a seed text to start generating text: every step he took, is every step closer to danger, so he said his name was peter heisenberg and asked jesse pinkman to join in in his underworld job to\n"
837
- ]
838
- },
839
- {
840
- "name": "stdout",
841
- "output_type": "stream",
842
- "text": [
843
- "\n",
844
- "Generated Text:\n",
845
- " every step he took, is every step closer to danger, so he said his name was peter heisenberg and asked jesse pinkman to join in in his underworld job to me, and i had dines spaw the stars was a that i see terrible was tounderal as in the confession of mondings the envelope.\n",
846
- "\n",
847
- "m. poirel de little coughs of suppace, asoral not know bean society of the surfucs of the disuracidesiling to such of his one surfession of tongs who cannot ence, who beot her parents light!\n",
848
- "\n",
849
- "he dat daughtar. i cannot express mell the crib.\n",
850
- "\n",
851
- "hew was mother lay containing to one's sillel, gone that i delt terrible calsived, and ime aw a youcted her peppanion, this was sleeps\n"
852
- ]
853
- }
854
- ],
855
- "source": [
856
- "import numpy as np\n",
857
- "import tensorflow as tf\n",
858
- "from tensorflow.keras.models import Sequential\n",
859
- "from tensorflow.keras.layers import LSTM, Dense\n",
860
- "from tensorflow.keras.optimizers import Adam\n",
861
- "\n",
862
- "# Load and preprocess the data\n",
863
- "file_path = 'story.txt' # Path to your story.txt\n",
864
- "\n",
865
- "with open(file_path, 'r', encoding='utf-8') as file:\n",
866
- " text = file.read().lower() # Convert to lowercase for consistency\n",
867
- "\n",
868
- "# Create character-to-index and index-to-character mappings\n",
869
- "chars = sorted(list(set(text)))\n",
870
- "char_to_index = {c: i for i, c in enumerate(chars)}\n",
871
- "index_to_char = {i: c for i, c in enumerate(chars)}\n",
872
- "\n",
873
- "# Prepare the dataset\n",
874
- "sequence_length = 100\n",
875
- "sequences = []\n",
876
- "next_chars = []\n",
877
- "\n",
878
- "for i in range(0, len(text) - sequence_length, 1):\n",
879
- " sequences.append(text[i:i + sequence_length])\n",
880
- " next_chars.append(text[i + sequence_length])\n",
881
- "\n",
882
- "# Convert sequences to integer format\n",
883
- "X = np.zeros((len(sequences), sequence_length, len(chars)), dtype=bool)\n",
884
- "y = np.zeros((len(sequences), len(chars)), dtype=bool)\n",
885
- "\n",
886
- "for i, sequence in enumerate(sequences):\n",
887
- " for t, char in enumerate(sequence):\n",
888
- " X[i, t, char_to_index[char]] = 1\n",
889
- " y[i, char_to_index[next_chars[i]]] = 1\n",
890
- "\n",
891
- "# Build the LSTM model\n",
892
- "model = Sequential()\n",
893
- "model.add(LSTM(128, input_shape=(sequence_length, len(chars))))\n",
894
- "model.add(Dense(len(chars), activation='softmax'))\n",
895
- "\n",
896
- "# Compile the model\n",
897
- "model.compile(loss='categorical_crossentropy', optimizer=Adam(learning_rate=0.01))\n",
898
- "\n",
899
- "# Train the model\n",
900
- "model.fit(X, y, batch_size=128, epochs=20)\n",
901
- "\n",
902
- "# Function to apply temperature sampling\n",
903
- "def sample_with_temperature(preds, temperature=1.0):\n",
904
- " preds = np.asarray(preds).astype('float64')\n",
905
- " preds = np.log(preds + 1e-10) / temperature\n",
906
- " exp_preds = np.exp(preds)\n",
907
- " preds = exp_preds / np.sum(exp_preds)\n",
908
- " probas = np.random.multinomial(1, preds, 1)\n",
909
- " return np.argmax(probas)\n",
910
- "\n",
911
- "# Function to generate text based on user input with temperature\n",
912
- "def generate_text_based_on_input(seed, length=500, temperature=1.0):\n",
913
- " generated = seed\n",
914
- " for _ in range(length):\n",
915
- " x_pred = np.zeros((1, sequence_length, len(chars)))\n",
916
- " for t, char in enumerate(seed[-sequence_length:]):\n",
917
- " if char in char_to_index:\n",
918
- " x_pred[0, t, char_to_index[char]] = 1\n",
919
- " preds = model.predict(x_pred, verbose=0)[0]\n",
920
- " next_index = sample_with_temperature(preds, temperature)\n",
921
- " next_char = index_to_char[next_index]\n",
922
- "\n",
923
- " generated += next_char\n",
924
- " seed = seed[1:] + next_char\n",
925
- " return generated\n",
926
- "\n",
927
- "# Get user input\n",
928
- "user_input = input(\"Enter a seed text to start generating text: \").lower() # Convert to lowercase for consistency\n",
929
- "\n",
930
- "# Ensure the input is at least 100 characters long by padding if needed\n",
931
- "if len(user_input) < sequence_length:\n",
932
- " user_input = ' ' * (sequence_length - len(user_input)) + user_input\n",
933
- "\n",
934
- "# Generate new text based on the user's input\n",
935
- "temperature = 0.8 # Adjust this value between 0.5 (more predictable) to 1.5 (more random)\n",
936
- "generated_text = generate_text_based_on_input(user_input, 500, temperature=temperature) # Generate 500 characters\n",
937
- "\n",
938
- "print(\"\\nGenerated Text:\\n\", generated_text)\n"
939
- ]
940
- },
941
- {
942
- "cell_type": "code",
943
- "execution_count": 3,
944
- "id": "e7a5ca73-b0c1-4203-8784-29e66ac28d8f",
945
- "metadata": {},
946
- "outputs": [
947
- {
948
- "name": "stdout",
949
- "output_type": "stream",
950
- "text": [
951
- "Epoch 1/20\n",
952
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m5s\u001b[0m 62ms/step - loss: 3.0079\n",
953
- "Epoch 2/20\n",
954
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 61ms/step - loss: 2.4113\n",
955
- "Epoch 3/20\n",
956
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 61ms/step - loss: 2.0721\n",
957
- "Epoch 4/20\n",
958
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 61ms/step - loss: 1.7636\n",
959
- "Epoch 5/20\n",
960
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 60ms/step - loss: 1.5522\n",
961
- "Epoch 6/20\n",
962
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 61ms/step - loss: 1.3755\n",
963
- "Epoch 7/20\n",
964
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 60ms/step - loss: 1.1908\n",
965
- "Epoch 8/20\n",
966
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 62ms/step - loss: 1.0528\n",
967
- "Epoch 9/20\n",
968
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 60ms/step - loss: 0.9187\n",
969
- "Epoch 10/20\n",
970
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 61ms/step - loss: 0.8101\n",
971
- "Epoch 11/20\n",
972
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 61ms/step - loss: 0.7696\n",
973
- "Epoch 12/20\n",
974
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 62ms/step - loss: 0.6564\n",
975
- "Epoch 13/20\n",
976
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 61ms/step - loss: 0.5807\n",
977
- "Epoch 14/20\n",
978
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 62ms/step - loss: 0.5456\n",
979
- "Epoch 15/20\n",
980
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 61ms/step - loss: 0.4916\n",
981
- "Epoch 16/20\n",
982
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 62ms/step - loss: 0.4330\n",
983
- "Epoch 17/20\n",
984
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 61ms/step - loss: 0.4294\n",
985
- "Epoch 18/20\n",
986
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 61ms/step - loss: 0.3755\n",
987
- "Epoch 19/20\n",
988
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 61ms/step - loss: 0.3558\n",
989
- "Epoch 20/20\n",
990
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 64ms/step - loss: 0.3320\n"
991
- ]
992
- },
993
- {
994
- "name": "stdin",
995
- "output_type": "stream",
996
- "text": [
997
- "Enter a seed text to start generating text: AI-driven data visualization tools can automatically\n"
998
- ]
999
- },
1000
- {
1001
- "name": "stdout",
1002
- "output_type": "stream",
1003
- "text": [
1004
- "\n",
1005
- "Generated Text:\n",
1006
- " ai-driven data visualization tools can automatically generataly important that outcomes based on hast ai has tranigation.\n",
1007
- "\n",
1008
- "edge comons, and tagres, identify patterns. addations can the impact of ai in lea algorithms can prodising sociotes such as autofomation. techniques like straage to lights and trends intigting as, edeabled pledit or ai und sterat data science, which traising of the riskons, and preparation, advanced data visualizations based on the interactive databal complex risysns in the crakn souruted toolds and execument ai has suprers.\n",
1009
- "\n"
1010
- ]
1011
- }
1012
- ],
1013
- "source": [
1014
- "import numpy as np\n",
1015
- "import tensorflow as tf\n",
1016
- "from tensorflow.keras.models import Sequential\n",
1017
- "from tensorflow.keras.layers import LSTM, Dense\n",
1018
- "from tensorflow.keras.optimizers import Adam\n",
1019
- "\n",
1020
- "# Load and preprocess the data\n",
1021
- "file_path = 'text3.txt' # Path to your story.txt\n",
1022
- "\n",
1023
- "with open(file_path, 'r', encoding='utf-8') as file:\n",
1024
- " text = file.read().lower() # Convert to lowercase for consistency\n",
1025
- "\n",
1026
- "# Create character-to-index and index-to-character mappings\n",
1027
- "chars = sorted(list(set(text)))\n",
1028
- "char_to_index = {c: i for i, c in enumerate(chars)}\n",
1029
- "index_to_char = {i: c for i, c in enumerate(chars)}\n",
1030
- "\n",
1031
- "# Prepare the dataset\n",
1032
- "sequence_length = 100\n",
1033
- "sequences = []\n",
1034
- "next_chars = []\n",
1035
- "\n",
1036
- "for i in range(0, len(text) - sequence_length, 1):\n",
1037
- " sequences.append(text[i:i + sequence_length])\n",
1038
- " next_chars.append(text[i + sequence_length])\n",
1039
- "\n",
1040
- "# Convert sequences to integer format\n",
1041
- "X = np.zeros((len(sequences), sequence_length, len(chars)), dtype=bool)\n",
1042
- "y = np.zeros((len(sequences), len(chars)), dtype=bool)\n",
1043
- "\n",
1044
- "for i, sequence in enumerate(sequences):\n",
1045
- " for t, char in enumerate(sequence):\n",
1046
- " X[i, t, char_to_index[char]] = 1\n",
1047
- " y[i, char_to_index[next_chars[i]]] = 1\n",
1048
- "\n",
1049
- "# Build the LSTM model\n",
1050
- "model = Sequential()\n",
1051
- "model.add(LSTM(128, input_shape=(sequence_length, len(chars))))\n",
1052
- "model.add(Dense(len(chars), activation='softmax'))\n",
1053
- "\n",
1054
- "# Compile the model\n",
1055
- "model.compile(loss='categorical_crossentropy', optimizer=Adam(learning_rate=0.01))\n",
1056
- "\n",
1057
- "# Train the model\n",
1058
- "model.fit(X, y, batch_size=128, epochs=20)\n",
1059
- "\n",
1060
- "# Function to apply temperature sampling\n",
1061
- "def sample_with_temperature(preds, temperature=1.0):\n",
1062
- " preds = np.asarray(preds).astype('float64')\n",
1063
- " preds = np.log(preds + 1e-10) / temperature\n",
1064
- " exp_preds = np.exp(preds)\n",
1065
- " preds = exp_preds / np.sum(exp_preds)\n",
1066
- " probas = np.random.multinomial(1, preds, 1)\n",
1067
- " return np.argmax(probas)\n",
1068
- "\n",
1069
- "# Function to generate text based on user input with temperature\n",
1070
- "def generate_text_based_on_input(seed, length=500, temperature=1.0):\n",
1071
- " generated = seed\n",
1072
- " for _ in range(length):\n",
1073
- " x_pred = np.zeros((1, sequence_length, len(chars)))\n",
1074
- " for t, char in enumerate(seed[-sequence_length:]):\n",
1075
- " if char in char_to_index:\n",
1076
- " x_pred[0, t, char_to_index[char]] = 1\n",
1077
- " preds = model.predict(x_pred, verbose=0)[0]\n",
1078
- " next_index = sample_with_temperature(preds, temperature)\n",
1079
- " next_char = index_to_char[next_index]\n",
1080
- "\n",
1081
- " generated += next_char\n",
1082
- " seed = seed[1:] + next_char\n",
1083
- " return generated\n",
1084
- "\n",
1085
- "# Get user input\n",
1086
- "user_input = input(\"Enter a seed text to start generating text: \").lower() # Convert to lowercase for consistency\n",
1087
- "\n",
1088
- "# Ensure the input is at least 100 characters long by padding if needed\n",
1089
- "if len(user_input) < sequence_length:\n",
1090
- " user_input = ' ' * (sequence_length - len(user_input)) + user_input\n",
1091
- "\n",
1092
- "# Generate new text based on the user's input\n",
1093
- "temperature = 0.8 # Adjust this value between 0.5 (more predictable) to 1.5 (more random)\n",
1094
- "generated_text = generate_text_based_on_input(user_input, 500, temperature=temperature) # Generate 500 characters\n",
1095
- "\n",
1096
- "print(\"\\nGenerated Text:\\n\", generated_text)\n"
1097
- ]
1098
- },
1099
- {
1100
- "cell_type": "code",
1101
- "execution_count": 4,
1102
- "id": "d9f82657-ff95-41b4-a794-186864e4037f",
1103
- "metadata": {},
1104
- "outputs": [
1105
- {
1106
- "name": "stdout",
1107
- "output_type": "stream",
1108
- "text": [
1109
- "Epoch 1/20\n",
1110
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m5s\u001b[0m 63ms/step - loss: 3.0312\n",
1111
- "Epoch 2/20\n",
1112
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 59ms/step - loss: 2.4389\n",
1113
- "Epoch 3/20\n",
1114
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 60ms/step - loss: 2.0864\n",
1115
- "Epoch 4/20\n",
1116
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 60ms/step - loss: 1.8216\n",
1117
- "Epoch 5/20\n",
1118
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 60ms/step - loss: 1.5832\n",
1119
- "Epoch 6/20\n",
1120
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 60ms/step - loss: 1.3941\n",
1121
- "Epoch 7/20\n",
1122
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 60ms/step - loss: 1.2256\n",
1123
- "Epoch 8/20\n",
1124
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 60ms/step - loss: 1.0681\n",
1125
- "Epoch 9/20\n",
1126
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 60ms/step - loss: 0.9520\n",
1127
- "Epoch 10/20\n",
1128
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 61ms/step - loss: 0.8519\n",
1129
- "Epoch 11/20\n",
1130
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 62ms/step - loss: 0.7699\n",
1131
- "Epoch 12/20\n",
1132
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 61ms/step - loss: 0.6759\n",
1133
- "Epoch 13/20\n",
1134
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 60ms/step - loss: 0.6146\n",
1135
- "Epoch 14/20\n",
1136
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 61ms/step - loss: 0.5593\n",
1137
- "Epoch 15/20\n",
1138
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 60ms/step - loss: 0.5197\n",
1139
- "Epoch 16/20\n",
1140
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 61ms/step - loss: 0.4633\n",
1141
- "Epoch 17/20\n",
1142
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 60ms/step - loss: 0.4710\n",
1143
- "Epoch 18/20\n",
1144
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 61ms/step - loss: 0.3977\n",
1145
- "Epoch 19/20\n",
1146
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 61ms/step - loss: 0.3992\n",
1147
- "Epoch 20/20\n",
1148
- "\u001b[1m62/62\u001b[0m \u001b[32m━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[37m\u001b[0m \u001b[1m4s\u001b[0m 61ms/step - loss: 0.3407\n"
1149
- ]
1150
- },
1151
- {
1152
- "name": "stdin",
1153
- "output_type": "stream",
1154
- "text": [
1155
- "Enter a seed text to start generating text: improve and understand\n"
1156
- ]
1157
- },
1158
- {
1159
- "name": "stdout",
1160
- "output_type": "stream",
1161
- "text": [
1162
- "\n",
1163
- "Generated Text:\n",
1164
- " improve and understand a dredve spent on action.\n",
1165
- "\n",
1166
- "crighes in al this. the vast improved decisions within techniques in a surtiquer innovation\n",
1167
- "these tomly valuarly this can ai husting recolvential for making spess, aid techniquss bisting data science, which focuses on healthes and preparations. ai has transformed natural languate processing tevinion techniques can process can analyze machine learning and moces and trinssing processing inducting reclarization\n",
1168
- "tatked techniques tht requiremention\n",
1169
- "data visualization\n",
1170
- "data\n"
1171
- ]
1172
- }
1173
- ],
1174
- "source": [
1175
- "import numpy as np\n",
1176
- "import tensorflow as tf\n",
1177
- "from tensorflow.keras.models import Sequential\n",
1178
- "from tensorflow.keras.layers import LSTM, Dense\n",
1179
- "from tensorflow.keras.optimizers import Adam\n",
1180
- "\n",
1181
- "# Load and preprocess the data\n",
1182
- "file_path = 'text3.txt' # Path to your story.txt\n",
1183
- "\n",
1184
- "with open(file_path, 'r', encoding='utf-8') as file:\n",
1185
- " text = file.read().lower() # Convert to lowercase for consistency\n",
1186
- "\n",
1187
- "# Create character-to-index and index-to-character mappings\n",
1188
- "chars = sorted(list(set(text)))\n",
1189
- "char_to_index = {c: i for i, c in enumerate(chars)}\n",
1190
- "index_to_char = {i: c for i, c in enumerate(chars)}\n",
1191
- "\n",
1192
- "# Prepare the dataset\n",
1193
- "sequence_length = 100\n",
1194
- "sequences = []\n",
1195
- "next_chars = []\n",
1196
- "\n",
1197
- "for i in range(0, len(text) - sequence_length, 1):\n",
1198
- " sequences.append(text[i:i + sequence_length])\n",
1199
- " next_chars.append(text[i + sequence_length])\n",
1200
- "\n",
1201
- "# Convert sequences to integer format\n",
1202
- "X = np.zeros((len(sequences), sequence_length, len(chars)), dtype=bool)\n",
1203
- "y = np.zeros((len(sequences), len(chars)), dtype=bool)\n",
1204
- "\n",
1205
- "for i, sequence in enumerate(sequences):\n",
1206
- " for t, char in enumerate(sequence):\n",
1207
- " X[i, t, char_to_index[char]] = 1\n",
1208
- " y[i, char_to_index[next_chars[i]]] = 1\n",
1209
- "\n",
1210
- "# Build the LSTM model\n",
1211
- "model = Sequential()\n",
1212
- "model.add(LSTM(128, input_shape=(sequence_length, len(chars))))\n",
1213
- "model.add(Dense(len(chars), activation='softmax'))\n",
1214
- "\n",
1215
- "# Compile the model\n",
1216
- "model.compile(loss='categorical_crossentropy', optimizer=Adam(learning_rate=0.01))\n",
1217
- "\n",
1218
- "# Train the model\n",
1219
- "model.fit(X, y, batch_size=128, epochs=20)\n",
1220
- "\n",
1221
- "# Function to apply temperature sampling\n",
1222
- "def sample_with_temperature(preds, temperature=1.0):\n",
1223
- " preds = np.asarray(preds).astype('float64')\n",
1224
- " preds = np.log(preds + 1e-10) / temperature\n",
1225
- " exp_preds = np.exp(preds)\n",
1226
- " preds = exp_preds / np.sum(exp_preds)\n",
1227
- " probas = np.random.multinomial(1, preds, 1)\n",
1228
- " return np.argmax(probas)\n",
1229
- "\n",
1230
- "# Function to generate text based on user input with temperature\n",
1231
- "def generate_text_based_on_input(seed, length=500, temperature=1.0):\n",
1232
- " generated = seed\n",
1233
- " for _ in range(length):\n",
1234
- " x_pred = np.zeros((1, sequence_length, len(chars)))\n",
1235
- " for t, char in enumerate(seed[-sequence_length:]):\n",
1236
- " if char in char_to_index:\n",
1237
- " x_pred[0, t, char_to_index[char]] = 1\n",
1238
- " preds = model.predict(x_pred, verbose=0)[0]\n",
1239
- " next_index = sample_with_temperature(preds, temperature)\n",
1240
- " next_char = index_to_char[next_index]\n",
1241
- "\n",
1242
- " generated += next_char\n",
1243
- " seed = seed[1:] + next_char\n",
1244
- " return generated\n",
1245
- "\n",
1246
- "# Get user input\n",
1247
- "user_input = input(\"Enter a seed text to start generating text: \").lower() # Convert to lowercase for consistency\n",
1248
- "\n",
1249
- "# Ensure the input is at least 100 characters long by padding if needed\n",
1250
- "if len(user_input) < sequence_length:\n",
1251
- " user_input = ' ' * (sequence_length - len(user_input)) + user_input\n",
1252
- "\n",
1253
- "# Generate new text based on the user's input\n",
1254
- "temperature = 0.8 # Adjust this value between 0.5 (more predictable) to 1.5 (more random)\n",
1255
- "generated_text = generate_text_based_on_input(user_input, 500, temperature=temperature) # Generate 500 characters\n",
1256
- "\n",
1257
- "print(\"\\nGenerated Text:\\n\", generated_text)\n"
1258
- ]
1259
- },
1260
- {
1261
- "cell_type": "code",
1262
- "execution_count": null,
1263
- "id": "84b8bddc-ed76-47c2-8c42-10193d55ac03",
1264
- "metadata": {},
1265
- "outputs": [],
1266
- "source": []
1267
- }
1268
- ],
1269
- "metadata": {
1270
- "kernelspec": {
1271
- "display_name": "Python 3 (ipykernel)",
1272
- "language": "python",
1273
- "name": "python3"
1274
- },
1275
- "language_info": {
1276
- "codemirror_mode": {
1277
- "name": "ipython",
1278
- "version": 3
1279
- },
1280
- "file_extension": ".py",
1281
- "mimetype": "text/x-python",
1282
- "name": "python",
1283
- "nbconvert_exporter": "python",
1284
- "pygments_lexer": "ipython3",
1285
- "version": "3.11.7"
1286
- }
1287
- },
1288
- "nbformat": 4,
1289
- "nbformat_minor": 5
1290
- }