1
$\begingroup$

I am pretty new to ML and have a basic but fundamental question.

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: enter image description here

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 short, 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?

I would really appreciate your time.

$\endgroup$

1 Answer 1

1
$\begingroup$

Your premise is wrong. You are assuming we don't know how to compute the features on new sentences. But we do know.

We construct features so that we can compute the features on any sentence whatsoever (not just the ones in the training set). For instance, one feature might be "does the sentence contain the word 'not'?". That is clearly a feature that can be computed on any new sentence.

You might be reading an example in a textbook that omits mentioning how the features are computed, to keep the example simple and avoid mentioning details that are not important for the author's purposes. But if you use this in practice, the features will be known and can be computed on any sentence.

$\endgroup$
2
  • $\begingroup$ @ D.W. Thank you very much for your explanation. Yeah. You are right it basically stems from books I’ve read before. Based on your answer, I suppose I must create a function that gets a new sentence as an input and return all features as output for each new input sentence. That way my model can predict each sentence’s classification. $\endgroup$
    – Z Bokaee
    May 17, 2023 at 17:37
  • $\begingroup$ @ZBokaee, correct! $\endgroup$
    – D.W.
    May 17, 2023 at 19:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.