Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Mastering Spark for Data Science

You're reading from  Mastering Spark for Data Science

Product type Book
Published in Mar 2017
Publisher Packt
ISBN-13 9781785882142
Pages 560 pages
Edition 1st Edition
Languages
Authors (4):
Andrew Morgan Andrew Morgan
Profile icon Andrew Morgan
Antoine Amend Antoine Amend
Profile icon Antoine Amend
Matthew Hallett Matthew Hallett
Profile icon Matthew Hallett
David George David George
Profile icon David George
View More author details

Table of Contents (22) Chapters

Mastering Spark for Data Science
Credits
Foreword
About the Authors
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
The Big Data Science Ecosystem Data Acquisition Input Formats and Schema Exploratory Data Analysis Spark for Geographic Analysis Scraping Link-Based External Data Building Communities Building a Recommendation System News Dictionary and Real-Time Tagging System Story De-duplication and Mutation Anomaly Detection on Sentiment Analysis TrendCalculus Secure Data Scalable Algorithms

Twitter and the Godwin point


With our text content properly cleaned up, we can feed a Word2Vec algorithm and attempt to understand the words in their actual context.

Learning context

As it says on the tin, the Word2Vec algorithm transforms a word into a vector. The idea is that similar words will be embedded into similar vector spaces and, as such, will look close to one another contextually.

Well integrated into Spark, a Word2Vec model can be trained as follows:

import org.apache.spark.mllib.feature.Word2Vec

val corpusRDD = tweetRDD
   .map(_.body.split("\\s").toSeq)
   .filter(_.distinct.length >= 4)

val model = new Word2Vec().fit(corpusRDD)

Here we extract each tweet as a sequence of words, only keeping records with at least 4 distinct words. Note that the list of all words needs to...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}