Code Monkey home page Code Monkey logo

spark-lsh's Introduction

Locality Sensitive Hashing (LSH) using Spark for Clustering

to be updated.

df = spark.read.format("csv").option("header",True) .load("data.csv")
df.show(truncate=False)
+---+------------------------------------------------------------------------------+
|id |Text                                                                          |
+---+------------------------------------------------------------------------------+
|1  |This is an example. Let's see if it can produce hashes close to the next line.|
|2  |This is another example. It should produce hashes close to the previous line. |
|3  |here we are using a different text and saying hello world!                    |
|4  |hello world! is different here because we are using and saying them first.    |
+---+------------------------------------------------------------------------------+
LSH_pipeline = build_LSH_pipeline(inputCol="Text", outputCol="hashes", n_ngram=3, seedValue=110, p=5)

train_df = df.select("Text")
trained_LSHModel = LSH_pipeline.fit(train_df)
trained_LSHModel.write().overwrite().save(MODEL_PATH)
saved_LSHModel = PipelineModel.load(MODEL_PATH)

df = saved_LSHModel.transform(df).select("id", "Text", "hashes")
df.show(truncate=False)

+---+------------------------------------------------------------------------------+-------------------------------------------------+
|id |Text                                                                          |hashes                                           |
+---+------------------------------------------------------------------------------+-------------------------------------------------+
|1  |This is an example. Let's see if it can produce hashes close to the next line.|[21235875, 6320997, 3753495, 724070, 415965]     |
|2  |This is another example. It should produce hashes close to the previous line. |[21235875, 13769064, 1722002, 724070, 415965]    |
|3  |here we are using a different text and saying hello world!                    |[31557483, 47151896, 5784988, 21384188, 870083]  |
|4  |hello world! is different here because we are using and saying them first.    |[31557483, 39703829, 5784988, 21384188, 18556512]|
+---+------------------------------------------------------------------------------+-------------------------------------------------+

spark-lsh's People

Contributors

saaay71 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.