<jupyter_start><jupyter_text>💬 Basic Text Classification 🚙 Importing libraries, data sets, required files and modules<jupyter_code>import tensorflow as tf
tf.enable_eager_execution()
import numpy as np
import tensorflow_hub as tfhub
import tensorflow_datasets as tfds
from tensorflow.keras.layers import Dense
from tensorflow.keras.models import Sequential<jupyter_output><empty_output><jupyter_text>⏬ Data Loading> 🎈 For datset [details](https://www.tensorflow.org/datasets/catalog/imdb_reviews)<jupyter_code>train_val_split_ratio = tfds.Split.TRAIN.subsplit([6, 4])
(train, val), test = tfds.load(
    name = 'imdb_reviews',
    split = (train_val_split_ratio, tfds.Split.TEST),
    as_supervised = True
)<jupyter_output><empty_output><jupyter_text>🕵️‍♀️ Understand the data<jupyter_code>train_examples, train_labels = next(iter(train.batch(10)))
train_examples
train_labels<jupyter_output><empty_output><jupyter_text>👩‍🔧 Data Preparation (pre-processing) 🎳 Prepare word embeddings> To represent words<jupyter_code>embeddings = "https://tfhub.dev/google/tf2-preview/gnews-swivel-20dim/1"
emb_layer = tfhub.KerasLayer(
    embeddings, 
    input_shape=[], 
    dtype = tf.string, 
    trainable=True)
# explore embeddings
emb_layer(train_examples[:2])<jupyter_output><empty_output><jupyter_text>👩‍💻 Model Designing 🧱 Make layers design- Number of layers and number of units in each layer- Activation function of each layer<jupyter_code>layers = [
          emb_layer,
          Dense(16, activation='relu'),
          Dense(1, activation='sigmoid')
]<jupyter_output><empty_output><jupyter_text>🚀 Implement your design<jupyter_code>model = Sequential(layers)
model.summary()
model.compile(optimizer='adam', 
              loss='binary_crossentropy',
              metrics=['accuracy'])<jupyter_output><empty_output><jupyter_text>🤓 Training- Keras .fit() [details](https://keras.io/models/model/fit)<jupyter_code>model.fit(train.shuffle(10000).batch(512),
          epochs=20,
          validation_data=val.batch(512))<jupyter_output>Epoch 1/20
30/30 [==============================] - 9s 289ms/step - loss: 0.5552 - acc: 0.7235 - val_loss: 0.0000e+00 - val_acc: 0.0000e+00
Epoch 2/20
30/30 [==============================] - 8s 283ms/step - loss: 0.5321 - acc: 0.7439 - val_loss: 0.5351 - val_acc: 0.7409
Epoch 3/20
30/30 [==============================] - 9s 287ms/step - loss: 0.5063 - acc: 0.7632 - val_loss: 0.5132 - val_acc: 0.7566
Epoch 4/20
30/30 [==============================] - 8s 282ms/step - loss: 0.4794 - acc: 0.7843 - val_loss: 0.4882 - val_acc: 0.7739
Epoch 5/20
30/30 [==============================] - 9s 292ms/step - loss: 0.4475 - acc: 0.8043 - val_loss: 0.4638 - val_acc: 0.7887
Epoch 6/20
30/30 [==============================] - 9s 287ms/step - loss: 0.4173 - acc: 0.8225 - val_loss: 0.4408 - val_acc: 0.8022
Epoch 7/20
30/30 [==============================] - 9s 290ms/step - loss: 0.3880 - acc: 0.8383 - val_loss: 0.4196 - val_acc: 0.8127
Epoch 8/20
30/30 [==============================] - 9s 289ms/step - [...]<jupyter_text>👮‍♀️ Evaluate the model- Keras .evaluate() [details](https://keras.io/models/model/evaluate)<jupyter_code>loss, acc = model.evaluate(test.batch(512))
print('Loss:', loss, 'Accuracy', acc)<jupyter_output>Loss: 0.3329200106007712 Accuracy 0.85672
{'fraction_non_alphanumeric': 0.2032766990291262, 'fraction_numerical': 0.0858616504854369, 'mean_word_length': 4.908602150537634, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 33, 'https://': 4, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '381979', 'license': 'MIT', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1206, 'n_words': 237, 'path': '9-dizi-modelleri/A-TextClassification.ipynb', 'repo_name': 'maidis/DeepLearningNotes-tr', 'size': '3296'}