Dominic Elm
Uri Shaked
@elmd_
@UriShaked
@UriShaked
Angular Connect 2018
How to AI in JS? - Assim Hussain
@UriShaked
@UriShaked
@UriShaked
Given a function signature, can we create a model that will predict the body of that function?
@UriShaked
@UriShaked
email = 'How to be a Millionaire in 4 weeks'
if (email contains 'Millionaire')
markAsSpam(email)
else if (email contains '...')
...
else if (email contains '...')
...
data = [
('How to be a Millionaire in 4 weeks', SPAM),
('...', NO_SPAM),
('...', NO_SPAM),
('...', SPAM),
...
]
for example in data:
classify data
optimize
Traditional Program
ML Program
@UriShaked
@UriShaked
...
120
4
24.4
square meters
#bedrooms
0.2
0.1
120 x 0.2
4 x 0.1
+
@UriShaked
...
120
4
24.4
square meters
#bedrooms
0.2
0.1
120 x 0.2
4 x 0.1
+
15
9.4
ERROR
@UriShaked
...
120
4
12.2
square meters
#bedrooms
0.1
0.05
120 x 0.1
4 x 0.05
+
15
-2.8
ERROR
@UriShaked
Input
Hidden
Output
@UriShaked
@UriShaked
function greet(name: string)
function greet(name: string) {
const prefix = name.length < 10 ? 'Hi' : 'Hello';
return prefix + name;
}
@UriShaked
{
function greet(name: string) {
const prefix = name.length < 10 ? 'Hi' : 'Hello';
return prefix + name;
}
function greet(name: string)
@UriShaked
const
function greet(name: string) {
const prefix = name.length < 10 ? 'Hi' : 'Hello';
return prefix + name;
}
function greet(name: string)
@UriShaked
prefix
function greet(name: string) {
const prefix = name.length < 10 ? 'Hi' : 'Hello';
return prefix + name;
}
function greet(name: string)
@UriShaked
Gather Data
Clean Data
Choose Model
Training
Evaluation
@UriShaked
@UriShaked
How can we quickly gather a lot of function examples?
Look at open source projects on GitHub
@UriShaked
We filtered only TypeScript files and extracted 324,280 TypeScript functions and collected them in a huge JSON file.
Using Google BigQuery we can run an SQL query to fetch all the code on GitHub in under a minute!
@UriShaked
function greet(name: string) {
const prefix = name.length < 10 ? 'Hi' : 'Hello';
return prefix + name;
}
@UriShaked
2
Prepare model inputs
1
Preprocess raw dataset
function greet(name: string)
Split signature from body
{
const prefix = name.length < 10 ? 'Hi' : 'Hello';
return prefix + name;
}
@UriShaked
function greet($arg0$: string)
Rename function parameters
{
const prefix = $arg0$.length < 10 ? 'Hi' : 'Hello';
return prefix + $arg0$;
}
@UriShaked
2
Prepare model inputs
1
Preprocess raw dataset
function greet($arg0$: string)
Rename identifiers and literals
{
const id0 = $arg0$.id1 < 2 ? '3' : '4';
return id0 + $arg0$;
}
@UriShaked
2
Prepare model inputs
1
Preprocess raw dataset
function greet ( $arg0$ : string )
Space tokens
{
const id0 = $arg0$ . id1 < 2 ? '3' : '4' ;
return id0 + $arg0$ ;
}
@UriShaked
2
Prepare model inputs
1
Preprocess raw dataset
function greet ( $arg0$ : string )
Add START and END symbols
START {
const id0 = $arg0$ . id1 < 2 ? '3' : '4' ;
return id0 + $arg0$ ;
} END
@UriShaked
2
Prepare model inputs
1
Preprocess raw dataset
Create Model Inputs and Outputs
Input
Ouput
function greet ( $arg0$ : string )
START
{
function greet ( $arg0$ : string )
START {
const
function greet ( $arg0$ : string )
START { const
id0
@UriShaked
2
Prepare model inputs
1
Preprocess raw dataset
Building a dictionary with all tokens
function greet ( $arg0$ : string )
START {
const id0 = $arg0$ . id1 < 2 ? '3' : '4' ;
return id0 + $arg0$ ;
} END
dict = {
'function': 1,
'greet': 2,
'(': 3,
'$arg0$': 4,
':': 5,
'string': 6,
')': 7,
'START': 8,
'{': 9,
...
}
@UriShaked
2
Prepare model inputs
1
Preprocess raw dataset
Text to Sequence
function greet ( $arg0$ : string )
[1, 2, 3, 4, 5, 6, 7]
Add Padding
[0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7]
[1, 2, 3, 4, 5, 6, 7]
function isPrime ( $arg0$ : number )
[1, 13, 3, 4, 5, 23, 7]
@UriShaked
2
Prepare model inputs
1
Preprocess raw dataset
Encode Output
{
Next Token(Y)
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
One Hot Encoding
9
string
[0, 0, 0, 0, 0, 0, 1, 0, 0, 0]
6
@UriShaked
2
Prepare model inputs
1
Preprocess raw dataset
@UriShaked
@UriShaked
@UriShaked
@UriShaked
Google Colab
@UriShaked
Google Cloud TPU (TensorFlow Processing Unit)
@UriShaked
Evaluating the performance of the model
@UriShaked
@UriShaked
@UriShaked
https://urish.org