Ad

Tuesday, February 18, 2020

Neo4j Graph Database Basics 2021-2022

Neo4j models graphs - relationships (edges) of nodes. It is in contrast with Relational Database, traditional tabular database. SQL Joints are expensive, costly, and hard-to-learn (confusing for analysts).  

Graph: a collection of nodes (Vertices) and relationships (Edges) that connect them. The math symbol of it is G(V, E). 

Graph data is everywhere in real life. It is intuitive to model real world data using graph models.

UI - Neo4j Browser

Neo4j Browser is the query workbench using JavaScript bolt under the hood. Bolt is a binary protocol, a fast one, Neo4j uses for connections. 


Data Modeling

First step of getting started with graph database is to model the data in a graph. It is important to model and store data as a graph. 

Neo4j uses a property graph model. 

Neo4j can store direction one way but can query either ways. There are four main elements: node, can be labeled, similar to SQL table name, can have key property value pairs. Property can go on node or labels. 

Node
Relationship
Labels 

Data modeling can be done with a white board or using apjones Arrows App 

Relationship edge can also have property associated with it. 

Cypher

Cypher is the language developers use to make queries against a graph / retrieve information from a graph. It also controls what results are returned. Developers also use cypher to create nodes and relationships, modify nodes and relationships in a graph. 
Neo4j cypher query executed in session get back cursor of records

Cypher is an open sourced graph database query language, a part of the open cypher project. Other graph databases use cypher too. Not just Neo4j

Cypher versus SQL Comparison

MATCH ~= FROM
WHERE ~= WHERE
RETURN ~= SELECT

View Schema

Call apoc to view schema
https://neo4j.com/developer/kb/viewing-schema-data-with-apoc/

WHERE CLAUSE allows developers to filter nodes and relationships. 

CRUD with Cypher Neo4j

SELECT STATEMENT
SELECT all nodes
MATCH (n)
RETURN n

SELECT all nodes with a specific label
MATCH (n:Label)
RETURN n

Match all relationships in neo4j graph
MATCH(m)--(n)
RETURN m, n

Neo4j create statement
CREATE(nodefirst:Label {propertname:"Property Name", propertyagain:99999})
CREATE (nodeagain)-[:REL_TO { roleproperty: ["List Item"]}]->(nodefirst)

Merge operation: equivalent of a SQL update, first look up if node exists, if not create it, don't create duplicates / new record if a record already exists. Get or Create.  

Call - cypher keyword to call functions and procedures

Read more about user defined procedures source 11

You try write and customize your own procedure
Cypher styling and query guide source 12

Graph database can also be queried and modeled using ORMs. 



APOC

Neo4j procedures (apoc) are community driven code modules. There are high quality NLP apoc procedures for Neo4j. 

"Just in time for GraphConnect, Michael released version 3.4.0.3 of the popular APOC library. This release has support for defining custom procedures and functions implemented in plain Cypher and then calling them like regular ones, as well as a new procedure for scraping web pages" - May 2020 

11- https://neo4j.com/docs/java-reference/current/extending-neo4j/procedures-and-functions/procedures/
12- https://neo4j.com/docs/cypher-manual/current/styleguide/
Use cases for Neo4j:
Salmon researchers, salmon hatchling in northern atmosphere, knowledge graph, information management.
Graphs, in general, is great for highly connected data. 
Neo4j for journalist
Panama paper is available as a sandbox dataset
Investigative journalist: panama paper paradise paper
Relationship model can be super insightful in data analysis and for relationship modeling, Neo4j is great.



Can even use graph for chemicals drug discovery



Use for recommendation collaborative filtering



Fraud prevention











Use graph when context matters. How did the data result happen?







Graphing interaction data is also very useful. Relationship data is important.







Neo4j lead data scientist Alicia Frame PhD talks works on graph algorithms







Learn Neo4j (Neo4j Tutorials)

Neo4j Sandbox Feature : Neo4j tutorials can be run in Neo4j Sandboxes

Use :play to launch Neo4j tutorials

Using the :play feature in Neo4j sandbox and sandbox datasets, you can give your cypher skill a try and get started with Neo4j. It is insightful, easy and a lot of fun.

You can create your own Neo4j Browser Guide (tutorial). 

Graph Academy


Neo4j 4.0

Advanced Neo4j Experts

You can become a Neo4j Ninja, Neo4j expert, and join the Neo4j Speaker Program. Neo4j investigative journalism program

Certification available

