This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Utility function: Given the results of HuggingFace API, select the State with the highest score | |
/// </summary> | |
/// <param name="maxValue">Value of the option with the highest score</param> | |
/// <param name="maxIndex">Index of the option with the highest score</param> | |
private void Utility(float maxScore, int maxScoreIndex) | |
{ | |
// First we check that the score is > of 0.3, otherwise we let our agent perplexed; | |
// This way we can handle strange input text (for instance if we write "Go see the dog!" the agent will be puzzled). | |
if (maxScore < 0.20f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void Update() | |
{ | |
// Here's the State Machine, where given its current state, the agent will act accordingly | |
switch(state) | |
{ | |
default: | |
case State.Idle: | |
Debug.Log("STATE IDLE"); | |
break; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Enum of the different possible states of our Robot | |
/// </summary> | |
private enum State | |
{ | |
Idle, | |
Hello, // Say hello | |
Happy, // Be happy | |
Puzzled, // Be Puzzled | |
MoveTo, // Move to a pillar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// We receive a string like "[0.7777, 0.19, 0.01]", we need to process this data to transform it to an array of floats | |
/// [0.77, 0.19, 0.01] to be able to perform operations on it. | |
/// </summary> | |
/// <param name="result">json return from API call</param> | |
private IEnumerator ProcessResult(string result) | |
{ | |
// The data is a score for each possible sentence candidate | |
// But, it looks something like this "[0.7777, 0.19, 0.01]" | |
// First, we need to remove [ and ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public IEnumerator HFScore(string prompt) | |
{ | |
... | |
// Make the web request | |
UnityWebRequest request = UnityWebRequest.Put(model_url, bytes); | |
request.SetRequestHeader("Content-Type", "application/json"); | |
request.SetRequestHeader("Authorization", "Bearer " + hf_api_key); | |
request.method = "POST"; // Hack to send POST to server instead of PUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public IEnumerator HFScore(string prompt) | |
{ | |
// Form the JSON | |
var form = new Dictionary<string, object>(); | |
var attributes = new Dictionary<string, object>(); | |
attributes["source_sentence"] = prompt; | |
attributes["sentences"] = sentences; | |
form["inputs"] = attributes; | |
var json = Json.Serialize(form); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gym | |
from stable_baselines.common.policies import MlpPolicy | |
from stable_baselines.common.vec_env import DummyVecEnv | |
from stable_baselines import PPO2 | |
# Create the environment | |
env = gym.make('BipedalWalker-v2') | |
env = DummyVecEnv([lambda: env]) # The algorithms require a vectorized environment to run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import gym | |
from keras.models import Sequential | |
from keras.layers import Dense, Activation, Flatten | |
from keras.optimizers import Adam | |
from rl.agents.dqn import DQNAgent | |
from rl.policy import BoltzmannQPolicy | |
from rl.memory import SequentialMemory |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
NewerOlder