TensorFlow हब के साथ टेक्स्ट वर्गीकरण: मूवी समीक्षा

TensorFlow.org पर देखें Google Colab में चलाएं गिटहब पर देखें नोटबुक डाउनलोड करें TF हब मॉडल देखें

यह नोटबुक समीक्षा के टेक्स्ट का उपयोग करके मूवी समीक्षाओं को सकारात्मक या नकारात्मक के रूप में वर्गीकृत करती है। यह बाइनरी -या टू-क्लास-वर्गीकरण का एक उदाहरण है, जो एक महत्वपूर्ण और व्यापक रूप से लागू होने वाली मशीन सीखने की समस्या है।

ट्यूटोरियल TensorFlow हब और केरस के साथ स्थानांतरण सीखने के मूल अनुप्रयोग को प्रदर्शित करता है।

यह IMDB डेटासेट का उपयोग करता है जिसमें इंटरनेट मूवी डेटाबेस से 50,000 मूवी समीक्षाओं का टेक्स्ट होता है। इन्हें प्रशिक्षण के लिए 25,000 समीक्षाओं और परीक्षण के लिए 25,000 समीक्षाओं में विभाजित किया गया है। प्रशिक्षण और परीक्षण सेट संतुलित हैं, जिसका अर्थ है कि उनमें समान संख्या में सकारात्मक और नकारात्मक समीक्षाएं हैं।

यह नोटबुक tf.keras का उपयोग करता है, जो TensorFlow में मॉडल बनाने और प्रशिक्षित करने के लिए एक उच्च-स्तरीय API है, और tensorflow_hub , कोड की एक पंक्ति में TFHub से प्रशिक्षित मॉडल लोड करने के लिए एक पुस्तकालय है। tf.keras का उपयोग करके अधिक उन्नत टेक्स्ट वर्गीकरण ट्यूटोरियल के लिए, MLCC टेक्स्ट क्लासिफिकेशन गाइड देखें।

pip install tensorflow-hub
pip install tensorflow-datasets
import os
import numpy as np

import tensorflow as tf
import tensorflow_hub as hub
import tensorflow_datasets as tfds

print("Version: ", tf.__version__)
print("Eager mode: ", tf.executing_eagerly())
print("Hub version: ", hub.__version__)
print("GPU is", "available" if tf.config.list_physical_devices("GPU") else "NOT AVAILABLE")
Version:  2.8.0-rc1
Eager mode:  True
Hub version:  0.12.0
GPU is available

IMDB डेटासेट डाउनलोड करें

IMDB डेटासेट imdb समीक्षाओं पर या TensorFlow डेटासेट पर उपलब्ध है। निम्न कोड IMDB डेटासेट को आपकी मशीन (या कोलाब रनटाइम) पर डाउनलोड करता है:

