Sun Dec 15 21:49:01 2024 imdb(): python version: 3.10.12 numpy version: 1.26.4 tensorflow version: 2.16.1 Use a neural network to classify movie reviews as negative (0) or positive (1) based on the usage of the 1000 most common words. Sample training data #0: [1, 14, 22, 16, 43, 530, 973, 2, 2, 65, 458, 2, 66, 2, 4, 173, 36, 256, 5, 25, 100, 43, 838, 112, 50, 670, 2, 9, 35, 480, 284, 5, 150, 4, 172, 112, 167, 2, 336, 385, 39, 4, 172, 2, 2, 17, 546, 38, 13, 447, 4, 192, 50, 16, 6, 147, 2, 19, 14, 22, 4, 2, 2, 469, 4, 22, 71, 87, 12, 16, 43, 530, 38, 76, 15, 13, 2, 4, 22, 17, 515, 17, 12, 16, 626, 18, 2, 5, 62, 386, 12, 8, 316, 8, 106, 5, 4, 2, 2, 16, 480, 66, 2, 33, 4, 130, 12, 16, 38, 619, 5, 25, 124, 51, 36, 135, 48, 25, 2, 33, 6, 22, 12, 215, 28, 77, 52, 5, 14, 407, 16, 82, 2, 8, 4, 107, 117, 2, 15, 256, 4, 2, 7, 2, 5, 723, 36, 71, 43, 530, 476, 26, 400, 317, 46, 7, 4, 2, 2, 13, 104, 88, 4, 381, 15, 297, 98, 32, 2, 56, 26, 141, 6, 194, 2, 18, 4, 226, 22, 21, 134, 476, 26, 480, 5, 144, 30, 2, 18, 51, 36, 28, 224, 92, 25, 104, 4, 226, 65, 16, 38, 2, 88, 12, 16, 283, 5, 16, 2, 113, 103, 32, 15, 16, 2, 19, 178, 32] Label for sample training data #0: 1 Maximum index in training data is 999 Sample training data #0 after vectorization: [1, 14, 22, 16, 43, 530, 973, 2, 2, 65, 458, 2, 66, 2, 4, 173, 36, 256, 5, 25, 100, 43, 838, 112, 50, 670, 2, 9, 35, 480, 284, 5, 150, 4, 172, 112, 167, 2, 336, 385, 39, 4, 172, 2, 2, 17, 546, 38, 13, 447, 4, 192, 50, 16, 6, 147, 2, 19, 14, 22, 4, 2, 2, 469, 4, 22, 71, 87, 12, 16, 43, 530, 38, 76, 15, 13, 2, 4, 22, 17, 515, 17, 12, 16, 626, 18, 2, 5, 62, 386, 12, 8, 316, 8, 106, 5, 4, 2, 2, 16, 480, 66, 2, 33, 4, 130, 12, 16, 38, 619, 5, 25, 124, 51, 36, 135, 48, 25, 2, 33, 6, 22, 12, 215, 28, 77, 52, 5, 14, 407, 16, 82, 2, 8, 4, 107, 117, 2, 15, 256, 4, 2, 7, 2, 5, 723, 36, 71, 43, 530, 476, 26, 400, 317, 46, 7, 4, 2, 2, 13, 104, 88, 4, 381, 15, 297, 98, 32, 2, 56, 26, 141, 6, 194, 2, 18, 4, 226, 22, 21, 134, 476, 26, 480, 5, 144, 30, 2, 18, 51, 36, 28, 224, 92, 25, 104, 4, 226, 65, 16, 38, 2, 88, 12, 16, 283, 5, 16, 2, 113, 103, 32, 15, 16, 2, 19, 178, 32] Label for sample training data #0: 1 Epoch 1/20  1/30 ━━━━━━━━━━━━━━━━━━━━ 21s 757ms/step - accuracy: 0.4941 - loss: 0.6938  8/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.5548 - loss: 0.6871  16/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.6011 - loss: 0.6743 25/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.6391 - loss: 0.6588 30/30 ━━━━━━━━━━━━━━━━━━━━ 1s 25ms/step - accuracy: 0.6575 - loss: 0.6490 - val_accuracy: 0.8206 - val_loss: 0.5107 Epoch 2/20  1/30 ━━━━━━━━━━━━━━━━━━━━ 1s 38ms/step - accuracy: 0.8379 - loss: 0.5036  9/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8298 - loss: 0.4963  17/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8309 - loss: 0.4878 26/30 ━━━━━━━━━━━━━━━━━━━━ 0s 6ms/step - accuracy: 0.8324 - loss: 0.4792 30/30 ━━━━━━━━━━━━━━━━━━━━ 0s 10ms/step - accuracy: 0.8332 - loss: 0.4748 - val_accuracy: 0.8079 - val_loss: 0.4377 Epoch 3/20  1/30 ━━━━━━━━━━━━━━━━━━━━ 1s 44ms/step - accuracy: 0.8086 - loss: 0.4412  8/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8394 - loss: 0.4130  16/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8483 - loss: 0.3976 25/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8507 - loss: 0.3907 30/30 ━━━━━━━━━━━━━━━━━━━━ 0s 10ms/step - accuracy: 0.8517 - loss: 0.3876 - val_accuracy: 0.8506 - val_loss: 0.3609 Epoch 4/20  1/30 ━━━━━━━━━━━━━━━━━━━━ 1s 51ms/step - accuracy: 0.8828 - loss: 0.3091  8/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8658 - loss: 0.3364  15/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8657 - loss: 0.3385 23/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8649 - loss: 0.3394 30/30 ━━━━━━━━━━━━━━━━━━━━ 0s 10ms/step - accuracy: 0.8643 - loss: 0.3394 - val_accuracy: 0.8552 - val_loss: 0.3425 Epoch 5/20  1/30 ━━━━━━━━━━━━━━━━━━━━ 1s 45ms/step - accuracy: 0.8809 - loss: 0.2975  8/30 ━━━━━━━━━━━━━━━━━━━━ 0s 8ms/step - accuracy: 0.8734 - loss: 0.3121  15/30 ━━━━━━━━━━━━━━━━━━━━ 0s 8ms/step - accuracy: 0.8751 - loss: 0.3124 22/30 ━━━━━━━━━━━━━━━━━━━━ 0s 8ms/step - accuracy: 0.8749 - loss: 0.3140 30/30 ━━━━━━━━━━━━━━━━━━━━ 0s 11ms/step - accuracy: 0.8737 - loss: 0.3160 - val_accuracy: 0.8585 - val_loss: 0.3381 Epoch 6/20  1/30 ━━━━━━━━━━━━━━━━━━━━ 1s 43ms/step - accuracy: 0.8828 - loss: 0.2998  8/30 ━━━━━━━━━━━━━━━━━━━━ 0s 8ms/step - accuracy: 0.8761 - loss: 0.3020  16/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8735 - loss: 0.3070 24/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8739 - loss: 0.3075 30/30 ━━━━━━━━━━━━━━━━━━━━ 0s 11ms/step - accuracy: 0.8738 - loss: 0.3078 - val_accuracy: 0.8602 - val_loss: 0.3334 Epoch 7/20  1/30 ━━━━━━━━━━━━━━━━━━━━ 1s 58ms/step - accuracy: 0.8926 - loss: 0.2734  7/30 ━━━━━━━━━━━━━━━━━━━━ 0s 9ms/step - accuracy: 0.8775 - loss: 0.3019  13/30 ━━━━━━━━━━━━━━━━━━━━ 0s 9ms/step - accuracy: 0.8765 - loss: 0.3045 20/30 ━━━━━━━━━━━━━━━━━━━━ 0s 8ms/step - accuracy: 0.8773 - loss: 0.3030 29/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8776 - loss: 0.3024 30/30 ━━━━━━━━━━━━━━━━━━━━ 0s 11ms/step - accuracy: 0.8776 - loss: 0.3025 - val_accuracy: 0.8521 - val_loss: 0.3544 Epoch 8/20  1/30 ━━━━━━━━━━━━━━━━━━━━ 1s 42ms/step - accuracy: 0.8535 - loss: 0.3281  8/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8697 - loss: 0.3093  15/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8719 - loss: 0.3054 23/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8737 - loss: 0.3021 30/30 ━━━━━━━━━━━━━━━━━━━━ 0s 10ms/step - accuracy: 0.8741 - loss: 0.3017 - val_accuracy: 0.8533 - val_loss: 0.3469 Epoch 9/20  1/30 ━━━━━━━━━━━━━━━━━━━━ 1s 50ms/step - accuracy: 0.8496 - loss: 0.3161  7/30 ━━━━━━━━━━━━━━━━━━━━ 0s 9ms/step - accuracy: 0.8736 - loss: 0.2888  14/30 ━━━━━━━━━━━━━━━━━━━━ 0s 9ms/step - accuracy: 0.8781 - loss: 0.2870 21/30 ━━━━━━━━━━━━━━━━━━━━ 0s 8ms/step - accuracy: 0.8785 - loss: 0.2895 29/30 ━━━━━━━━━━━━━━━━━━━━ 0s 8ms/step - accuracy: 0.8783 - loss: 0.2913 30/30 ━━━━━━━━━━━━━━━━━━━━ 0s 11ms/step - accuracy: 0.8782 - loss: 0.2916 - val_accuracy: 0.8389 - val_loss: 0.3871 Epoch 10/20  1/30 ━━━━━━━━━━━━━━━━━━━━ 1s 61ms/step - accuracy: 0.8672 - loss: 0.3075  8/30 ━━━━━━━━━━━━━━━━━━━━ 0s 9ms/step - accuracy: 0.8768 - loss: 0.2896  16/30 ━━━━━━━━━━━━━━━━━━━━ 0s 8ms/step - accuracy: 0.8794 - loss: 0.2870 25/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8794 - loss: 0.2889 30/30 ━━━━━━━━━━━━━━━━━━━━ 0s 11ms/step - accuracy: 0.8795 - loss: 0.2898 - val_accuracy: 0.8607 - val_loss: 0.3373 Epoch 11/20  1/30 ━━━━━━━━━━━━━━━━━━━━ 1s 47ms/step - accuracy: 0.8750 - loss: 0.2720  8/30 ━━━━━━━━━━━━━━━━━━━━ 0s 8ms/step - accuracy: 0.8728 - loss: 0.2882  15/30 ━━━━━━━━━━━━━━━━━━━━ 0s 8ms/step - accuracy: 0.8751 - loss: 0.2905 23/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8761 - loss: 0.2914 30/30 ━━━━━━━━━━━━━━━━━━━━ 0s 10ms/step - accuracy: 0.8762 - loss: 0.2922 - val_accuracy: 0.8591 - val_loss: 0.3383 Epoch 12/20  1/30 ━━━━━━━━━━━━━━━━━━━━ 1s 46ms/step - accuracy: 0.8984 - loss: 0.2576  8/30 ━━━━━━━━━━━━━━━━━━━━ 0s 8ms/step - accuracy: 0.8837 - loss: 0.2825  15/30 ━━━━━━━━━━━━━━━━━━━━ 0s 8ms/step - accuracy: 0.8824 - loss: 0.2832 23/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8814 - loss: 0.2847 30/30 ━━━━━━━━━━━━━━━━━━━━ 0s 11ms/step - accuracy: 0.8805 - loss: 0.2869 - val_accuracy: 0.8580 - val_loss: 0.3418 Epoch 13/20  1/30 ━━━━━━━━━━━━━━━━━━━━ 1s 53ms/step - accuracy: 0.8711 - loss: 0.3140  7/30 ━━━━━━━━━━━━━━━━━━━━ 0s 8ms/step - accuracy: 0.8819 - loss: 0.2893  14/30 ━━━━━━━━━━━━━━━━━━━━ 0s 8ms/step - accuracy: 0.8821 - loss: 0.2888 22/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8818 - loss: 0.2887 30/30 ━━━━━━━━━━━━━━━━━━━━ 0s 10ms/step - accuracy: 0.8812 - loss: 0.2895 - val_accuracy: 0.8569 - val_loss: 0.3438 Epoch 14/20  1/30 ━━━━━━━━━━━━━━━━━━━━ 1s 49ms/step - accuracy: 0.8594 - loss: 0.3056  8/30 ━━━━━━━━━━━━━━━━━━━━ 0s 8ms/step - accuracy: 0.8803 - loss: 0.2809  15/30 ━━━━━━━━━━━━━━━━━━━━ 0s 8ms/step - accuracy: 0.8817 - loss: 0.2802 23/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8812 - loss: 0.2814 30/30 ━━━━━━━━━━━━━━━━━━━━ 0s 10ms/step - accuracy: 0.8807 - loss: 0.2831 - val_accuracy: 0.8441 - val_loss: 0.3792 Epoch 15/20  1/30 ━━━━━━━━━━━━━━━━━━━━ 1s 48ms/step - accuracy: 0.8711 - loss: 0.3013  8/30 ━━━━━━━━━━━━━━━━━━━━ 0s 8ms/step - accuracy: 0.8788 - loss: 0.2920  15/30 ━━━━━━━━━━━━━━━━━━━━ 0s 8ms/step - accuracy: 0.8788 - loss: 0.2924 23/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8791 - loss: 0.2907 30/30 ━━━━━━━━━━━━━━━━━━━━ 0s 11ms/step - accuracy: 0.8794 - loss: 0.2902 - val_accuracy: 0.8586 - val_loss: 0.3431 Epoch 16/20  1/30 ━━━━━━━━━━━━━━━━━━━━ 1s 46ms/step - accuracy: 0.9043 - loss: 0.2544  7/30 ━━━━━━━━━━━━━━━━━━━━ 0s 8ms/step - accuracy: 0.8982 - loss: 0.2605  14/30 ━━━━━━━━━━━━━━━━━━━━ 0s 8ms/step - accuracy: 0.8927 - loss: 0.2673 21/30 ━━━━━━━━━━━━━━━━━━━━ 0s 8ms/step - accuracy: 0.8892 - loss: 0.2724 30/30 ━━━━━━━━━━━━━━━━━━━━ 0s 11ms/step - accuracy: 0.8864 - loss: 0.2771 - val_accuracy: 0.8534 - val_loss: 0.3625 Epoch 17/20  1/30 ━━━━━━━━━━━━━━━━━━━━ 1s 48ms/step - accuracy: 0.8750 - loss: 0.2720  8/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8867 - loss: 0.2690  16/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8873 - loss: 0.2721 24/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8865 - loss: 0.2753 30/30 ━━━━━━━━━━━━━━━━━━━━ 0s 10ms/step - accuracy: 0.8856 - loss: 0.2772 - val_accuracy: 0.8581 - val_loss: 0.3481 Epoch 18/20  1/30 ━━━━━━━━━━━━━━━━━━━━ 1s 36ms/step - accuracy: 0.8887 - loss: 0.2846  8/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8913 - loss: 0.2702  16/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8858 - loss: 0.2787 25/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8844 - loss: 0.2801 30/30 ━━━━━━━━━━━━━━━━━━━━ 0s 10ms/step - accuracy: 0.8839 - loss: 0.2806 - val_accuracy: 0.8585 - val_loss: 0.3464 Epoch 19/20  1/30 ━━━━━━━━━━━━━━━━━━━━ 1s 51ms/step - accuracy: 0.8926 - loss: 0.2741  8/30 ━━━━━━━━━━━━━━━━━━━━ 0s 8ms/step - accuracy: 0.8810 - loss: 0.2932  16/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8821 - loss: 0.2902 24/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8824 - loss: 0.2877 30/30 ━━━━━━━━━━━━━━━━━━━━ 0s 10ms/step - accuracy: 0.8828 - loss: 0.2861 - val_accuracy: 0.8564 - val_loss: 0.3481 Epoch 20/20  1/30 ━━━━━━━━━━━━━━━━━━━━ 1s 46ms/step - accuracy: 0.8965 - loss: 0.2552  8/30 ━━━━━━━━━━━━━━━━━━━━ 0s 8ms/step - accuracy: 0.8815 - loss: 0.2810  15/30 ━━━━━━━━━━━━━━━━━━━━ 0s 8ms/step - accuracy: 0.8809 - loss: 0.2831 23/30 ━━━━━━━━━━━━━━━━━━━━ 0s 7ms/step - accuracy: 0.8817 - loss: 0.2830 30/30 ━━━━━━━━━━━━━━━━━━━━ 0s 11ms/step - accuracy: 0.8824 - loss: 0.2823 - val_accuracy: 0.8480 - val_loss: 0.3779 Model loss and accuracy on validation data: Final validation loss 0.377914160490036 Final validation accuracy 0.8479999899864197 Test the model:  1/782 ━━━━━━━━━━━━━━━━━━━━ 16s 21ms/step - accuracy: 0.7812 - loss: 0.4636  53/782 ━━━━━━━━━━━━━━━━━━━━ 0s 967us/step - accuracy: 0.8425 - loss: 0.3691 110/782 ━━━━━━━━━━━━━━━━━━━━ 0s 923us/step - accuracy: 0.8373 - loss: 0.3808 167/782 ━━━━━━━━━━━━━━━━━━━━ 0s 911us/step - accuracy: 0.8359 - loss: 0.3882 223/782 ━━━━━━━━━━━━━━━━━━━━ 0s 908us/step - accuracy: 0.8351 - loss: 0.3912 282/782 ━━━━━━━━━━━━━━━━━━━━ 0s 898us/step - accuracy: 0.8350 - loss: 0.3918 339/782 ━━━━━━━━━━━━━━━━━━━━ 0s 894us/step - accuracy: 0.8352 - loss: 0.3915 398/782 ━━━━━━━━━━━━━━━━━━━━ 0s 888us/step - accuracy: 0.8354 - loss: 0.3916 456/782 ━━━━━━━━━━━━━━━━━━━━ 0s 885us/step - accuracy: 0.8355 - loss: 0.3916 515/782 ━━━━━━━━━━━━━━━━━━━━ 0s 882us/step - accuracy: 0.8357 - loss: 0.3916 575/782 ━━━━━━━━━━━━━━━━━━━━ 0s 878us/step - accuracy: 0.8358 - loss: 0.3915 635/782 ━━━━━━━━━━━━━━━━━━━━ 0s 875us/step - accuracy: 0.8363 - loss: 0.3909 693/782 ━━━━━━━━━━━━━━━━━━━━ 0s 874us/step - accuracy: 0.8367 - loss: 0.3903 753/782 ━━━━━━━━━━━━━━━━━━━━ 0s 871us/step - accuracy: 0.8371 - loss: 0.3895 782/782 ━━━━━━━━━━━━━━━━━━━━ 1s 870us/step - accuracy: 0.8373 - loss: 0.3892 Model loss and accuracy on test data: loss 0.3805773854255676 compile_metrics 0.8423600196838379  1/782 ━━━━━━━━━━━━━━━━━━━━ 28s 36ms/step  39/782 ━━━━━━━━━━━━━━━━━━━━ 0s 1ms/step  101/782 ━━━━━━━━━━━━━━━━━━━━ 0s 1ms/step 167/782 ━━━━━━━━━━━━━━━━━━━━ 0s 907us/step 236/782 ━━━━━━━━━━━━━━━━━━━━ 0s 855us/step 306/782 ━━━━━━━━━━━━━━━━━━━━ 0s 823us/step 376/782 ━━━━━━━━━━━━━━━━━━━━ 0s 804us/step 444/782 ━━━━━━━━━━━━━━━━━━━━ 0s 794us/step 513/782 ━━━━━━━━━━━━━━━━━━━━ 0s 786us/step 582/782 ━━━━━━━━━━━━━━━━━━━━ 0s 778us/step 649/782 ━━━━━━━━━━━━━━━━━━━━ 0s 776us/step 714/782 ━━━━━━━━━━━━━━━━━━━━ 0s 775us/step 782/782 ━━━━━━━━━━━━━━━━━━━━ 0s 796us/step 782/782 ━━━━━━━━━━━━━━━━━━━━ 1s 796us/step Model predictions on first 20 test movie reviews: # Predict Actual 0 0.3835 0 1 0.9982 1 2 0.8903 1 3 0.8954 0 4 0.9264 1 5 0.9042 1 6 0.9991 1 7 0.0208 0 8 0.9768 0 9 0.9743 1 10 0.9059 1 11 0.0067 0 12 0.0343 0 13 0.4391 0 14 0.9929 1 15 0.0030 0 16 0.9649 1 17 0.8806 0 18 0.0135 0 19 0.0548 0 imdb(): Normal end of execution. Sun Dec 15 21:49:19 2024