1
$\begingroup$

How to use unigram and bigram as an feature to build an Natural Language Inference model on SVM or logistic regression?on my dataset i have premise, hypotesis and label column. I'm planning to use the unigram and bigram of the premis or hipotesis or both as one of the features on my training. for example :

 premise                                      |hipotesis                         |hypothesis bigram
===============================================================================================
I am planning to use the unigram and bigram   |I am planning to use the unigram  |[(i, am), (am, planning), (planning, to), (to, use), (use, the), (the, unigram)]

the hypothesis bigram is a list of bigram(word), so i cant use it as input to my svm or logistic. can i convert the hypothesis bigram into vector?

$\endgroup$
  • $\begingroup$ Please explain more on the "How". What is your expectation and what is your currently achieved status/code? You might get a very simple answer e.g. an SVM classification code etc., which will not serve your purpose. $\endgroup$ – 10xAI Jul 2 at 4:21
  • $\begingroup$ for example can i turn it into vector so i can use it to my svm or logistic regression? $\endgroup$ – thenoirlatte Jul 2 at 5:15
1
$\begingroup$

You need to create a vocabulary of the n-grams, i.e., a numbered inventory of bigrams that you are going to use as features. Typically, these are the most frequent ones. When you create the feature vector, you start with a zero vector and put one (or add one) if the n-gram with the corresponding index appears is in your sentence.

Machine learning libraries typically have functions that do that. For instance, in scikit-learn, you can use CountVectorizer to do the job. The fit method has an ngram_range argument that controls the length of n-grams that are considered in the feature vectors.

| improve this answer | |
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.