Skip to content

Instantly share code, notes, and snippets.

View georgeperry1's full-sized avatar

George Perry georgeperry1

View GitHub Profile
name: Production Build
on:
pull_request:
push:
branches:
- master
function run() {
Promise.all([
encodeData(comments),
encodeData(comment_testing)
])
.then(data => {
const {
0: training_data,
1: testing_data,
} = data;
const model = tf.sequential();
// Add layers to the model
model.add(tf.layers.dense({
inputShape: [512],
activation: 'sigmoid',
units: 2,
}));
model.add(tf.layers.dense({
const outputData = tf.tensor2d(comments.map(comment => [
comment.intent === 'buy' ? 1 : 0,
comment.intent === 'none' ? 1 : 0,
]));
// Output: [1,0] or [0,1]
@georgeperry1
georgeperry1 / encode.comment-analysis.js
Created July 12, 2019 14:33
encode.comment-analysis.js
const encodeData = data => {
const sentences = data.map(comment => comment.text.toLowerCase());
const trainingData = use.load()
.then(model => {
return model.embed(sentences)
.then(embeddings => {
return embeddings;
});
})
.catch(err => console.error('Fit Error:', err));
@georgeperry1
georgeperry1 / import-json.comment-analysis.js
Created July 12, 2019 14:09
import-json.comment-analysis.js
import * as tf from '@tensorflow/tfjs';
import '@tensorflow/tfjs-node';
import * as use from '@tensorflow-models/universal-sentence-encoder';
import comments from './comment-training.json';
import comment_testing from './comment-test.json';
@georgeperry1
georgeperry1 / test.comment-analysis.js
Created July 12, 2019 14:08
test.comment-analysis.js
[
{
"text": "where can I buy your dress?",
"intent": "buy"
},
{
"text": "how much was that dress?",
"intent": "buy"
},
{
@georgeperry1
georgeperry1 / training-buy.comment-analysis.js
Created July 12, 2019 14:04
training-none.comment-analysis.js
[
{
"text": "Woah yess❤️❤️",
"intent": "none"
},
{
"text": "Happy birthday to the most beautiful woman on Instagram ! 💗💗",
"intent": "none"
},
{
@georgeperry1
georgeperry1 / training-buy.comment-analysis.js
Last active July 12, 2019 14:03
training.comment-analysis.js
[
{
"text": "buy",
"intent": "buy"
},
{
"text": "buying",
"intent": "buy"
},
{
@georgeperry1
georgeperry1 / import.comment-analysis.js
Last active July 12, 2019 13:55
import.comment-analysis.js
import * as tf from '@tensorflow/tfjs';
import '@tensorflow/tfjs-node';
import * as use from '@tensorflow-models/universal-sentence-encoder';