-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathExample.php
54 lines (42 loc) · 1.41 KB
/
Example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
// Example usage:
// Include the class
require_once("Class.Tokenizer.php"); // If not in this file include the class
// Create a new tokenizer object
$tokenizer = new tokenizer();
$string = "Hello world foobar hello tree three";
// Encode the string
$encoded = $tokenizer->encode($string); // words to vocabulary token keys
// Print the encoded string
print_r($encoded);
// Array
// (
// [0] => 50195 // hello
// [1] => 98440 // world
// [2] => -1 // [foobar = UNKNOWN LEXEME]
// [3] => 50195 // hello
// [4] => 92285 // tree
// [5] => 90606 // three
// )
// Print the decoded string
$decoded = $tokenizer->decode($encoded); // Decode the string
// NOTE: 'Hello' is unknown so it becomes 'hello' which is in the vocabulary
print_r($decoded); // hello world hello tree three
$embedding = $tokenizer->GetEmbedding($encoded); // Get the embedding
// Not telling you what to do... but... you might want
// to feed the embedding into your neural network ;P
// Dont print the embedding its 99170 indexes long...
// you can print but... it's not very human readable
// Uncomment to print the embedding
//print_r($embedding);
// It looks like this:
// Array
// (
// ...
// [99165] => 1.0082419351834E-5
// [99166] => 1.0082419351834E-5
// [99167] => 1.0082419351834E-5
// [99168] => 1.0082419351834E-5
// [99169] => 1.0082419351834E-5
// [99170] => 1.0082419351834E-5
// )