Machine Learning is something which is one of the most in-demand fields of today’s tech market. It is very interesting to learn how to teach your system to do some specific things by its own. Today we will take our first small step in discovering machine learning with the help of libraries like Tensorflow and Numpy. We will create a neural structure with one neuron whose only purpose in life will be to change the characters fed by us into other characters by following a specific pattern whose examples are stored by us in the sample data from which machine will learn.
Libraries Used :
Code : Importing Libraries
We will also be using Keras which is neural network library written in Python and is preadded in Tensorflow library.
Working of Model :
The aim of given example is to take input code from user and then encrypt it so that no one will be able to understand it without knowing the key of it. Here we will see the message character by character and replace it with the character having an ASCII value 1 + ASCII value of given character. But first of all, we will create a neural structure to do such work for us. We will call it model here and define it using Keras. Here
keras.Sequential defines that our model will be sequential or the model is linear stack of layers and then we will define the kind of layer(We will use a densely connected neural network(NN) layer) with the number of layers or units we want. Finally, we will give the number of neurons we want as input_shape and will compile the model with optimizer and loss. Optimizer and loss are the 2 functions that will help our model to work in the correct direction. The loss will calculate the error of the prediction made by our model and optimizer will check that error and move the model in the direction in which error will decrease.
Code : Creating Sequential Model
After this, we will specify our training data as Numpy array which will connect all the values of x to the respective y and then we will train our model on the given data with
model.fit. Here Epochs will specify the number of times our model will work on the training data to increase its accuracy using Loss and Optimizer.
Lastly, we will take the Input from the user and will break it down to characters by using tuple function, then we will save all these characters into a list. Now we will create a for loop and will send each character one at a time in our model to make the prediction and will print all the predictions so that they together form an encrypted message which will not be easy to understand until you know the key to it.
Complete Implementation –
- keras.fit() and keras.fit_generator()
- Keras.Conv2D Class
- Python | Image Classification using keras
- Building an Auto-Encoder using Keras
- Building a Generative Adversarial Network using Keras
- XOR Encryption by Shifting Plaintext
- NLP | Word Collocations
- NLP | Likely Word Tags
- NLP | Synsets for a word in WordNet
- Python | Word Stretch
- Word Prediction using concepts of N - grams and CDF
- Python | Word Similarity using spaCy
- Generating Word Cloud in Python | Set 2
- Count occurrences of a word in string
- Python | Reverse each word in a sentence
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.