Let’s imagine we want to create a simple Sentiment Analysis model using Machine Learning not Deep Learning algorithms, so we need to have a set of handcrafted features for this classification problem.
Let's say we have 2 features (F1, F2) for each sentence and a target class consisting of 0 and 1 as positive and negative. So we have a bunch of sentences in a dataset like this:
Well, classification algorithms like SVM, LR, DT, and …. can be trained from the training set and learn the sentiment of each sentence from their features. They can also test themselves using the test set. Now the model is ready to predict the sentiment of any sentence out of the dataset. Till now, there is no problem and everything is clear to me.
My problem is when we want to give a new sentence to the model form outside the dataset. Obviously, when we give a sentence to the model, we don’t give any feature to the model. So here is my question, how the model can predict the sentiment of the new sentence when it doesn’t know how to calculate each of the features?
Should we define what is F1, and F2 in the model first? Should we define a function and for any new input sentence, call the function to calculate the proper value for each feature and then teach the model that the function outputs are equal to F1 and F2 in the dataset?
To make a long question shorter, let me give a clear instance. My new sentence is "She was overjoyed when saw my cat". I want to give this sentence to the model and obviously expect to see a predicted positive sentiment. This sentence is not in my dataset so there is no feature for it and the model has no idea about F1 and F2. On the other hand, my model learned to determine the sentiment of each sentence using F1 and F2. So back to my question, when I don't give new sentence features (F1, F2) to my model and don't specify any procedure to calculate the features for new inputs, how the model can predict the sentiment of my new sentences?
As an example of a classification problem, I mentioned the article " A Pattern-Based Approach for Sarcasm Detection on Twitter," Click here! where the authors proposed four sets of features that cover the different types of sarcasm. They used those to classify tweets as sarcastic and non-sarcastic. These features are sentiment-related features, Punctuation-related features, Syntactic and semantic features, and Pattern features. For instance, in sentiment-related features, they checked whether there is a contrast between the different components. By contrast, they mean the coexistence of a negative component and a positive one within the same tweet. Once the features are extracted, they ran the classification using classifiers like (SVM). So till now, everything is clear, with those features they trained their model and then test it with the test set. The question is when they wanna check the classification for a new sentence, say x for instance, obviously, we should calculate all four sets of features for the new input x. Assume that G(x) is a function that gets a new sentence x and returns four sets of features for it (F1,F2,F3, F4), where (F1 = Sentiment-relatedfeatures, F2 = Punctuation-related features, F3 = Syntactic and semantic features, F4 = Pattern features) How should I show the model to use these features (F1,...,F4) to predict the class for this new sentence (x)?
We have such a code: Ypred = model.predict(x, F1,F2,F3,F4); how the model should know to use F1,...F4 features in the same way as its train or test phase?