a lot of small stuff

This commit is contained in:
2019-12-07 19:56:23 -08:00
parent 997d3a7618
commit 5abe7bb413
4 changed files with 35 additions and 6 deletions

4
.gitignore vendored
View File

@@ -1,9 +1,9 @@
.*.sw? .*.sw?
DS_Store .DS_Store
run run
compile_commands.json compile_commands.json
*.txt *.txt
build/ build/
cythoned/ cythoned/
__pycache__/ __pycache__/
data* data/

View File

@@ -7,6 +7,7 @@ from libc.stdlib cimport malloc, realloc
from libc.string cimport memcpy from libc.string cimport memcpy
import library as nn import library as nn
import flask
tokenizers = {} tokenizers = {}
@@ -44,6 +45,10 @@ cdef public char *greeting():
return f'The value is {3**3**3}'.encode('utf-8') return f'The value is {3**3**3}'.encode('utf-8')
cdef public void serve():
nn.app.run(port=8448)
cdef public int get_tokens(WordList* wl, const char *filename): cdef public int get_tokens(WordList* wl, const char *filename):
fnu = filename.decode('utf-8') fnu = filename.decode('utf-8')
if fnu not in tokenizers: if fnu not in tokenizers:

View File

@@ -2,15 +2,18 @@ import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
import numpy as np import numpy as np
import flask
import tensorflow as tf import tensorflow as tf
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR) # STFU! tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR) # STFU!
from nltk.tokenize import word_tokenize as wt
from mynet import onehot from mynet import onehot
HERE = os.path.abspath(os.path.dirname(__file__)) HERE = os.path.abspath(os.path.dirname(__file__))
CORPUS = os.path.join(HERE, 'melville-moby_dick.txt') DATA = os.path.join(HERE, 'data')
VOCAB = os.path.join(HERE, 'vocab.txt') CORPUS = os.path.join(DATA, 'corpus.txt')
VOCAB = os.path.join(DATA, 'vocab.txt')
vocab = { vocab = {
w: i for i, w in enumerate(open(VOCAB).read().splitlines(keepends=False)) w: i for i, w in enumerate(open(VOCAB).read().splitlines(keepends=False))
@@ -18,6 +21,14 @@ vocab = {
inv_vocab = sorted(vocab, key=vocab.get) inv_vocab = sorted(vocab, key=vocab.get)
app = flask.Flask(__name__)
@app.route('/')
def webfront():
return 'Hello world!'
def word_tokenize(s: str): def word_tokenize(s: str):
l = ''.join(c.lower() if c.isalpha() else ' ' for c in s) l = ''.join(c.lower() if c.isalpha() else ' ' for c in s)
return l.split() return l.split()

17
main.c
View File

@@ -40,6 +40,7 @@ typedef enum{
FILTERER, FILTERER,
BATCHER, BATCHER,
LEARNER, LEARNER,
VISUALIZER,
DISPATCHER DISPATCHER
} Role; } Role;
@@ -72,7 +73,10 @@ size_t number_of(Role what) {
- number_of(TOKENIZER) - number_of(TOKENIZER)
- number_of(FILTERER) - number_of(FILTERER)
- number_of(BATCHER) - number_of(BATCHER)
- number_of(DISPATCHER); - number_of(DISPATCHER)
- number_of(VISUALIZER);
case VISUALIZER:
return 1;
case DISPATCHER: case DISPATCHER:
return 1; return 1;
} }
@@ -320,7 +324,7 @@ void dispatcher() {
} }
combo_weights(&wl, wls, lpr); combo_weights(&wl, wls, lpr);
set_net_weights(frank, &wl); set_net_weights(frank, &wl);
// INFO_PRINTF("Frank: %f\n", eval_net(frank)); INFO_PRINTF("Frank: %f\n", eval_net(frank));
} }
Py_DECREF(frank); Py_DECREF(frank);
free_weightlist(&wl); free_weightlist(&wl);
@@ -329,6 +333,12 @@ void dispatcher() {
free(round); free(round);
} }
void visualizer() {
INFO_PRINTF("Starting visualizer %d\n", getpid());
serve();
}
int main (int argc, const char **argv) { int main (int argc, const char **argv) {
MPI_Init(NULL, NULL); MPI_Init(NULL, NULL);
@@ -358,6 +368,9 @@ int main (int argc, const char **argv) {
case DISPATCHER: case DISPATCHER:
dispatcher(); dispatcher();
break; break;
case VISUALIZER:
visualizer();
break;
default: default:
INFO_PRINTLN("DYING HORRIBLY!"); INFO_PRINTLN("DYING HORRIBLY!");
} }