stsievert / salmon

A tool to collect triplet queries
https://docs.stsievert.com/salmon/
BSD 3-Clause "New" or "Revised" License
9 stars 2 forks source link

[feature request] use pdb when developing new algorithms #54

Closed stsievert closed 4 years ago

stsievert commented 4 years ago

It'd be really nice to use pdb when developing a new algorithm. Can that be done?

stsievert commented 4 years ago

I think so. It'd certainly require activating the environment in skorch.yaml. It'd probably also require this script:

from salmon.triplets.algs import STE

alg = STE()
for k in range(1000):
    query = alg.get_query()
    # or this implementation
    queries, scores = alg.get_queries()
    query = queries[scores.argmax()]

    answer = random_answer(query)
    alg.process_answers(answer)
stsievert commented 4 years ago

Actually, it's as simple as this method:

from salmon.triplets.algs import STE
from copy import copy
import random

def random_answer(q):
    ans = copy(q)
    winner = random.choice(["left", "right"])
    ans["winner"] = q[winner]
    return ans

params = {
    "optimizer__lr": 0.1,
    "optimizer__momentum": 0.75,
}
alg = STE(n=10, **params)
for k in range(1000):
    query, score = alg.get_query()
    if query is None:
        queries, scores = alg.get_queries()
        h, a, b = queries[scores.argmax()]
        query = {"head": h, "left": a, "right": b, "score": scores.max()}

    answer = random_answer(query)
    alg.process_answers([answer])

I'll post this to the documentation and close this issue.