Neo4j Community and Neo4j Universe

"GraphXR is a browser-based visual analytics platform that delivers unprecedented speed, power, and fluidity to anyone working with connected, high-dimensional, and big data." GraphXR in its own words.

Become a super user
Become a Neo4j Ninja
 
Load CSV

GRANDSTACK - Hosting Neo4j Website

Neo4j Desktop : allows managing multiple projects databases
Neo4j Graph Apps: graph apps are applications that interact with Neo4j database through the desktop app. Graph apps are single page applications (SPAs) that are built with vanilla JavaScript or front end web development frameworks. 


Advanced Algorithms with Neo4j  | Advanced Graph Algorithms
The study of graph theory and graph algorithms is set to be pioneered by Euler.  The interesting problem The Seven Bridges of Königsberg is solved using graph concepts. 

Use call to launch Neo4j helper functions, stored procs, and algorithms

Algorithms:
Page Rank


Neo4j NLP library

Launch Neo4j on google cloud

Can host a Neo4j graph database and deploy using GKE. 

Launching Neo4j on Google Kubernetes Market Place
 https://medium.com/google-cloud/launching-neo4j-on-googles-kubernetes-marketplace-97c23c94e960
Neo4j prefers SSDs.
A strong password is automatically chosen. Not neo4j's typical default.
Retrieve it in cloud shell. 
 $ kubectl get secrets my-graph-neo4j-secrets -o yaml | grep neo4j-password: | sed 's/.*neo4j-password: *//' | base64 --decode
3lg81oVvGY



Graph Academy | Getting Certified
Certification exam 
Duration 1 hour 80 questions
Introduction to Neo4j Online Course and Tutorial
Duration 1 day
Course Outline
Introduction to Graph Databases
Introduction to Neo4j
Setting up your Development Environment Tutorial
Introduction to Cypher
Getting More out of Queries
Creating Nodes and Relationships
Getting More out of Neo4j

graphaware has plugin for tokenization
3rd party natural language processing platform for neo4j graphs

Using Python with Neo4j py2neo

Friday, February 7, 2020

Develop a smart Twilio app 2020 - for SMS phone voice or fax

Key Twilio Concepts

  • TwiML pronounced tweemle and ML does not stand for machine learning. "TwiML (the Twilio Markup Language) is a set of instructions you can use to tell Twilio what to do when you receive an incoming call, SMS, or fax." - official documentation
    • "When someone makes a call to one of your Twilio numbers, Twilio looks up the URL associated with that phone number and sends it a request. Twilio then reads the TwiML instructions hosted at that URL to determine what to do, whether it's recording the call, playing a message for the caller, or prompting the caller to press digits on their keypad."


Twilio Customers and Use Cases

Lyft and Uber both use Twilio for SMS and customer support. See more on the customers page and use case landing page. 

Cool products by Twilio

  • Twilio Studio for drag and drop app building released Jan 2018
  • Twilio Flex source 20
  • Twilio Function (beta as of Feb 2020) 
Tutorial Twilio + Flask + Spotify API
The spotify API is deprecated but this tutorial still shows you how to use Twilio with Flask.
To make the Flask app online, accessible by Twilio use ngrok


Sources

20 - https://www.twilio.com/flex
2- Getting start with Twilio examples, code snippet : twilio.com/code-exchange

Wednesday, February 5, 2020

Getting started with Alexa 2021 for Developers

It is not too late to get started coding for Alexa - making Alexa skills. Let's get started! updated December 2021. 


Design

Alexa design : Why Voice Design Matters: We Don’t Speak the Way We Write (2018) 
https://developer.amazon.com/blogs/alexa/post/96f434ac-430b-426c-a457-ebabcd20c0fd/why-voice-design-matters-we-don-t-speak-the-way-we-write
  • Workflow: Build Test Launch and Measure
  • Use the Alexa Developer Console
  • Start with a custom skill or Flash Briefing or Smart Home or Video skill
  • Invocation name that is unique for your Alexa app
  • Build an interaction model voice user interface (VUI)VUI (specific to voice apps)
  • Need to provide examples, sample utterance
Wake word wakes up Alexa, for example "Alex, reminder me to ..." Alexa is the wake word.

Details


  • How user interacts with Alexa? How does it work Source 1 (also see above image from source 5)
  • Innovation name is used often, succinct and unique is good
  • Intent is what your skill app can do
  • Utterances is how or the language that users expresses to your skill the right intent
  • Slot accept inputs from users
  • Connect other APIs use interfaces
  • JSON editor. You can use the visual console to enter intents and utterances or you can write JSON code.
  • Specify end point where the code will live. End point receives request. "where the custom logic will live". Not the interaction model. 
