diff --git a/data/sentence_function/labels.txt b/data/sentence_function/labels.txt new file mode 100644 index 0000000..e69de29 diff --git a/data/sentence_function/sentences.txt b/data/sentence_function/sentences.txt new file mode 100644 index 0000000..e69de29 diff --git a/docs/acceptable_mistakes.txt b/docs/acceptable_mistakes.txt new file mode 100644 index 0000000..3470dec --- /dev/null +++ b/docs/acceptable_mistakes.txt @@ -0,0 +1,5 @@ + +Greeting function misinterpretation +Misinterpreting a greeting sentence as an information-querying sentence is an acceptable mistake. +Lots of people make it when greeted with "How are ya?" + diff --git a/docs/concepts_to_graph.txt b/docs/concepts_to_graph.txt new file mode 100644 index 0000000..c503a3e --- /dev/null +++ b/docs/concepts_to_graph.txt @@ -0,0 +1,10 @@ + + +A list of things to consider fleshing out in the web + + +Qualia + + + + diff --git a/docs/feature_justification.txt b/docs/feature_justification.txt new file mode 100644 index 0000000..bc3ef34 --- /dev/null +++ b/docs/feature_justification.txt @@ -0,0 +1,22 @@ + + +Arguments justifying different features + + + +Information Priority +Pieces of information have different priorities and should be handled accordingly. +Keep a 'hot' web of the most important parts of info that should immediately be searchable every frame. +This can link into 'colder' webs that store lower priority information. +Will have this with both relations and nodes in the web. +To justify for nodes, some people in your life are of higher importance than others to remember. +You don't keep all people you know immediately accessible in your brain. +To justify for relations, relations between specific numbers are thrown out almost immediately when done solving a math problem. + + +Layered webs +If you have a conversation about the color of a hat, you will not store the color of the hat in your immediately accessible brain long term. +This lets you not constantly scan a huge repertoire of information when you want to perform day-to-day tasks. +Thus, I want to create an information heirarchy to mimic this and make engineering potentially easier. + + diff --git a/docs/mantas.txt b/docs/mantas.txt new file mode 100644 index 0000000..fbbf2e4 --- /dev/null +++ b/docs/mantas.txt @@ -0,0 +1,6 @@ + +1. keep it simple, stupid + +2. make everything easily debug-able + +3. work on a single sentence at a time diff --git a/improvement_ideas.txt b/improvement_ideas.txt index f325292..3bb1450 100644 --- a/improvement_ideas.txt +++ b/improvement_ideas.txt @@ -1 +1,11 @@ -summarize previous statements to provide context instead of using full statement \ No newline at end of file + +summarize previous statements to provide context instead of using full statement + +Come up with strategies for culling the number of connections in the knowledge web + - Particularly, connections used during immediate processing + - don't need to keep track of the color of the paper that a sentence you're going to forget about is written on + - Assign value weight to different nodes in web and use that to periodically clean web (?) + +Layered webs + - Have more fine grained processing data get pushed into a lower priority web that is not immediately searched all the time + - ie low value detail relations, like colors or other qualities of objects, relations between people, etc diff --git a/src/main/java/org/studiorailgun/conversation/evaluators/GreetingEval.java b/src/main/java/org/studiorailgun/conversation/evaluators/GreetingEval.java new file mode 100644 index 0000000..be5ef63 --- /dev/null +++ b/src/main/java/org/studiorailgun/conversation/evaluators/GreetingEval.java @@ -0,0 +1,20 @@ +package org.studiorailgun.conversation.evaluators; + +/** + * Evaluates a greeting + */ +public class GreetingEval { + + /** + * Evaluates a greeting + * @param input The sentence + */ + public static void evaluate(String input){ + switch(input){ + case "Hello": { + + } break; + } + } + +} diff --git a/src/main/java/org/studiorailgun/conversation/semantic/SentenceSubjectParser.java b/src/main/java/org/studiorailgun/conversation/semantic/SentenceSubjectParser.java index ff1d113..477cb5f 100644 --- a/src/main/java/org/studiorailgun/conversation/semantic/SentenceSubjectParser.java +++ b/src/main/java/org/studiorailgun/conversation/semantic/SentenceSubjectParser.java @@ -36,6 +36,10 @@ public class SentenceSubjectParser { // System.out.println(model.functions().get(0).signature().getInputs().values().iterator().next().shape); } + /** + * Evaluates a sentence + * @param sentence The sentence to evaluate + */ public void evaluate(String sentence){ //run predict TInt64 tensor = TInt64.scalarOf(10); diff --git a/src/main/python/conversation/sentence/function.py b/src/main/python/conversation/sentence/function.py new file mode 100644 index 0000000..e3748ab --- /dev/null +++ b/src/main/python/conversation/sentence/function.py @@ -0,0 +1,105 @@ +import tensorflow as tf +keras = tf.keras +from tensorflow import Tensor +from keras.api.layers import TextVectorization, Embedding, LSTM, Dense, Input +from keras.api.models import Sequential +import numpy as np +import numpy.typing as npt + + + +# +# +# Description: The purpose of this model is to qualify sentences into different 'functions' +# +# - "Utility" - A sentence whose purpose is to perform some non-informational duty in a conversation. +# An example of this could be a greeting or farewell. +# +# - "Transfer" - Transfers a piece of information to another participant. For instance, describing +# the details of an object. +# +# - "Query" - Queries a piece of information from another participant. +# +# - "Imperative" - Commands a participant to do something. +# + + + + +# Model constants. +max_features: int = 20000 +embedding_dim: int = 128 +sequence_length: int = 500 +epochs: int = 50 +max_tokens: int = 5000 +output_sequence_length: int = 4 + + +# read sentences +data_path: str = './data/semantic/subject.txt' +data_raw: str = open(data_path).read() +vocab: list[str] = data_raw.split('\n') + +# read labels +label_data_path: str = './data/semantic/subject_label.txt' +label_data_raw: str = open(label_data_path).read() +labels: list[int] = list(map(int,label_data_raw.split())) + +# init vectorizer +textVec: TextVectorization = TextVectorization( + max_tokens=max_tokens, + output_mode='int', + output_sequence_length=output_sequence_length, + pad_to_max_tokens=True) + +# Add the vocab to the tokenizer +textVec.adapt(vocab) +input_data: list[str] = vocab +data: Tensor = textVec.call(input_data) + +# construct model +model: Sequential = Sequential([ + keras.Input(shape=(None,), dtype="int64"), + Embedding(max_features + 1, embedding_dim), + LSTM(64), + Dense(1, activation='sigmoid') +]) + +#compile the model +# model.build(keras.Input(shape=(None,), dtype="int64")) +model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy']) + + +# fit the training data +npData = np.array(data) +npLabel = np.array(labels) +model.fit(npData,npLabel,epochs=epochs) + + +# evaluate here + + +# predict +predictTargetRaw: list[str] = ['saf'] +predictTargetToken: list[int] = textVec.call(predictTargetRaw) +npPredict: npt.NDArray[np.complex64] = np.array(predictTargetToken) +# print(npPredict) +result: list[int] = model.predict(npPredict) +print("predict result:") +print(predictTargetToken) +print(result) +print(data) +print(labels) + + + +# save the model so keras can reload +# savePath: str = './data/semantic/model.keras' +# model.save(savePath) + +# export the model so java can leverage it +exportPath: str = './data/semantic/model' +model.export(exportPath) + +# tf.keras.utils.get_file('asdf') +# asdf: str = 'a' \ No newline at end of file