- Theano
- Lasagne (edge)
- NumPy
- SciPy
Create directory under models/
with its model name.
Place train.txt
, test.txt
and encode.txt
under the directory.
$ python3 train.py --model_name=mymodel
$ python3 encode.py --model_name=mymodel
from shared import *
model = Seyade('example')
model.load_result()
doc = model.train_docs[0]
doc['text'] # => 'Lorem ipsum ...'
doc['targets'] # => ['foo', 'baz']
doc['predictions'] # => ['foo', 'bar']
doc['scored_predictions'] # => [('foo', 0.95), ('bar', 0.88)]
doc['embedding'] # => array([ 0.1, 0.5, -0.9, ...])
for doc in model.test_docs:
print(doc['targets'], doc['scored_predictions'], doc['text'])
# comparable precision@1 score with old method
model.load_result(0)
correct = 0
for doc in model.test_docs:
if doc['predictions'][0] in doc['targets']:
correct += 1
# Set different threshold for prediction.
model.load_result(0.9) # 0.7 => 82.61(632/765), 0.9 => 87.66, 0.99 => 93.48
correct = 0
total = 0
for doc in model.test_docs:
for p in doc['predictions']:
total += 1
if p == doc['targets'][0]:
correct += 1
print(total, correct, correct / total)
with io.open(model.file_path(BEST_MODEL_FILE), 'rb') as f: npzfile = np.load(f) for k, v in npzfile.items(): pass