dennybritz / cnn-text-classification-tf

Convolutional Neural Network for Text Classification in Tensorflow
Apache License 2.0
5.65k stars 2.77k forks source link

custom word #162

Open niranjan8129 opened 6 years ago

niranjan8129 commented 6 years ago

how to train custom word like

source word --------------------- target word

1- #U@SAA$ -------------------------- USA 2- %Goo@#g-le ----------------------- Google

rohan12345a commented 7 months ago

You can refer to the below code as a starting point:

import tensorflow as tf

Define the source and target word pairs

source_words = ['#U@SAA$', '%Goo@#g-le'] target_words = ['USA', 'Google']

Define the simple neural network architecture a basic one.

model = tf.keras.Sequential([ tf.keras.layers.Embedding(input_dim=vocab_size, output_dim=embedding_dim), tf.keras.layers.GlobalAveragePooling1D(), tf.keras.layers.Dense(output_dim) ])

Compile the model

model.compile(optimizer='adam', loss='mse')

Train the model

model.fit(source_words, target_words, epochs=num_epochs, batch_size=batch_size)