Source 6

User Alexa Interactions

  • The user says the wake word, Alexa.
  • Alexa hears the wake word and listens.
  • The Alexa service uses the interaction model to figure where to route the request.
  • A JSON request is sent to the skill's lambda function.
  • The lambda function inspects the JSON request.
  • The lambda function determines how to respond.
  • The lambda function sends a JSON response to the Alexa service.
  • The Alexa service receives the JSON response and converts the output text to an audio file.
  • The Alexa-enabled device receives and plays the audio.
Direct quote from Source 5

Free Alexa Developer Training Course

Use this full end-to-end training course from Amazon Source 5

Best practice

  • Welcome prompt is important. Provide important information.
  • Avoid jargons - difficult or professional words that are hard for users to recall, use or understand. See what I did there? Avoided jargons. 
  • Use conversations that are natural. Ironically, you should even test if your conversation models are natural. Does it understand common utterances - things users say or use? Is it what the users expect?
  • One breath test: dialogs should be finished in one breath
  • Read out loud to test the dialog scripts
  • Can use Alexa simulator to test. 
  • Recommend testing and get user feedback before submitting for certification
  • Take pauses 
<speak>
text here <break time="600ms"/> more text here
</speak>

More best practices source 7



Create Alexa Skills with Blueprint

Blueprint is the no-code way to get started building with Alexa. Minimum coding skills required! It's possible to non-engineers to build a common pattern alexa app quickly using Alexa Blueprint!

Example Flash Briefing Blueprint Source 12

Create Alexa Skills with APIs

Some available APIs.

Create Alexa without code


Alexa for Gaming

Read the document or join a hackathon to learn more.