# Split the training set into 60% and 40% to end up with 15,000 examples
# for training, 10,000 examples for validation and 25,000 examples for testing.
train_data, validation_data, test_data = tfds.load(
    split=('train[:60%]', 'train[60%:]', 'test'),

डेटा का अन्वेषण करें

आइए डेटा के प्रारूप को समझने के लिए कुछ समय निकालें। प्रत्येक उदाहरण फिल्म समीक्षा और संबंधित लेबल का प्रतिनिधित्व करने वाला एक वाक्य है। वाक्य किसी भी तरह से पूर्वसंसाधित नहीं है। लेबल या तो 0 या 1 का पूर्णांक मान है, जहां 0 एक नकारात्मक समीक्षा है, और 1 एक सकारात्मक समीक्षा है।

आइए पहले 10 उदाहरण प्रिंट करें।

train_examples_batch, train_labels_batch = next(iter(train_data.batch(10)))
<tf.Tensor: shape=(10,), dtype=string, numpy=
array([b"This was an absolutely terrible movie. Don't be lured in by Christopher Walken or Michael Ironside. Both are great actors, but this must simply be their worst role in history. Even their great acting could not redeem this movie's ridiculous storyline. This movie is an early nineties US propaganda piece. The most pathetic scenes were those when the Columbian rebels were making their cases for revolutions. Maria Conchita Alonso appeared phony, and her pseudo-love affair with Walken was nothing but a pathetic emotional plug in a movie that was devoid of any real meaning. I am disappointed that there are movies like this, ruining actor's like Christopher Walken's good name. I could barely sit through it.",
       b'I have been known to fall asleep during films, but this is usually due to a combination of things including, really tired, being warm and comfortable on the sette and having just eaten a lot. However on this occasion I fell asleep because the film was rubbish. The plot development was constant. Constantly slow and boring. Things seemed to happen, but with no explanation of what was causing them or why. I admit, I may have missed part of the film, but i watched the majority of it and everything just seemed to happen of its own accord without any real concern for anything else. I cant recommend this film at all.',
       b'Mann photographs the Alberta Rocky Mountains in a superb fashion, and Jimmy Stewart and Walter Brennan give enjoyable performances as they always seem to do. <br /><br />But come on Hollywood - a Mountie telling the people of Dawson City, Yukon to elect themselves a marshal (yes a marshal!) and to enforce the law themselves, then gunfighters battling it out on the streets for control of the town? <br /><br />Nothing even remotely resembling that happened on the Canadian side of the border during the Klondike gold rush. Mr. Mann and company appear to have mistaken Dawson City for Deadwood, the Canadian North for the American Wild West.<br /><br />Canadian viewers be prepared for a Reefer Madness type of enjoyable howl with this ludicrous plot, or, to shake your head in disgust.',
       b'This is the kind of film for a snowy Sunday afternoon when the rest of the world can go ahead with its own business as you descend into a big arm-chair and mellow for a couple of hours. Wonderful performances from Cher and Nicolas Cage (as always) gently row the plot along. There are no rapids to cross, no dangerous waters, just a warm and witty paddle through New York life at its best. A family film in every sense and one that deserves the praise it received.',
       b'As others have mentioned, all the women that go nude in this film are mostly absolutely gorgeous. The plot very ably shows the hypocrisy of the female libido. When men are around they want to be pursued, but when no "men" are around, they become the pursuers of a 14 year old boy. And the boy becomes a man really fast (we should all be so lucky at this age!). He then gets up the courage to pursue his true love.',
       b"This is a film which should be seen by anybody interested in, effected by, or suffering from an eating disorder. It is an amazingly accurate and sensitive portrayal of bulimia in a teenage girl, its causes and its symptoms. The girl is played by one of the most brilliant young actresses working in cinema today, Alison Lohman, who was later so spectacular in 'Where the Truth Lies'. I would recommend that this film be shown in all schools, as you will never see a better on this subject. Alison Lohman is absolutely outstanding, and one marvels at her ability to convey the anguish of a girl suffering from this compulsive disorder. If barometers tell us the air pressure, Alison Lohman tells us the emotional pressure with the same degree of accuracy. Her emotional range is so precise, each scene could be measured microscopically for its gradations of trauma, on a scale of rising hysteria and desperation which reaches unbearable intensity. Mare Winningham is the perfect choice to play her mother, and does so with immense sympathy and a range of emotions just as finely tuned as Lohman's. Together, they make a pair of sensitive emotional oscillators vibrating in resonance with one another. This film is really an astonishing achievement, and director Katt Shea should be proud of it. The only reason for not seeing it is if you are not interested in people. But even if you like nature films best, this is after all animal behaviour at the sharp edge. Bulimia is an extreme version of how a tormented soul can destroy her own body in a frenzy of despair. And if we don't sympathise with people suffering from the depths of despair, then we are dead inside.",
       b'Okay, you have:<br /><br />Penelope Keith as Miss Herringbone-Tweed, B.B.E. (Backbone of England.) She\'s killed off in the first scene - that\'s right, folks; this show has no backbone!<br /><br />Peter O\'Toole as Ol\' Colonel Cricket from The First War and now the emblazered Lord of the Manor.<br /><br />Joanna Lumley as the ensweatered Lady of the Manor, 20 years younger than the colonel and 20 years past her own prime but still glamourous (Brit spelling, not mine) enough to have a toy-boy on the side. It\'s alright, they have Col. Cricket\'s full knowledge and consent (they guy even comes \'round for Christmas!) Still, she\'s considerate of the colonel enough to have said toy-boy her own age (what a gal!)<br /><br />David McCallum as said toy-boy, equally as pointlessly glamourous as his squeeze. Pilcher couldn\'t come up with any cover for him within the story, so she gave him a hush-hush job at the Circus.<br /><br />and finally:<br /><br />Susan Hampshire as Miss Polonia Teacups, Venerable Headmistress of the Venerable Girls\' Boarding-School, serving tea in her office with a dash of deep, poignant advice for life in the outside world just before graduation. Her best bit of advice: "I\'ve only been to Nancherrow (the local Stately Home of England) once. I thought it was very beautiful but, somehow, not part of the real world." Well, we can\'t say they didn\'t warn us.<br /><br />Ah, Susan - time was, your character would have been running the whole show. They don\'t write \'em like that any more. Our loss, not yours.<br /><br />So - with a cast and setting like this, you have the re-makings of "Brideshead Revisited," right?<br /><br />Wrong! They took these 1-dimensional supporting roles because they paid so well. After all, acting is one of the oldest temp-jobs there is (YOU name another!)<br /><br />First warning sign: lots and lots of backlighting. They get around it by shooting outdoors - "hey, it\'s just the sunlight!"<br /><br />Second warning sign: Leading Lady cries a lot. When not crying, her eyes are moist. That\'s the law of romance novels: Leading Lady is "dewy-eyed."<br /><br />Henceforth, Leading Lady shall be known as L.L.<br /><br />Third warning sign: L.L. actually has stars in her eyes when she\'s in love. Still, I\'ll give Emily Mortimer an award just for having to act with that spotlight in her eyes (I wonder . did they use contacts?)<br /><br />And lastly, fourth warning sign: no on-screen female character is "Mrs." She\'s either "Miss" or "Lady."<br /><br />When all was said and done, I still couldn\'t tell you who was pursuing whom and why. I couldn\'t even tell you what was said and done.<br /><br />To sum up: they all live through World War II without anything happening to them at all.<br /><br />OK, at the end, L.L. finds she\'s lost her parents to the Japanese prison camps and baby sis comes home catatonic. Meanwhile (there\'s always a "meanwhile,") some young guy L.L. had a crush on (when, I don\'t know) comes home from some wartime tough spot and is found living on the street by Lady of the Manor (must be some street if SHE\'s going to find him there.) Both war casualties are whisked away to recover at Nancherrow (SOMEBODY has to be "whisked away" SOMEWHERE in these romance stories!)<br /><br />Great drama.',
       b'The film is based on a genuine 1950s novel.<br /><br />Journalist Colin McInnes wrote a set of three "London novels": "Absolute Beginners", "City of Spades" and "Mr Love and Justice". I have read all three. The first two are excellent. The last, perhaps an experiment that did not come off. But McInnes\'s work is highly acclaimed; and rightly so. This musical is the novelist\'s ultimate nightmare - to see the fruits of one\'s mind being turned into a glitzy, badly-acted, soporific one-dimensional apology of a film that says it captures the spirit of 1950s London, and does nothing of the sort.<br /><br />Thank goodness Colin McInnes wasn\'t alive to witness it.',
       b'I really love the sexy action and sci-fi films of the sixties and its because of the actress\'s that appeared in them. They found the sexiest women to be in these films and it didn\'t matter if they could act (Remember "Candy"?). The reason I was disappointed by this film was because it wasn\'t nostalgic enough. The story here has a European sci-fi film called "Dragonfly" being made and the director is fired. So the producers decide to let a young aspiring filmmaker (Jeremy Davies) to complete the picture. They\'re is one real beautiful woman in the film who plays Dragonfly but she\'s barely in it. Film is written and directed by Roman Coppola who uses some of his fathers exploits from his early days and puts it into the script. I wish the film could have been an homage to those early films. They could have lots of cameos by actors who appeared in them. There is one actor in this film who was popular from the sixties and its John Phillip Law (Barbarella). Gerard Depardieu, Giancarlo Giannini and Dean Stockwell appear as well. I guess I\'m going to have to continue waiting for a director to make a good homage to the films of the sixties. If any are reading this, "Make it as sexy as you can"! I\'ll be waiting!',
       b'Sure, this one isn\'t really a blockbuster, nor does it target such a position. "Dieter" is the first name of a quite popular German musician, who is either loved or hated for his kind of acting and thats exactly what this movie is about. It is based on the autobiography "Dieter Bohlen" wrote a few years ago but isn\'t meant to be accurate on that. The movie is filled with some sexual offensive content (at least for American standard) which is either amusing (not for the other "actors" of course) or dumb - it depends on your individual kind of humor or on you being a "Bohlen"-Fan or not. Technically speaking there isn\'t much to criticize. Speaking of me I find this movie to be an OK-movie.'],

आइए पहले 10 लेबल भी प्रिंट करें।

<tf.Tensor: shape=(10,), dtype=int64, numpy=array([0, 0, 0, 1, 1, 1, 0, 0, 0, 0])>

मॉडल बनाएं

तंत्रिका नेटवर्क परतों को ढेर करके बनाया गया है - इसके लिए तीन मुख्य वास्तु निर्णयों की आवश्यकता होती है:

  • पाठ का प्रतिनिधित्व कैसे करें?
  • मॉडल में कितनी परतों का उपयोग करना है?
  • प्रत्येक परत के लिए कितनी छिपी हुई इकाइयों का उपयोग करना है?

इस उदाहरण में, इनपुट डेटा में वाक्य होते हैं। भविष्यवाणी करने के लिए लेबल या तो 0 या 1 हैं।

पाठ का प्रतिनिधित्व करने का एक तरीका वाक्यों को एम्बेडिंग वैक्टर में बदलना है। पहली परत के रूप में एक पूर्व-प्रशिक्षित टेक्स्ट एम्बेडिंग का उपयोग करें, जिसके तीन फायदे होंगे:

  • आपको टेक्स्ट प्रीप्रोसेसिंग के बारे में चिंता करने की ज़रूरत नहीं है,
  • स्थानांतरण सीखने से लाभ,
  • एम्बेडिंग का एक निश्चित आकार होता है, इसलिए इसे संसाधित करना आसान होता है।

इस उदाहरण के लिए आप TensorFlow हब से एक पूर्व-प्रशिक्षित टेक्स्ट एम्बेडिंग मॉडल का उपयोग करते हैं जिसे google/nnlm-en-dim50/2 कहा जाता है।

TFHub से कई अन्य पूर्व-प्रशिक्षित टेक्स्ट एम्बेडिंग हैं जिनका उपयोग इस ट्यूटोरियल में किया जा सकता है:

  • google/nnlm-en-dim128/2 - google/nnlm-en-dim50 / 2 के समान डेटा पर समान NNLM आर्किटेक्चर के साथ प्रशिक्षित, लेकिन एक बड़े एम्बेडिंग आयाम के साथ। बड़े आयामी एम्बेडिंग आपके कार्य में सुधार कर सकते हैं लेकिन आपके मॉडल को प्रशिक्षित करने में अधिक समय लग सकता है।
  • google/nnlm-en-dim128-with-normalization/2 - google/nnlm-en-dim128/2 के समान, लेकिन अतिरिक्त टेक्स्ट सामान्यीकरण जैसे विराम चिह्नों को हटाने के साथ। यदि आपके कार्य के टेक्स्ट में अतिरिक्त वर्ण या विराम चिह्न हैं तो यह मदद कर सकता है।
  • google/universal-sentence-encoder/4 - एक बहुत बड़ा मॉडल जो एक गहरे औसत नेटवर्क (DAN) एन्कोडर के साथ प्रशिक्षित 512 आयामी एम्बेडिंग देता है।

और बहुत सारे! TFHub पर अधिक टेक्स्ट एम्बेडिंग मॉडल खोजें।

आइए पहले एक केरस परत बनाएं जो वाक्यों को एम्बेड करने के लिए एक TensorFlow हब मॉडल का उपयोग करता है, और इसे कुछ इनपुट उदाहरणों पर आज़माएं। ध्यान दें कि इनपुट टेक्स्ट की लंबाई चाहे जितनी भी हो, एम्बेडिंग का आउटपुट आकार है: (num_examples, embedding_dimension)

embedding = "https://tfhub.dev/google/nnlm-en-dim50/2"
hub_layer = hub.KerasLayer(embedding, input_shape=[], 
                           dtype=tf.string, trainable=True)
<tf.Tensor: shape=(3, 50), dtype=float32, numpy=
array([[ 0.5423194 , -0.01190171,  0.06337537,  0.0686297 , -0.16776839,
        -0.10581177,  0.168653  , -0.04998823, -0.31148052,  0.07910344,
         0.15442258,  0.01488661,  0.03930155,  0.19772716, -0.12215477,
        -0.04120982, -0.27041087, -0.21922147,  0.26517656, -0.80739075,
         0.25833526, -0.31004202,  0.2868321 ,  0.19433866, -0.29036498,
         0.0386285 , -0.78444123, -0.04793238,  0.41102988, -0.36388886,
        -0.58034706,  0.30269453,  0.36308962, -0.15227163, -0.4439151 ,
         0.19462997,  0.19528405,  0.05666233,  0.2890704 , -0.28468323,
        -0.00531206,  0.0571938 , -0.3201319 , -0.04418665, -0.08550781,
        -0.55847436, -0.2333639 , -0.20782956, -0.03543065, -0.17533456],
       [ 0.56338924, -0.12339553, -0.10862677,  0.7753425 , -0.07667087,
        -0.15752274,  0.01872334, -0.08169781, -0.3521876 ,  0.46373403,
        -0.08492758,  0.07166861, -0.00670818,  0.12686071, -0.19326551,
        -0.5262643 , -0.32958236,  0.14394784,  0.09043556, -0.54175544,
         0.02468163, -0.15456744,  0.68333143,  0.09068333, -0.45327246,
         0.23180094, -0.8615696 ,  0.3448039 ,  0.12838459, -0.58759046,
        -0.40712303,  0.23061076,  0.48426905, -0.2712814 , -0.5380918 ,
         0.47016335,  0.2257274 , -0.00830665,  0.28462422, -0.30498496,
         0.04400366,  0.25025868,  0.14867125,  0.4071703 , -0.15422425,
        -0.06878027, -0.40825695, -0.31492147,  0.09283663, -0.20183429],
       [ 0.7456156 ,  0.21256858,  0.1440033 ,  0.52338624,  0.11032254,
         0.00902788, -0.36678016, -0.08938274, -0.24165548,  0.33384597,
        -0.111946  , -0.01460045, -0.00716449,  0.19562715,  0.00685217,
        -0.24886714, -0.42796353,  0.1862    , -0.05241097, -0.664625  ,
         0.13449019, -0.22205493,  0.08633009,  0.43685383,  0.2972681 ,
         0.36140728, -0.71968895,  0.05291242, -0.1431612 , -0.15733941,
        -0.15056324, -0.05988007, -0.08178931, -0.15569413, -0.09303784,
        -0.18971168,  0.0762079 , -0.02541647, -0.27134502, -0.3392682 ,
        -0.10296471, -0.27275252, -0.34078008,  0.20083308, -0.26644838,
         0.00655449, -0.05141485, -0.04261916, -0.4541363 ,  0.20023566]],

आइए अब पूरा मॉडल बनाएं:

model = tf.keras.Sequential()
model.add(tf.keras.layers.Dense(16, activation='relu'))

Model: "sequential"
 Layer (type)                Output Shape              Param #   
 keras_layer (KerasLayer)    (None, 50)                48190600  
 dense (Dense)               (None, 16)                816       
 dense_1 (Dense)             (None, 1)                 17        
Total params: 48,191,433
Trainable params: 48,191,433
Non-trainable params: 0

क्लासिफायरियर बनाने के लिए परतों को क्रमिक रूप से ढेर किया जाता है:

  1. पहली परत एक TensorFlow हब परत है। यह परत अपने एम्बेडिंग वेक्टर में एक वाक्य को मैप करने के लिए पूर्व-प्रशिक्षित सहेजे गए मॉडल का उपयोग करती है। आप जिस पूर्व-प्रशिक्षित टेक्स्ट एम्बेडिंग मॉडल का उपयोग कर रहे हैं ( google/nnlm-en-dim50/2 ) वाक्य को टोकन में विभाजित करता है, प्रत्येक टोकन को एम्बेड करता है और फिर एम्बेडिंग को जोड़ता है। परिणामी आयाम हैं: (num_examples, embedding_dimension) । इस एनएनएलएम मॉडल के लिए, embedding_dimension 50 है।
  2. यह निश्चित-लंबाई आउटपुट वेक्टर 16 छिपी इकाइयों के साथ पूरी तरह से जुड़ी ( Dense ) परत के माध्यम से पाइप किया जाता है।
  3. अंतिम परत एकल आउटपुट नोड के साथ घनी रूप से जुड़ी हुई है।

आइए मॉडल को संकलित करें।

हानि समारोह और अनुकूलक

एक मॉडल को प्रशिक्षण के लिए एक हानि फ़ंक्शन और एक अनुकूलक की आवश्यकता होती है। चूंकि यह एक द्विआधारी वर्गीकरण समस्या है और मॉडल लॉगिट्स (रैखिक सक्रियण के साथ एक एकल-इकाई परत) को आउटपुट करता है, आप binary_crossentropy हानि फ़ंक्शन का उपयोग करेंगे।

हानि फ़ंक्शन के लिए यह एकमात्र विकल्प नहीं है, उदाहरण के लिए, आप mean_squared_error चुन सकते हैं। लेकिन, आम तौर पर, binary_crossentropy संभावनाओं से निपटने के लिए बेहतर है-यह संभाव्यता वितरण के बीच, या हमारे मामले में, जमीनी सच्चाई वितरण और भविष्यवाणियों के बीच "दूरी" को मापता है।

बाद में, जब आप प्रतिगमन समस्याओं की खोज कर रहे हों (जैसे, किसी घर की कीमत का अनुमान लगाने के लिए), तो आप देखेंगे कि माध्य वर्ग त्रुटि नामक एक अन्य हानि फ़ंक्शन का उपयोग कैसे करें।

अब, अनुकूलक और हानि फ़ंक्शन का उपयोग करने के लिए मॉडल को कॉन्फ़िगर करें:


मॉडल को प्रशिक्षित करें

512 नमूनों के मिनी-बैच में 10 युगों के लिए मॉडल को प्रशिक्षित करें। यह x_train और y_train टेंसर में सभी नमूनों पर 10 पुनरावृत्तियों का है। प्रशिक्षण के दौरान, सत्यापन सेट से 10,000 नमूनों पर मॉडल के नुकसान और सटीकता की निगरानी करें:

history = model.fit(train_data.shuffle(10000).batch(512),
Epoch 1/10
30/30 [==============================] - 3s 59ms/step - loss: 0.6707 - accuracy: 0.5317 - val_loss: 0.6150 - val_accuracy: 0.5882
Epoch 2/10
30/30 [==============================] - 2s 57ms/step - loss: 0.5382 - accuracy: 0.7012 - val_loss: 0.4972 - val_accuracy: 0.7450
Epoch 3/10
30/30 [==============================] - 2s 56ms/step - loss: 0.3976 - accuracy: 0.8246 - val_loss: 0.4023 - val_accuracy: 0.8149
Epoch 4/10
30/30 [==============================] - 2s 61ms/step - loss: 0.2879 - accuracy: 0.8894 - val_loss: 0.3503 - val_accuracy: 0.8385
Epoch 5/10
30/30 [==============================] - 2s 59ms/step - loss: 0.2120 - accuracy: 0.9243 - val_loss: 0.3248 - val_accuracy: 0.8530
Epoch 6/10
30/30 [==============================] - 2s 54ms/step - loss: 0.1560 - accuracy: 0.9513 - val_loss: 0.3148 - val_accuracy: 0.8663
Epoch 7/10
30/30 [==============================] - 2s 55ms/step - loss: 0.1147 - accuracy: 0.9680 - val_loss: 0.3168 - val_accuracy: 0.8675
Epoch 8/10
30/30 [==============================] - 2s 56ms/step - loss: 0.0847 - accuracy: 0.9791 - val_loss: 0.3199 - val_accuracy: 0.8670
Epoch 9/10
30/30 [==============================] - 2s 54ms/step - loss: 0.0617 - accuracy: 0.9880 - val_loss: 0.3272 - val_accuracy: 0.8649
Epoch 10/10
30/30 [==============================] - 2s 57ms/step - loss: 0.0449 - accuracy: 0.9931 - val_loss: 0.3379 - val_accuracy: 0.8651

मॉडल का मूल्यांकन करें

और देखते हैं कि मॉडल कैसा प्रदर्शन करता है। दो मान लौटाए जाएंगे। हानि (एक संख्या जो हमारी त्रुटि का प्रतिनिधित्व करती है, कम मान बेहतर होते हैं), और सटीकता।

results = model.evaluate(test_data.batch(512), verbose=2)

for name, value in zip(model.metrics_names, results):
  print("%s: %.3f" % (name, value))
49/49 - 2s - loss: 0.3599 - accuracy: 0.8523 - 2s/epoch - 34ms/step
loss: 0.360
accuracy: 0.852

यह काफी भोला दृष्टिकोण लगभग 87% की सटीकता प्राप्त करता है। अधिक उन्नत दृष्टिकोणों के साथ, मॉडल को 95% के करीब पहुंचना चाहिए।

अग्रिम पठन

# MIT License
# Copyright (c) 2017 François Chollet
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.