kakadzhun
There was a paper by someone @ Microsoft who tried to train a boardgame playing AI like this. The "best" models started losing to beginner level players from some point onwards.
https://zenodo.org/record/1146014/files/GNU_Parallel_2018.pd...
import numpy as np
print(np.__version__)
a = np.array([1,2,3])
b = np.array([1])
print(a in b)
print(b in a)
print(np.isin(a, b))
print(np.isin(b, a))
print(np.isin(a.astype(float), b))
print(np.isin(a, b.astype(float))))
1.21.6
True
True
[ True False False]
[ True]
[ True False False]
[ True False False]What if you were truly immortal, wouldn't you be driven mad soon enough?
import sys
import orjson
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('expr')
parser.add_argument('file', nargs='?')
args = parser.parse_args()
expression = compile(args.expr, '<string>', 'eval', optimize=0)
if args.file:
stream = open(args.file, 'f')
else:
stream = sys.stdin
try:
for line in stream:
json = orjson.loads(line)
if eval(expression, {}, json):
print(line.strip())
finally:
if args.file:
stream.close()Last but not least, you will be bound by your inability to accurately communicate exactly the behaviour you want out of the AI because you are incapable of writing down a mathematical function that would induce the behaviour in the learner. And then you wonder why the general AI decided to pull the plug on your grandma and try to use that resource for something else instead.
Minimal working example of storing numpy vectors in sqlite3 using Python:
import sqlite3
from scipy.spatial.distance import cdist
import numpy as np
class Vector:
def __init__(self, arg):
self.arg = arg
def __str__(self):
return 'Vector({!r})'.format(self.arg)
def adapter_func(obj: np.ndarray):
return obj.tobytes()
def converter_func(data: bytes):
return np.frombuffer(data)
sqlite3.register_adapter(Vector, adapter_func)
sqlite3.register_converter(f"{Vector.__name__}", converter_func)
if __name__ == '__main__':
with sqlite3.connect(":memory:", detect_types=sqlite3.PARSE_DECLTYPES) as con:
cur = con.cursor()
cur.execute("create table test(v vector)")
cur.execute("insert into test(v) values (?)", (np.random.random(1280),))
cur.execute("insert into test(v) values (?)", (np.random.random(1280),))
cur.execute('select v from test')
vectors = []
for v, in cur.fetchall():
print(v.shape, v)
assert isinstance(v, np.ndarray)
vectors.append(v)
assert len(vectors) == 2
print(cdist(vectors[:1], vectors[1:], metric='cosine')[0])
cur.close() In [1]: np.argmax(np.array([[1,2,3],[1,9,3],[1,2,3]]).flat)
Out[2]: 4