Backend



    • The backend is usually a lambda function and is interacted via a lambda endpoint
    • A simple storage service (S3) is provisioned if hosted on AWS

    Other resources


    • Amazon often hosts Build Your First Alexa Skill in 1 Hour Webinars
    • Udacity Natural Language Processing nanodegree (NLP) for deep learning and machine learning teaches Alexa and IBM Watson skills.
    • Twilio Autopilot can build smart language interaction models based on sample utterances, and outputs JSON files that can integrate with Alexa.
    • Shark Tank Mark Cuban talks about how he uses Alexa and why developers should develop for Alexa. Source 8
    • Amazon Pay in Alexa example Blu ai Source 9
    • Alexa Skills Kit Developer Console Source Source 11
    • Alexa for Business allows businesses to host private skills within the organization Source 13
    • You can write Alexa backend in either Node.js or Python
    • Alexa can speak other languages such as English, Japanese, Spanish, Italian etc. Unfortunately it cannot speak Chinese right now. Source 14
    • Alexa is on many IoT devices including driving speakers, and Facebook Portal photo frame and video call. 

    Branding

    Can brand with a sound or a familiar tune. 


    Sources

    6-  https://youtu.be/q-mrSBrlDso
    7 - https://developer.amazon.com/blogs/alexa/post/d92c7822-d289-44fd-a9fe-9652874fc3c9/five-benchmarks-for-writing-dialog-that-sounds-great-to-alexa-customers
    8 - https://youtu.be/DOWXIWJF3lk
    9 - https://blu.ai/?ld=ELNALPA-go.payments.amazon.com
    10 - Best practices https://developer.amazon.com/blogs/alexa/post/d92c7822-d289-44fd-a9fe-9652874fc3c9/five-benchmarks-for-writing-dialog-that-sounds-great-to-alexa-customers
    11 - https://youtu.be/q-mrSBrlDso
    12 - Flash Briefing https://blueprints.amazon.com/bp/amzn.ask.bp.0758a769-9b10-4089-9679-1791ee6bfa5f
    13 - https://aws.amazon.com/about-aws/whats-new/2017/11/alexa-for-business-is-now-generally-available
    14 - https://developer.amazon.com/en-US/docs/alexa/custom-skills/develop-skills-in-multiple-languages.html

    Sunday, January 26, 2020

    Handling Imbalanced Dataset in Machine Learning


    • Imbalanced dataset can affect machine learning decision boundaries.
    • Distribution of target class matters!
    • Why is imbalanced class bad - source 1
    • Sometimes imbalanced dataset is "good" such as in fraud detection. It is important to find those anomalies. 
    • "imbalancec class puts accuracy out of business". It is important to not choose accuracy as metric because the model can cheat by just guessing the majority class and achieve high accuracy. The high accuracy in this case is an illusion. It is about using a trade-off of precision and recall, confusion matrix.

    Related Concepts:
    • Imbalanced datasets
    • Confusion matrix
    • Resampling
    • Random under-sampling
    • Random over-sampling
    • Python imbalanced-learn module
    • Random under-sampling and over-sampling with imbalanced-learn
    • Under-sampling: Tomek links
    • Under-sampling: Cluster Centroids
    • Over-sampling: SMOTE
    Source 4


    Wednesday, January 22, 2020

    Applying to Graduate School Master Degree and PhD

    After transitioning to machine learning, I had to learn it the hard way that it is now very competitive and difficult to get into graduate school. Engineering departments are crammed. Here are some difficult lessons I have learned. I am not admissions, I don't know what's the best, but I know what didn't work.

    • Not having strong recommendations letters
      • Without strong recommendation letters, nothing works. It's important to build that network out in the long strong: peers and supervisors in a work or academic setting is especially important
    • Not having a strong personal statement
      • I made the mistake of focusing on my technical skills. There are always people who are better than me. I should have had a narrative, a bigger picture. Higher performance.
      • Even writing papers they require you to write about why the research project matters to me personally.  

    Know your AWS SageMaker by Amazon Web Services

    How AWS Describes SageMaker:

    "Amazon SageMaker provides a fully managed service for data science and machine learning workflows. One of the most important capabilities of Amazon SageMaker is its ability to run fully managed training jobs to train machine learning models." Source 1

    The Estimator Object

    S3 Storage

    AWS SageMaker instance types

    Note AWS Sagemaker instances are now separated from EC2 instances, and can differ by region. It is has accelerated computing options more commonly known as GPUs such as ml.p2.xlarge.

    See the full list of AWS Sagemaker instances here Source 2

    There's a comprehensive table of instance type, vCPU count, GPU, Mem (GiB), GPU Mem (GiB), a simple description of Network Performance.

    Optimization Bring your data to AWS
    Previously all file has to be stored in S3 now you can use Amazon's distributed systems.
    "Training machine learning models requires providing the training datasets to the training job. Until now, when using Amazon S3 as the training datasource in File input mode, all training data had to be downloaded from Amazon S3 to the EBS volumes attached to the training instances at the start of the training job. A distributed file system such as Amazon FSx for Lustre or EFS can speed up machine learning training by eliminating the need for this download step." 
    Amazon FSx for Lustre or Amazon Elastic File System (EFS) Source 1


    Can train as well as deploy model

    Fully managed serverless. You can train as well as deploy a model. Be sure to know that you can choose the instance type for each : train or deploy and each can utilize the same or a difference compute instance type 

    Get SageMaker AWS AI Certified

    The certificate exam is not easy and requires study as well as actual years of experience. But SageMaker is a relatively new technology so may be the standard isn't too hard yet. Src 3. 

    Sources:
    2. https://aws.amazon.com/sagemaker/pricing/instance-types/
    3. https://aws.amazon.com/certification/certified-machine-learning-specialty/

    Sunday, December 29, 2019

    Convert Tensorflow 1.0 to Tensorflow 2.0


    • Specify Tensorflow version in Google Colab `%tensorflow_version 2.x`. It is not recommended to use pip install in Google Colab: quote "We recommend against using pip install to specify a particular TensorFlow version for GPU backends. Colab builds TensorFlow from source to ensure compatibility with our fleet of GPUs. Versions of TensorFlow fetched from PyPI by pip may suffer from performance problems or may not work at all." 
    • Check tensorflow version after installing `import tensorflow` `print(tensorflow.__version__)`
    • TPU for Tensorflow 2.0 is not yet available. "TPUs are not fully supported in Tensorflow 2.0. We expect they will be supported in Tensorflow 2.1. Follow along on GitHub."
    • tf.layers from Tensorflow 1.0 is going away in Tensorflow 2.0
    • Previously use keras pip install keras
    • Currently in Tensorflow 2.0 use keras : from tensorflow import keras

    React UI, UI UX, Reactstrap React Bootstrap

    React UI MATERIAL  Install yarn add @material-ui/icons Reactstrap FORMS. Controlled Forms. Uncontrolled Forms.  Columns, grid