Giter Club home page Giter Club logo

pynotes's Introduction

PyNotes

Transformers

My notebooks on using Tranformer models off-line for fine-tuning and prediction purposes.

May the Spark โญ be with you

My notebook on using Python with Jupyter Notebook, PySpark and other well known machine learning frameworks.

SparkNLP

Write a PySpark Array of Strings as String into ONE Parquet File

Use Case

You can use a PySpark Tokenizer to convert a string into tokens and apply machine learning algorithms on it. The code snippets below might be useful if you want to inspect the result of the tokenizer (an array of unicode strings) via csv file (saved in a Parquet environment).

Code

df.select("words").show()
+--------------------+
|               words|
+--------------------+
| [I, am, looking,...|
|     [not, today,...|
|   [but, tomorrow...|
+--------------------+
# Select column with array of words into seperate DataFrame
dfSave = df.select("words")

#dfSave.printSchema()
# root
#  |-- words: array (nullable = true)
#  |    |-- element: string (containsNull = true)
#

import pyspark.sql.functions as F

# Convert Array of unicode strings into a string using PySpark's function
# https://stackoverflow.com/questions/38924762/how-to-convert-column-of-arrays-of-strings-to-strings
dfSave = dfSave.withColumn("words_str", F.concat_ws(" ", dfSave["words"]))

# drop arrays of strings column
dfSave = dfSave.drop("words")

# Write dataframe with string into ONE parquet file
# https://stackoverflow.com/questions/42022890/how-can-i-write-a-parquet-file-using-spark-pyspark
# https://stackoverflow.com/questions/36162055/pyspark-spit-out-single-file-when-writing-instead-of-multiple-part-files
dfSave.coalesce(1).write.format('csv').save('/home/me/tokenized.csv')

Neural Networks

pynotes's People

Contributors

dirkster99 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.