Commit
·
df5b346
1
Parent(s):
3367556
cleanup syntax
Browse files- RunPhi15.cs +7 -6
RunPhi15.cs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
|
|
| 1 |
using System.Collections.Generic;
|
| 2 |
-
using UnityEngine;
|
| 3 |
-
using Unity.InferenceEngine;
|
| 4 |
using System.Text;
|
| 5 |
-
using
|
|
|
|
|
|
|
| 6 |
|
| 7 |
public class RunPhi15 : MonoBehaviour
|
| 8 |
{
|
|
@@ -58,8 +59,8 @@ public class RunPhi15 : MonoBehaviour
|
|
| 58 |
var graph = new FunctionalGraph();
|
| 59 |
var input = graph.AddInput(model1, 0);
|
| 60 |
var currentTokenInput = graph.AddInput<int>(new TensorShape(), "currentToken");
|
| 61 |
-
var row =
|
| 62 |
-
var output =
|
| 63 |
var model2 = graph.Compile(output);
|
| 64 |
|
| 65 |
engine = new Worker(model2, backend);
|
|
@@ -127,7 +128,7 @@ public class RunPhi15 : MonoBehaviour
|
|
| 127 |
void LoadVocabulary()
|
| 128 |
{
|
| 129 |
var jsonText = vocabAsset.text;
|
| 130 |
-
vocab =
|
| 131 |
tokens = new string[vocab.Count];
|
| 132 |
foreach (var item in vocab)
|
| 133 |
{
|
|
|
|
| 1 |
+
using System;
|
| 2 |
using System.Collections.Generic;
|
|
|
|
|
|
|
| 3 |
using System.Text;
|
| 4 |
+
using Newtonsoft.Json;
|
| 5 |
+
using Unity.InferenceEngine;
|
| 6 |
+
using UnityEngine;
|
| 7 |
|
| 8 |
public class RunPhi15 : MonoBehaviour
|
| 9 |
{
|
|
|
|
| 59 |
var graph = new FunctionalGraph();
|
| 60 |
var input = graph.AddInput(model1, 0);
|
| 61 |
var currentTokenInput = graph.AddInput<int>(new TensorShape(), "currentToken");
|
| 62 |
+
var row = Functional.Select(Functional.Forward(model1, input)[^1], 1, currentTokenInput);
|
| 63 |
+
var output = Functional.Multinomial(predictability * row, 1);
|
| 64 |
var model2 = graph.Compile(output);
|
| 65 |
|
| 66 |
engine = new Worker(model2, backend);
|
|
|
|
| 128 |
void LoadVocabulary()
|
| 129 |
{
|
| 130 |
var jsonText = vocabAsset.text;
|
| 131 |
+
vocab = JsonConvert.DeserializeObject<Dictionary<string, int>>(jsonText);
|
| 132 |
tokens = new string[vocab.Count];
|
| 133 |
foreach (var item in vocab)
|
| 134 |
{
|