<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/starspace-for-nlp-nlproc/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.bnosac.be/index.php/blog/84-starspace-for-nlp-nlproc"> bnosac :: open analytical helpers - bnosac :: open analytical helpers</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Our recent addition to the NLP R universe is called <strong>R package ruimtehol</strong> which is open sourced at <a rel="nofollow" href="https://github.com/bnosac/ruimtehol" target="_blank">https://github.com/bnosac/ruimtehol</a> This R package is a wrapper around <a rel="nofollow" href="https://github.com/facebookresearch/StarSpace" target="_blank">Starspace</a> which provides a neural embedding model for doing the following on text:</p>
<ul>
<li><strong>Text classification</strong></li>
<li><strong>Learning word, sentence or document level embeddings</strong></li>
<li><strong>Finding sentence or document similarity</strong></li>
<li><strong>Ranking web documents</strong></li>
<li><strong>Content-based recommendation (e.g. recommend text/music based on the content)</strong></li>
<li><strong>Collaborative filtering based recommendation (e.g. recommend text/music based on interest)</strong></li>
<li><strong>Identification of entity relationships</strong></li>
</ul>
<p><img alt="logo ruimtehol" src="https://i1.wp.com/www.bnosac.be/images/bnosac/blog/logo-ruimtehol.png?w=450" data-recalc-dims="1"></p>
<p>If you are an R user and are interested in NLP techniques. Feel free to test out the framework and provide feedback at <a rel="nofollow" href="https://github.com/bnosac/ruimtehol/issues" target="_blank">https://github.com/bnosac/ruimtehol/issues.</a> The package is not on CRAN yet, but can be installed easily with the command <span>devtools::install_github(“bnosac/ruimtehol”, build_vignettes = TRUE)</span>.</p>
<p>Below is an example how the package can be used for multi-label classification on questions asked in Belgian parliament. Each question in parliament was labelled with several of one of the 1785 categories.</p>
<pre>library(ruimtehol)<br>data(dekamer, package = &quot;ruimtehol&quot;)<br><br>## Each question in parliament was labelled with more than 1 category. There are 1785 categories in this dataset<br>dekamer$question_themes &lt;- strsplit(dekamer$question_theme, &quot; +\\| +&quot;)<br>## Plain text of the question in parliament<br>dekamer$text &lt;- strsplit(dekamer$question, &quot;\\W&quot;)<br>dekamer$text &lt;- sapply(dekamer$text, FUN=function(x) paste(x, collapse = &quot; &quot;))<br>dekamer$text &lt;- tolower(dekamer$text)</pre>
<pre>## Build starspace model<br>model &lt;- embed_tagspace(x = dekamer$text, <br>                        y = dekamer$question_themes, <br>                        dim = 50, <br>                        ngram = 3, loss = &quot;hinge&quot;, similarity = &quot;cosine&quot;, adagrad = TRUE,<br>                        early_stopping = 0.8, minCount = 2, <br>                        thread = 4)</pre>
<pre>## Get embeddings of the dictionary of words as well as the categories<br>embedding_words  &lt;- as.matrix(model, type = &quot;words&quot;)<br>embedding_labels &lt;- as.matrix(model, type = &quot;label&quot;)</pre>
<pre>## Find closest labels / predict<br>embedding_combination &lt;- starspace_embedding(model, &quot;federale politie patrouille&quot;, type = &quot;document&quot;)<br>embedding_similarity(embedding_combination, <br>                     embedding_labels, <br>                     top_n = 3)<br><br>term1                                            term2 similarity rank<br>federale politie patrouille           __label__POLITIE  0.8480641    1<br>federale politie patrouille          __label__OPENBARE  0.6919607    2<br>federale politie patrouille __label__BEROEPSMOBILITEIT  0.6907637    3 </pre>
<pre>predict(model, &quot;de migranten komen naar europa, in asielcentra ...&quot;)<br>$input<br>&quot;de migranten komen naar europa, in asielcentra ...&quot;<br>$prediction<br>                label               label_starspace similarity<br> VLUCHTELINGENCENTRUM __label__VLUCHTELINGENCENTRUM  0.7075160<br>          VLUCHTELING          __label__VLUCHTELING  0.6253517<br>             ILLEGALE             __label__ILLEGALE  0.5997692<br>       MIGRATIEBELEID       __label__MIGRATIEBELEID  0.5939595<br>           UITWIJZING           __label__UITWIJZING  0.5376520</pre>
<p>The list of R packages regarding text mining with R provided by BNOSAC has been steadily growing. This is the list of R packages maintained by BNOSAC.</p>
<ul>
<li><a rel="nofollow" href="https://github.com/bnosac/udpipe" target="_blank">udpipe</a>: tokenisation, lemmatisation, parts of speech tagging, dependency parsing, morphological feature extraction, sentiment scoring, keyword extraction, NLP flows</li>
<li><a rel="nofollow" href="https://github.com/bnosac/crfsuite" target="_blank">crfsuite</a>: named entity recognition, text classification, chunking, sequence modelling</li>
<li><a rel="nofollow" href="https://github.com/bnosac/textrank" target="_blank">textrank</a>: text summarisation</li>
<li><a rel="nofollow" href="https://github.com/bnosac/ruimtehol" target="_blank">ruimtehol</a>: text classification, word/sentence/document embeddings, document/label similarities, ranking documengs, content based recommendation, collaborative filtering-based recommendation</li>
</ul>
<p>More details of ruimtehol at the development repository <a rel="nofollow" href="https://github.com/bnosac/ruimtehol" target="_blank">https://github.com/bnosac/ruimtehol</a> where you can also provide feedback.</p>
<h3><strong>Training on Text Mining <br></strong></h3>
<p>Are you interested in how text mining techniques work, then you might be interested in the following data science courses that are held in the coming months.<img alt="rtraining" src="https://i1.wp.com/www.bnosac.be/images/bnosac/blog/rtraining.png?w=456" data-recalc-dims="1"></p>
<ul>
<li>19-20/12/2018: Applied spatial modelling with R. Leuven (Belgium). Subscribe <a rel="nofollow" href="https://lstat.kuleuven.be/training/applied-spatial-modelling-with-r" target="_blank">here</a></li>
<li>21-22/02/2018: Advanced R programming. Leuven (Belgium). Subscribe <a rel="nofollow" href="https://lstat.kuleuven.be/training/coursedescriptions/AdvancedprogramminginR.html" target="_blank">here</a></li>
<li>13-14/03/2018: Computer Vision with R and Python. Leuven (Belgium). Subscribe <a rel="nofollow" href="https://lstat.kuleuven.be/training/coursedescriptions/ComputervisionwithRandPython" target="_blank">here</a></li>
<li>     15/03/2019: Image Recognition with R and Python: Subscribe <a rel="nofollow" href="https://lstat.kuleuven.be/training/coursedescriptions/Imagerecognition" target="_blank">here</a></li>
<li><strong>01-02/04/2019: Text Mining with R. Leuven (Belgium). Subscribe <a rel="nofollow" href="https://lstat.kuleuven.be/training/coursedescriptions/text-mining-with-r" target="_blank">here</a></strong></li>
</ul>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.bnosac.be/index.php/blog/84-starspace-for-nlp-nlproc"> bnosac :: open analytical helpers - bnosac :: open analytical helpers</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/QIO6490W3y0" height="1"></a></div>