1
$\begingroup$

Q1: how to feed 2 input to LR and SVM?

My dataset consist of three columns which are: sentence1 , sentence 2, and label (1 if the sentence2 is a paraphrased of sentence1)

I prepare my data and convert it numeric features using (tf-idf) now I would like to train a classifier, but all the tutorials I find do one input and one output while I would like two inputs and one output. Could you help with an example?

Picture of my data: my dataset

$\endgroup$
1
  • 1
    $\begingroup$ one way would be to have all sentence2's as extra features with same label as related sentence1's $\endgroup$
    – Nikos M.
    Oct 19, 2021 at 17:03

2 Answers 2

0
$\begingroup$

The simplest option in order to represent the two sentences independently of each other is to represent each of the two sentences with its own TFIDF vector of features and concatenate the two vectors. In other words you obtain 2 * N features where N is the size of the vocabulary.

But at first sight it looks like the wrong approach for the problem that you're trying to solve: LR or SVM are unlikely to capture the high-level nature of paraphrasing, especially if fed with only basic vocabulary features like this. A slightly more advanced approach would be to provide the model with features which represent the relationship between the two sentences: length, words in common, readability measure, etc.

$\endgroup$
2
  • $\begingroup$ thank you for explaining. yes I extracted some features from the text such as common words , length also tf_idf I considered as a feature. Now I have 2 length and 2 tf_idf how to feed them to a classifier and which I classifier I could try ? $\endgroup$
    – Arwa
    Nov 3, 2021 at 13:17
  • $\begingroup$ @Arwa you could try simple models like SVM, LR or decision tree/random forest. But apparently the task that you're doing is paraphrasing, which is a difficult NLP problem and an active area of research. I'm not very familiar with the state of the art of this task but there are more advanced methods. $\endgroup$
    – Erwan
    Nov 4, 2021 at 11:15
0
$\begingroup$

You can calculate the text-similarity using Transformers. With transformers, we can get better accuracies. Try the following code:

pip install sentence-transformers==1.2.1

from sentence_transformers import SentenceTransformer
model = SentenceTransformer('distilbert-base-uncased')

sen = [sentence1 , sentence 2]

sen_embeddings = model.encode(sen)

from sklearn.metrics.pairwise import cosine_similarity
#let's calculate cosine similarity for sentence 0:
cosine_similarity(
    [sen_embeddings[0]],
    sen_embeddings[1:]
)

If the similarity score is greater than 0.6 ( or 0.7), you can assume that sentence2 is a paraphrased of sentence1.

$\endgroup$

Your Answer

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

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