@good-i-deer/node-red-contrib-cosine-similarity
v1.0.1
Published
Calculates cosine similarity of two vector values in Node-RED
Downloads
8
Readme
@GOOD-I-DEER/node-red-contrib-cosine-similarity
This module provides a node that calculates cosine similarity of two vector values in Node-RED.
This node requires node.js version 18.16.1 and Node-RED version 3.1.0.
Description
This node calculates cosine similarity between two vectors and return it as an array. It can calculate multiple arrays of vectors. The output can be used for detecting if there are cases where the similarity is above a cerain value.
var input_array1 = [
[ "arrays of vectors 1" ],
[ "arrays of vectors 2" ],
[ "arrays of vectors 3" ]
]
var input_array2 = [
[ "arrays of vectors 4" ],
[ "arrays of vectors 5" ],
[ "arrays of vectors 6" ]
]
var outout_array = [
[ "arrays of cosine similarity between input_array2 and arrays of vectors 1" ],
[ "arrays of cosine similarity between input_array2 and arrays of vectors 2" ],
[ "arrays of cosine similarity between input_array2 and arrays of vectors 3" ]
]
Pre-requisites
The node-red-contrib-cosine-similarity requires Node-RED to be installed.
Install
cd ~/.node-red
npm install @good-i-deer/node-red-contrib-cosine-similarity
Restart your Node-RED instance
Input
Array of Vector Arrays
- The input is an array of vector arrays.
property
Name
- The name of the node displayed on the screen.
File
- File path of file that contains another array of vector arrays. This file will be compared with the input vector array. Can not be empty.
Output
Array of Cosine Similarity Arrays
- The output is an array of cosine similarity arrays. Each cosine similarity is similarity between vector of input and vector of file.
Examples
Here are some example flows of cosine similarity.
JSON
[
{
"id": "02168a0656dc6f37",
"type": "tab",
"label": "Example Flow",
"disabled": false,
"info": "",
"env": []
},
{
"id": "0e57c1a384a6551d",
"type": "calculate-cosine",
"z": "02168a0656dc6f37",
"name": "",
"file": "C:\\Users\\SSAFY\\Desktop\\ssdc\\object\\vectors\\stored.txt",
"x": 350,
"y": 80,
"wires": [
[
"71c649b78711fc2a"
]
]
},
{
"id": "a1704726f1bf888d",
"type": "function",
"z": "02168a0656dc6f37",
"name": "temp function1",
"func": "msg.payload = msg.payload[0];\nreturn msg",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 120,
"y": 80,
"wires": [
[
"0e57c1a384a6551d"
]
]
},
{
"id": "71c649b78711fc2a",
"type": "debug",
"z": "02168a0656dc6f37",
"name": "Similarity Value",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 570,
"y": 80,
"wires": []
}
]
Discussions and suggestions
Use GitHub Issues to ask questions or to discuss new features.
Authors
GOOD-I-DEER in SSAFY(Samsung Software Academy for Youth) 9th
Copyright and license
Copyright Samsung Automation Studio Team under the Apache 2.0 license