<p>input: phrase 1, phrase 2</p>

<p>output: semantic similarity value (between 0 and 1), or the probability these two phrases are talking about the same thing</p>

[{'answer_id': 62356, 'author': 'Rik', 'author_id': 5409, 'author_profile': 'https://Stackoverflow.com/users/5409', 'pm_score': 1, 'selected': False, 'text': '<p>This requires your algorithm actually knows what your talking about. It can be done in some rudimentary form by just comparing words and looking for synonyms etc, but any sort of accurate result would require some form of intelligence.</p>\n'}, {'answer_id': 62791, 'author': 'jonfm', 'author_id': 6924, 'author_profile': 'https://Stackoverflow.com/users/6924', 'pm_score': 3, 'selected': False, 'text': '<p>I would look into latent semantic indexing for this. I believe you can create something similar to a vector space search index but with semantically related terms being closer together i.e. having a smaller angle between them. If I learn more I will post here.</p>\n'}, {'answer_id': 63076, 'author': 'Matt Mower', 'author_id': 7518, 'author_profile': 'https://Stackoverflow.com/users/7518', 'pm_score': 6, 'selected': True, 'text': '<hr>\n\n<p>You might want to check out this paper:</p>\n\n<p><a href="http://ants.iis.sinica.edu.tw/3BkMJ9lTeWXTSrrvNoKNFDxRm3zFwRR/55/Sentence%20Similarity%20Based%20on%20Semantic%20Nets%20and%20corpus%20statistics.pdf" rel="noreferrer">Sentence similarity based on semantic nets and corpus statistics (PDF)</a></p>\n\n<p>I\'ve implemented the algorithm described. Our context was very general (effectively any two English sentences) and we found the approach taken was too slow and the results, while promising, not good enough (or likely to be so without considerable, extra, effort).</p>\n\n<p>You don\'t give a lot of context so I can\'t necessarily recommend this but reading the paper could be useful for you in understanding how to tackle the problem.</p>\n\n<p>Regards,</p>\n\n<p>Matt.</p>\n'}, {'answer_id': 63138, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>One simple solution is to use the dot product of character n-gram vectors.  This is robust over ordering changes (which many edit distance metrics are not) and captures many issues around stemming.  It also prevents the AI-complete problem of full semantic understanding.</p>\n\n<p>To compute the n-gram vector, just pick a value of n (say, 3), and hash every 3-word sequence in the phrase into a vector.  Normalize the vector to unit length, then take the dot product of different vectors to detect similarity.</p>\n\n<p>This approach has been described in \n<a href="http://onlinelibrary.wiley.com/doi/10.1111/j.1551-6709.2010.01106.x/abstract" rel="nofollow noreferrer">J. Mitchell and M. Lapata, “Composition in Distributional Models of Semantics,” Cognitive Science, vol. 34, no. 8, pp. 1388–1429, Nov. 2010., DOI 10.1111/j.1551-6709.2010.01106.x </a></p>\n'}, {'answer_id': 67670, 'author': 'Chuck Wooters', 'author_id': 8879, 'author_profile': 'https://Stackoverflow.com/users/8879', 'pm_score': 3, 'selected': False, 'text': '<p>You might want to check into the <a href="http://wordnet.princeton.edu/" rel="noreferrer">WordNet</a> project at Princeton University. One possible approach to this would be to first run each phrase through a stop-word list (to remove "common" words such as "a", "to", "the", etc.) Then for each of the remaining words in each phrase, you could compute the semantic "similarity" between each of the words in the other phrase using a distance measure based on WordNet. The distance measure could be something like: the number of arcs you have to pass through in WordNet to get from word1 to word2. </p>\n\n<p>Sorry this is pretty high-level. I\'ve obviously never tried this. Just a quick thought.</p>\n'}, {'answer_id': 179071, 'author': 'nfelger', 'author_id': 11819, 'author_profile': 'https://Stackoverflow.com/users/11819', 'pm_score': 5, 'selected': False, 'text': '<p>There\'s a short and a long answer to this.</p>\n\n<p>The short answer:</p>\n\n<p>Use the <a href="http://search.cpan.org/dist/WordNet-Similarity/" rel="noreferrer">WordNet::Similarity Perl package</a>. If Perl is not your language of choice, check the <a href="http://wordnet.princeton.edu/" rel="noreferrer">WordNet project page</a> at Princeton, or google for a wrapper library.</p>\n\n<p>The long answer:</p>\n\n<p>Determining word similarity is a complicated issue, and research is still very hot in this area. To compute similarity, you need an appropriate represenation of the <em>meaning</em> of a word. But what would be a representation of the meaning of, say, \'chair\'? In fact, what <em>is</em> the exact meaning of \'chair\'? If you think long and hard about this, it will twist your mind, you will go slightly mad, and finally take up a research career in Philosophy or Computational Linguistics to find the truth™. Both philosophers and linguists have tried to come up with an answer for literally thousands of years, and there\'s no end in sight.</p>\n\n<p>So, if you\'re interested in exploring this problem a little more in-depth, I highly recommend reading Chapter 20.7 in <a href="https://rads.stackoverflow.com/amzn/click/com/0131873210" rel="noreferrer" rel="nofollow noreferrer">Speech and Language Processing</a> by Jurafsky and Martin, some of which is available through <a href="http://books.google.co.uk/books?id=fZmj5UNK8AQC&amp;pg=PA379&amp;lpg=PA379b&amp;ots=LqQbZ7EJPG&amp;sig=7VIRoXss0BNLv-B28FCPQgnqjVs&amp;hl=en&amp;sa=X&amp;oi=book_result&amp;resnum=1&amp;ct=result#PPA658,M1" rel="noreferrer">Google Books</a>. It gives a very good overview of the state-of-the-art of distributional methods, which use word co-occurrence statistics to define a measure for word similarity. You are not likely to find libraries implementing these, however.</p>\n'}, {'answer_id': 3175629, 'author': 'Gia', 'author_id': 179812, 'author_profile': 'https://Stackoverflow.com/users/179812', 'pm_score': 2, 'selected': False, 'text': '<p>I would have a look at statistical techniques that take into consideration the probability of each word to appear within a sentence. This will allow you to give less importance to popular words such as \'and\', \'or\', \'the\' and give more importance to words that appear less regurarly, and that are therefore a better discriminating factor. For example, if you have two sentences:</p>\n\n<p>1) The smith-waterman algorithm gives you a similarity measure between two strings.\n2) We have reviewed the smith-waterman algorithm and we found it to be good enough for our project.</p>\n\n<p>The fact that the two sentences share the words "smith-waterman" and the words "algorithms" (which are not as common as \'and\', \'or\', etc.), will allow you to say that the two sentences might indeed be talking about the same topic.</p>\n\n<p>Summarizing, I would suggest you have a look at:\n 1) String similarity measures;\n 2) Statistic methods;</p>\n\n<p>Hope this helps.</p>\n'}, {'answer_id': 14384043, 'author': 'Lushan Han', 'author_id': 1987878, 'author_profile': 'https://Stackoverflow.com/users/1987878', 'pm_score': 2, 'selected': False, 'text': '<p>Try <a href="http://swoogle.umbc.edu/SimService/" rel="nofollow">SimService</a>, which provides a service for computing top-n similar words and phrase similarity.</p>\n'}, {'answer_id': 26142225, 'author': 'Hybrid System', 'author_id': 836885, 'author_profile': 'https://Stackoverflow.com/users/836885', 'pm_score': 2, 'selected': False, 'text': '<p>Sorry to dig up a 6 year old question, but as I just came across this post today, I\'ll throw in an answer in case anyone else is looking for something similar.</p>\n\n<p>cortical.io has developed a process for calculating the semantic similarity of two expressions and they have a <a href="http://www.cortical.io/demos/similarity-explorer/" rel="nofollow">demo of it up on their website</a>. They offer a <a href="http://www.cortical.io/developers.html" rel="nofollow">free API providing access to the functionality</a>, so you can use it in your own application without having to implement the algorithm yourself.</p>\n'}, {'answer_id': 34797381, 'author': 'kyrenia', 'author_id': 2801069, 'author_profile': 'https://Stackoverflow.com/users/2801069', 'pm_score': 3, 'selected': False, 'text': '<p>For anyone just coming at this, i would suggest taking a look at SEMILAR - <a href="http://www.semanticsimilarity.org/" rel="noreferrer">http://www.semanticsimilarity.org/</a> . They implement a lot of the modern research methods for calculating word and sentence similarity. It is written in Java.  </p>\n\n<blockquote>\n  <p>SEMILAR API comes with various similarity methods based on Wordnet, Latent Semantic Analysis (LSA), Latent Dirichlet Allocation (LDA), BLEU, Meteor, Pointwise Mutual Information (PMI), Dependency based methods, optimized methods based on Quadratic Assignment, etc. And the similarity methods work in different granularities - word to word, sentence to sentence, or bigger texts. </p>\n</blockquote>\n'}, {'answer_id': 43213509, 'author': 'sindhu', 'author_id': 1463333, 'author_profile': 'https://Stackoverflow.com/users/1463333', 'pm_score': 0, 'selected': False, 'text': '<p>Take a look at <a href="http://mkusner.github.io/publications/WMD.pdf" rel="nofollow noreferrer">http://mkusner.github.io/publications/WMD.pdf</a> This paper describes an algorithm called Word Mover distance that tries to uncover semantic similarity. It relies on the similarity scores as dictated by word2vec. Integrating this with GoogleNews-vectors-negative300 yields desirable results. </p>\n'}]
['https://Stackoverflow.com/questions/62328', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1925263/']