How to do it...

  1. Start a new project in IntelliJ or in an IDE of your choice. Make sure the necessary JAR files are included.
  1. The package statement for the recipe is as follows:
package spark.ml.cookbook.chapter12
  1. Import the necessary packages for Scala and Spark:
import org.apache.log4j.{Level, Logger}import org.apache.spark.ml.feature.{RegexTokenizer, StopWordsRemover, Word2Vec}import org.apache.spark.sql.{SQLContext, SparkSession}import org.apache.spark.{SparkConf, SparkContext}
  1. Let us define the location of our book file:
val input = "../data/sparkml2/chapter12/pg62.txt"
  1. Create a Spark session with configurations using the factory builder pattern:
val spark = SparkSession         .builder.master("local[*]")         .appName("Word2Vec App")

Get Apache Spark 2.x Machine Learning Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.