<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1055307259320776616</id><updated>2014-03-28T10:13:45.392Z</updated><category term="Bayes"/><category term="Bayes text classifier"/><category term="C++"/><category term="F#"/><category term="library"/><category term="semantic similarity"/><title type='text'>X Exception</title><subtitle type='html'>social networking, macine learning, c#, f# and asp.net MVC</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://xxxinl.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1055307259320776616/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://xxxinl.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Xin</name><uri>http://www.blogger.com/profile/07979568878714131398</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1055307259320776616.post-3587192478727346211</id><published>2013-10-08T17:28:00.002+01:00</published><updated>2013-11-12T07:55:59.695Z</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="library"/><category scheme="http://www.blogger.com/atom/ns#" term="semantic similarity"/><title type='text'>Semantic Similarity - C++ tool library</title><content type='html'>&lt;h1 style=&quot;border-bottom-color: rgb(221, 221, 221); border-bottom-style: solid; border-bottom-width: 1px; color: #333333; cursor: text; font-family: Helvetica, arial, freesans, clean, sans-serif; line-height: 1.7; margin-bottom: 15px; margin-left: 0px; margin-right: 0px; margin-top: 0px !important; padding: 0px; position: relative;&quot;&gt;&lt;a href=&quot;http://xxinl.github.io/semantic-similarity/&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;http://xxinl.github.io/semantic-similarity/&lt;/span&gt;&lt;/a&gt;&lt;/h1&gt;&lt;div style=&quot;color: #333333; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 15px; line-height: 25px; margin-bottom: 15px; margin-top: 15px;&quot;&gt;C++ tool lib to calculate semantic similarity between two sentences based on method described in paper&lt;/div&gt;&lt;div style=&quot;color: #333333; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 15px; line-height: 25px; margin-bottom: 15px; margin-top: 15px;&quot;&gt;&lt;em&gt;&quot;Sentence Similarity Based on Semantic Nets and Corpus Statistics&quot; Yuhua Li et al, 2006.&lt;/em&gt;&lt;/div&gt;&lt;h3 style=&quot;color: #333333; cursor: text; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 1.5em; line-height: 1.7; margin: 1em 0px 15px; padding: 0px; position: relative;&quot;&gt;&lt;a class=&quot;anchor&quot; href=&quot;https://github.com/xxinl/semantic-similarity#dependencies&quot; name=&quot;dependencies&quot; style=&quot;bottom: 0px; color: #4183c4; cursor: pointer; display: block; left: 0px; margin-left: -30px; padding-left: 30px; padding-right: 6px; position: absolute; text-decoration: none; top: 0px;&quot;&gt;&lt;/a&gt;Dependencies&lt;/h3&gt;&lt;div style=&quot;color: #333333; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 15px; line-height: 25px; margin-bottom: 15px; margin-top: 15px;&quot;&gt;Boost and Wordnet C API&lt;/div&gt;&lt;h3 style=&quot;color: #333333; cursor: text; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 1.5em; line-height: 1.7; margin: 1em 0px 15px; padding: 0px; position: relative;&quot;&gt;&lt;a class=&quot;anchor&quot; href=&quot;https://github.com/xxinl/semantic-similarity#demo&quot; name=&quot;demo&quot; style=&quot;bottom: 0px; color: #4183c4; cursor: pointer; display: block; left: 0px; margin-left: -30px; padding-left: 30px; padding-right: 6px; position: absolute; text-decoration: none; top: 0px;&quot;&gt;&lt;/a&gt;Demo&lt;/h3&gt;&lt;pre style=&quot;background-color: #f8f8f8; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221); color: #333333; font-family: Consolas, &#39;Liberation Mono&#39;, Courier, monospace; font-size: 13px; line-height: 19px; margin-bottom: 15px; margin-top: 15px; overflow: auto; padding: 6px 10px;&quot;&gt;&lt;code style=&quot;background-color: transparent; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: none; font-family: Consolas, &#39;Liberation Mono&#39;, Courier, monospace; font-size: 12px; margin: 0px; padding: 0px;&quot;&gt;SentenceSimilarityLi2006 ss;&lt;br /&gt;s = ss.compute_similarity(&quot;it is a dog&quot;, &quot;it is a log&quot;);&lt;br /&gt;s = ss.compute_similarity(&quot;it is a dog&quot;, &quot;it is a pig&quot;);&lt;br /&gt;&lt;br /&gt;===============================&lt;br /&gt;results:&lt;br /&gt;&quot;i like that bachelor&quot; vs &quot;i like that unmarrided man&quot; sim:0.386069&lt;br /&gt;&quot;John is very nice&quot; vs &quot;is John very nice&quot; sim:1&lt;br /&gt;&quot;I have a pen&quot; vs &quot;where do you live&quot; sim:0.0203516&lt;br /&gt;&quot;it is a dog&quot; vs &quot;it is a log&quot; sim:0.122288&lt;br /&gt;&quot;it is a dog&quot; vs &quot;it is a pig&quot; sim:0.442149&lt;br /&gt;&quot;red alcoholic drink&quot; vs &quot;a bottle of wine&quot; sim:0.105169&lt;br /&gt;&quot;red alcoholic drink&quot; vs &quot;fresh orange juice&quot; sim:0.0963826&lt;br /&gt;&quot;red alcoholic drink&quot; vs &quot;an english dictionary&quot; sim:0.0467486&lt;br /&gt;&quot;it is a dog&quot; vs &quot;that must be your dog&quot; sim:0.720558&lt;br /&gt;&quot;dogs are animals&quot; vs &quot;they are common pets&quot; sim:0.753427&lt;br /&gt;&quot;i have a hammer&quot; vs &quot;take some nails&quot; sim:0.0763042&lt;br /&gt;&quot;canis familiaris are animals&quot; vs &quot;dogs are common pets&quot; sim:0.349904&lt;br /&gt;&quot;i have a pen&quot; vs &quot;where is ink&quot; sim:0.119264&lt;br /&gt;&quot;red alcoholic drink&quot; vs &quot;fersh apple juice&quot; sim:0.0762678&lt;br /&gt;&quot;a glass of cider&quot; vs &quot;a full cup of apple juice&quot; sim:0.534483&lt;br /&gt;&quot;i have a hammer&quot; vs &quot;take some apples&quot; sim:0.0757834&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 style=&quot;color: #333333; cursor: text; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 1.5em; line-height: 1.7; margin: 1em 0px 15px; padding: 0px; position: relative;&quot;&gt;&lt;a class=&quot;anchor&quot; href=&quot;https://github.com/xxinl/semantic-similarity#setup&quot; name=&quot;setup&quot; style=&quot;bottom: 0px; color: #4183c4; cursor: pointer; display: block; left: 0px; margin-left: -30px; padding-left: 30px; padding-right: 6px; position: absolute; text-decoration: none; top: 0px;&quot;&gt;&lt;/a&gt;Setup&lt;/h3&gt;&lt;div style=&quot;color: #333333; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 15px; line-height: 25px; margin-bottom: 15px; margin-top: 15px;&quot;&gt;You will need to download Wordnet3.0/3.1 dictionary&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://xxxinl.blogspot.com/feeds/3587192478727346211/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xxxinl.blogspot.com/2013/10/semantic-similarity-c-tool-library.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1055307259320776616/posts/default/3587192478727346211'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1055307259320776616/posts/default/3587192478727346211'/><link rel='alternate' type='text/html' href='http://xxxinl.blogspot.com/2013/10/semantic-similarity-c-tool-library.html' title='Semantic Similarity - C++ tool library'/><author><name>Xin</name><uri>http://www.blogger.com/profile/07979568878714131398</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1055307259320776616.post-3062304201226533747</id><published>2012-07-09T14:52:00.001+01:00</published><updated>2012-07-22T13:45:04.904+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Bayes"/><category scheme="http://www.blogger.com/atom/ns#" term="Bayes text classifier"/><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><title type='text'>F# bayes text classifier</title><content type='html'>&lt;br /&gt;A F# implementable of &lt;a href=&quot;http://nlp.stanford.edu/IR-book/html/htmledition/naive-bayes-text-classification-1.html&quot; target=&quot;_blank&quot;&gt;text bayes classifier&lt;/a&gt;.&lt;br /&gt;&lt;h4&gt;            Input data structure&lt;/h4&gt;sampleDoc is a doc that has already been classified. i.e. training docs&lt;br /&gt;&lt;pre class=&quot;brush: js&quot;&gt;sampleDoc(docId,category_id,total_terms_count)&lt;/pre&gt;&lt;br /&gt;sampleTerm holds a list of doc posintgs with term appearance count. e.g (&quot;Obama&quot;, ((doc1, 10), (doc2, 20), (doc5, 15)...))&lt;br /&gt;&lt;pre class=&quot;brush: js&quot;&gt;sampleTerm(term,((docId,appearance count) list))&lt;/pre&gt;&lt;h4&gt;            Code&lt;/h4&gt;&lt;pre style=&quot;background-image: URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; namespace Data.Learner   &lt;br /&gt; module Classifier =  &lt;br /&gt;  //REF - http://nlp.stanford.edu/IR-book/html/htmledition/naive-bayes-text-classification-1.html  &lt;br /&gt;  //calculate probability for a category  &lt;br /&gt;  //catId: category Id  &lt;br /&gt;  //docs : int list: categoryId list  &lt;br /&gt;  //return: P(category)  &lt;br /&gt;  let private PCategory (catId : int) (docs : int list) =  &lt;br /&gt;   let catCount = List.choose(fun elem -&amp;gt;  &lt;br /&gt;    match elem with  &lt;br /&gt;     | elem when elem = catId -&amp;gt; Some(elem)  &lt;br /&gt;     | _ -&amp;gt; None) docs  &lt;br /&gt;   log (double(List.length catCount) / double(List.length docs)) &amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre style=&quot;background-image: URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;&lt;br /&gt;  //calculate probability for a term  &lt;br /&gt;  //docs : (int*int*int) list : category id * term appearance count * total terms count  &lt;br /&gt;  //catId: category Id  &lt;br /&gt;  //vocCount: vocabulary(terms) count  &lt;br /&gt;  //return: P(term)  &lt;br /&gt;  let private PTerm (docs : (int*int*int) list) (catId : int) (vocCount : int64) =   &lt;br /&gt;   let catDocs = List.choose(fun elem -&amp;gt;  &lt;br /&gt;    match elem with  &lt;br /&gt;     | (a, b, c) when a = catId -&amp;gt; Some(elem)  &lt;br /&gt;     | _ -&amp;gt; None) docs  &lt;br /&gt;   let appearanceCount = 1 + List.fold(fun acc (a, b, c) -&amp;gt; acc + b) 0 catDocs  &lt;br /&gt;   let totalTermsCount = List.fold(fun acc (a, b, c) -&amp;gt; acc + c) 0 catDocs  &lt;br /&gt;   log (double(appearanceCount) / (double(totalTermsCount) + double(vocCount))) &amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre style=&quot;background-image: URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;&lt;br /&gt;  //calculate probability for a doc in a specified category  &lt;br /&gt;  //sampleDocs : (int*int*int) list : docId * category id * total terms count  &lt;br /&gt;  //sampleTerms : (string * (int*int) list) list: term * (docId * appearance count)  &lt;br /&gt;  //terms: terms in doc  &lt;br /&gt;  //return: catId*appearance count*totlal terms count  &lt;br /&gt;  let private PDocInCategory (terms : string list) (sampleDocs : (int*int*int) list) (sampleTerms : (string * (int*int) list) list) catId =   &lt;br /&gt;   let getTermDocs term =   &lt;br /&gt;    let termDocPostings = sampleTerms |&amp;gt; List.choose (fun elem -&amp;gt;  &lt;br /&gt;                 match elem with  &lt;br /&gt;                 | elem when fst(elem) = term -&amp;gt; Some(elem)  &lt;br /&gt;                 | _ -&amp;gt; None)   &lt;br /&gt;    let getTermAppearanceCountForDoc docId : int =   &lt;br /&gt;                match termDocPostings.Length with  &lt;br /&gt;                         | 0 -&amp;gt; 0  &lt;br /&gt;                         | _ -&amp;gt; termDocPostings.Head |&amp;gt; snd |&amp;gt; List.choose(fun (a,b) -&amp;gt;   &lt;br /&gt;                                                                    match a with  &lt;br /&gt;                                                                    | a when a = docId -&amp;gt; Some(b)  &lt;br /&gt;                                                                    | _ -&amp;gt; Some(0))  &lt;br /&gt;                                                               |&amp;gt; List.head  &lt;br /&gt;    sampleDocs |&amp;gt; List.map(fun(a, b, c) -&amp;gt; (b, (getTermAppearanceCountForDoc a), c))  &lt;br /&gt;   let vocCount = int64(sampleTerms |&amp;gt; List.length)  &lt;br /&gt;   let pTerms = List.fold(fun acc (t) -&amp;gt;   &lt;br /&gt;    acc + (PTerm (getTermDocs t) catId vocCount)) (double 0) terms  &lt;br /&gt; //  let pCat = PCategory catId (sampleDocs |&amp;gt; List.map(fun(a, b, c) -&amp;gt; b))  &lt;br /&gt;   let pCat = sampleDocs |&amp;gt; List.map(fun(a, b, c) -&amp;gt; b) |&amp;gt; PCategory catId  &lt;br /&gt;   pCat + pTerms &amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre style=&quot;background-image: URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;&lt;br /&gt;  //sampleDocs : (int*int*int) list : docId * category id * total terms count  &lt;br /&gt;  //sampleTerms : (string * (int*int) list) list: term * (docId * appearance count)  &lt;br /&gt;  //terms: terms in doc  &lt;br /&gt;  //cats: all category ids  &lt;br /&gt;  //return top N categories has biggest probability  &lt;br /&gt;  let ClassifyDoc (terms : string list) (sampleDocs : (int*int*int) list) (sampleTerms : (string * (int*int) list) list) (cats : int list) (topN : int) =  &lt;br /&gt; //  let getPDocInCategory (cat : int) =   &lt;br /&gt; //   async { return (cat, PDocInCategory terms sampleDocs sampleTerms cat)}  &lt;br /&gt; //   &lt;br /&gt; //  let pCats : ((int * float)[]) =   &lt;br /&gt; //   cats  &lt;br /&gt; //   |&amp;gt; List.map getPDocInCategory  &lt;br /&gt; //   |&amp;gt; Async.Parallel  &lt;br /&gt; //   |&amp;gt; Async.RunSynchronously  &lt;br /&gt;   let pCats : ((int * float) list) = cats |&amp;gt; List.map(fun (cat) -&amp;gt;   &lt;br /&gt;                               let p = PDocInCategory terms sampleDocs sampleTerms cat  &lt;br /&gt;                               (cat, p))  &lt;br /&gt;   let rec getTopN (pCats : (int * float) list) =  &lt;br /&gt;    match pCats.Length with  &lt;br /&gt;     | n when n = topN -&amp;gt; pCats  &lt;br /&gt;     | _ -&amp;gt; getTopN pCats.Tail  &lt;br /&gt;   pCats |&amp;gt; List.sortBy (fun (c, p) -&amp;gt; p) |&amp;gt; getTopN  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;========================================================&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;http://www.vshopa.com/&quot; target=&quot;_blank&quot;&gt;Amazon hot deals. Twitter deals.&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://xxxinl.blogspot.com/feeds/3062304201226533747/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://xxxinl.blogspot.com/2012/07/f-bayes-text-classifier.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1055307259320776616/posts/default/3062304201226533747'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1055307259320776616/posts/default/3062304201226533747'/><link rel='alternate' type='text/html' href='http://xxxinl.blogspot.com/2012/07/f-bayes-text-classifier.html' title='F# bayes text classifier'/><author><name>Xin</name><uri>http://www.blogger.com/profile/07979568878714131398</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>